diff options
-rw-r--r-- | DOCS/encoding.rst | 141 | ||||
-rw-r--r-- | DOCS/man/en/changes.rst | 1 | ||||
-rw-r--r-- | DOCS/man/en/encode.rst | 134 | ||||
-rw-r--r-- | DOCS/man/en/mplayer-old.1 | 196 | ||||
-rw-r--r-- | DOCS/man/en/mplayer.rst | 2 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | cfg-mplayer.h | 18 | ||||
-rwxr-xr-x | configure | 14 | ||||
-rw-r--r-- | defaultopts.c | 2 | ||||
-rw-r--r-- | encode.h | 21 | ||||
-rw-r--r-- | encode_lavc.c | 1062 | ||||
-rw-r--r-- | encode_lavc.h | 93 | ||||
-rw-r--r-- | etc/encoding-example-profiles.conf | 189 | ||||
-rw-r--r-- | etc/input.conf | 2 | ||||
-rw-r--r-- | libao2/ao_lavc.c | 588 | ||||
-rw-r--r-- | libao2/audio_out.c | 4 | ||||
-rw-r--r-- | libao2/audio_out.h | 1 | ||||
-rw-r--r-- | libvo/csputils.c | 47 | ||||
-rw-r--r-- | libvo/csputils.h | 4 | ||||
-rw-r--r-- | libvo/video_out.c | 8 | ||||
-rw-r--r-- | libvo/video_out.h | 4 | ||||
-rw-r--r-- | libvo/vo_lavc.c | 590 | ||||
-rw-r--r-- | mp_core.h | 2 | ||||
-rw-r--r-- | mp_msg.h | 2 | ||||
-rw-r--r-- | mplayer.c | 97 | ||||
-rw-r--r-- | options.h | 18 |
26 files changed, 3208 insertions, 33 deletions
diff --git a/DOCS/encoding.rst b/DOCS/encoding.rst new file mode 100644 index 0000000000..67ad19bae6 --- /dev/null +++ b/DOCS/encoding.rst @@ -0,0 +1,141 @@ +General usage +============= + +:: + + mplayer infile -o outfile [-of outfileformat] [-ofopts formatoptions] \ + [-ofps outfps | -oautofps] [-oharddup] [-ocopyts | -orawts] [-oneverdrop] \ + [(any other mplayer options)] \ + -ovc outvideocodec [-ovcopts outvideocodecoptions] \ + -oac outaudiocodec [-oacopts outaudiocodecoptions] + +Help for these options is provided if giving help as parameter, as in:: + + mplayer -ovc help + +The suboptions of these generally are identical to ffmpeg's (as option parsing +is simply delegated to ffmpeg). The option -ocopyts enables copying timestamps +from the source as-is, instead of fixing them to match audio playback time +(note: this doesn't work with all output container formats); -orawts even turns +off discontinuity fixing. + +Note that if neither -ofps nor -oautofps is specified, VFR encoding is assumed +and the time base is 24000fps. -oautofps sets -ofps to a guessed fps number +from the input video. Note that not all codecs and not all formats support VFR +encoding, and some which do have bugs when a target bitrate is specified - use +-ofps or -oautofps to force CFR encoding in these cases. + +Of course, the options can be stored in a profile, like this .mplayer/config +section:: + + [myencprofile] + vf-add = scale=480:-2 + ovc = libx264 + ovcopts-add = preset=medium,tune=fastdecode + ovcopts-add = crf=23 + ovcopts-add = maxrate=1500k,bufsize=1000k,rc_init_occupancy=900k,refs=2 + ovcopts-add = profile=baseline + oac = aac + oacopts-add = b=96k + +One can then encode using this profile using the command:: + + mplayer infile -o outfile.mp4 -profile myencprofile + +Some example profiles are provided in a file +etc/encoding-example-profiles.conf; as for this, see below. + + +Encoding examples +================= + +These are some examples of encoding targets this code has been used and tested +for. + +Typical MPEG-4 Part 2 ("ASP", "DivX") encoding, AVI container:: + + mplayer infile -o outfile.avi \ + -ofps 25 \ + -ovc mpeg4 -ovcopts qscale=4 \ + -oac libmp3lame -oacopts ab=128k + +Note: AVI does not support variable frame rate, so -ofps must be used. The +frame rate should ideally match the input (25 for PAL, 24000/1001 or 30000/1001 +for NTSC) + +Typical MPEG-4 Part 10 ("AVC", "H.264") encoding, Matroska (MKV) container:: + + mplayer infile -o outfile.mkv \ + -ovc libx264 -ovcopts preset=medium,crf=23,profile=baseline \ + -oac vorbis -oacopts qscale=3 + +Typical MPEG-4 Part 10 ("AVC", "H.264") encoding, MPEG-4 (MP4) container:: + + mplayer infile -o outfile.mp4 \ + -ovc libx264 -ovcopts preset=medium,crf=23,profile=baseline \ + -oac aac -oacopts ab=128k + +Typical VP8 encoding, WebM (restricted Matroska) container:: + + mplayer infile -o outfile.mkv \ + -of webm \ + -ovc libvpx -ovcopts qmin=6,b=1000000k \ + -oac libvorbis -oacopts qscale=3 + + +Device targets +============== + +As the options for various devices can get complex, profiles can be used. + +An example profile file for encoding is provided in +etc/encoding-example-profiles.conf in the source tree. You can include it into +your configuration by doing, from the mplayer2-build directory:: + + mkdir -p ~/.mplayer + echo "include = $PWD/mplayer/etc/encoding-example-profiles.conf" >> ~/.mplayer/config + +Refer to the top of that file for more comments - in a nutshell, the following +options are added by it:: + + -profile enc-to-dvdpal DVD-Video PAL, use dvdauthor -v pal+4:3 -a ac3+en + -profile enc-to-dvdntsc DVD-Video NTSC, use dvdauthor -v ntsc+4:3 -a ac3+en + -profile enc-to-bb-9000 MP4 for Blackberry Bold 9000 + -profile enc-to-nok-6300 3GP for Nokia 6300 + -profile enc-to-psp MP4 for PlayStation Portable + -profile enc-to-iphone MP4 for iPhone + -profile enc-to-iphone4 MP4 for iPhone 4 (double res) + +You can encode using these with a command line like:: + + mplayer infile -o outfile.mp4 -profile enc-to-bb-9000 + +Of course, you are free to override options set by these profiles by specifying +them after the -profile option. + + +What works +========== + +* Encoding at variable frame rate (default) +* Encoding at constant frame rate using -ofps framerate -oharddup +* 2-pass encoding (specify flags=+pass1 in the first pass's -ovcopts, specify + flags=+pass2 in the second pass) +* Hardcoding subtitles using vobsub, ass or srt subtitle rendering (just + configure mplayer for the subtitles as usual) +* Hardcoding any other mplayer OSD (e.g. time codes, using -osdlevel 3 and -vf + expand=::::1) +* Encoding directly from a DVD, network stream, webcam, or any other source + mplayer supports +* Using x264 presets/tunings/profiles (by using profile=, tune=, preset= in the + -ovcopts) +* Deinterlacing/Inverse Telecine with any of mplayer's filters for that +* Audio file converting: mplayer -o outfile.mp3 infile.flac -novideo -oac + libmp3lame -oacopts ab=320k +* inverse telecine filters (confirmed working: detc, pullup, filmdint) + +What does not work yet + +* 3-pass encoding (ensuring constant total size and bitrate constraints while + having VBR audio; mencoder calls this "frameno") +* Direct stream copy diff --git a/DOCS/man/en/changes.rst b/DOCS/man/en/changes.rst index e4f331e807..c4fc3a0812 100644 --- a/DOCS/man/en/changes.rst +++ b/DOCS/man/en/changes.rst @@ -63,6 +63,7 @@ General changes for mplayer2 to mplayer3 * Do not lose settings when playing a new file in the same player instance * New location for config files, new name for the binary. (Planned change.) * Slave mode compatibility broken (see below) +* Encoding functionality (replacement for mencoder) * General code cleanups * Many more changes diff --git a/DOCS/man/en/encode.rst b/DOCS/man/en/encode.rst new file mode 100644 index 0000000000..7ebd8e6c01 --- /dev/null +++ b/DOCS/man/en/encode.rst @@ -0,0 +1,134 @@ +.. _encode: + +ENCODING +======== + +You can encode files from one format/codec to another using this facility. + +-o <filename> + Enables encoding mode and specifies the output file name. + +--of=<format> + Specifies the output format (overrides autodetection by the extension of + the file specified by -o). + See --of=help for a full list of supported formats. + +--ofopts=<options> + Specifies the output format options for libavformat. + See --ofopts=help for a full list of supported options. + + Options are managed in lists. There are a few commands to manage the + options list. + + --ofopts-add=<options1[,options2,...]> + Appends the options given as arguments to the options list. + + --ofopts-pre=<options1[,options2,...]> + Prepends the options given as arguments to the options list. + + --ofopts-del=<index1[,index2,...]> + Deletes the options at the given indexes. Index numbers start at 0, + negative numbers address the end of the list (-1 is the last). + + --ofopts-clr + Completely empties the options list. + +--ofps=<float value> + Specifies the output format time base (default: 24000). Low values like 25 + limit video fps by dropping frames. + +--oautofps + Sets the output format time base to the guessed frame rate of the input + video (simulates mencoder behaviour, useful for AVI; may cause frame + drops). Note that not all codecs and not all formats support VFR + encoding, and some which do have bugs when a target bitrate is + specified - use --ofps or --oautofps to force CFR encoding in these + cases. + +--oharddup + If set, the frame rate given by --ofps is attained not by skipping time + codes, but by duplicating frames (constant frame rate mode). + +--oneverdrop + If set, frames are never dropped. Instead, time codes of video are + readjusted to always increase. This may cause AV desync, though; to + work around this, use a high-fps time base using --ofps and absolutely + avoid --oautofps. + +--oac=<codec> + Specifies the output audio codec. + See --oac=help for a full list of supported codecs. + +--oaoffset=<value> + Shifts audio data by the given time (in seconds) by adding/removing + samples at the start. + +--oacopts=<options> + Specifies the output audio codec options for libavcodec. + See --oacopts=help for a full list of supported options. + + EXAMPLE: "--oac=libmp3lame --oacopts=b=128000" selects 128kbps MP3 + encoding. + + Options are managed in lists. There are a few commands to manage the + options list. + + --oacopts-add=<options1[,options2,...]> + Appends the options given as arguments to the options list. + + --oacopts-pre=<options1[,options2,...]> + Prepends the options given as arguments to the options list. + + --oacopts-del=<index1[,index2,...]> + Deletes the options at the given indexes. Index numbers start at 0, + negative numbers address the end of the list (-1 is the last). + + --oacopts-clr + Completely empties the options list. + +--ovc=<codec> + Specifies the output video codec. + See --ovc=help for a full list of supported codecs. + +--ovoffset=<value> + Shifts video data by the given time (in seconds) by shifting the pts + values. + +--ocopyts + Copies input pts to the output video (not supported by some output + container formats, e.g. avi). Discontinuities are still fixed. + By default, audio pts are set to playback time and video pts are + synchronized to match audio pts, as some output formats do not support + anything else. + +--orawts + Copies input pts to the output video (not supported by some output + container formats, e.g. avi). In this modem discontinuities are not fixed + and all pts are passed through as-is. Never seek backwards or use multiple + input files in this mode! + +--ovcopts <options> + Specifies the output video codec options for libavcodec. + See --ovcopts=help for a full list of supported options. + + EXAMPLE: "--ovc=mpeg4 --oacopts=qscale=5" selects constant quantizer scale + 5 for MPEG-4 encoding. + + EXAMPLE: "--ovc=libx264 --ovcopts=crf=23" selects VBR quality factor 23 for + H.264 encoding. + + Options are managed in lists. There are a few commands to manage the + options list. + + --ovcopts-add=<options1[,options2,...]> + Appends the options given as arguments to the options list. + + --ovcopts-pre=<options1[,options2,...]> + Prepends the options given as arguments to the options list. + + --ovcopts-del=<index1[,index2,...]> + Deletes the options at the given indexes. Index numbers start at 0, + negative numbers address the end of the list (-1 is the last). + + --ovcopts-clr + Completely empties the options list. diff --git a/DOCS/man/en/mplayer-old.1 b/DOCS/man/en/mplayer-old.1 index 477244cc58..92592c7f27 100644 --- a/DOCS/man/en/mplayer-old.1 +++ b/DOCS/man/en/mplayer-old.1 @@ -6707,7 +6707,7 @@ This will give much better results for material that has undergone heavy editing after telecine was applied, but as a result it is not as forgiving of noisy input, for example TV capture. The optional parameter (ivtc=1) corresponds to the dr=1 option for the -detc filter, and should not be used with MPlayer. +detc filter, and should not be used for playback. Further development on ivtc has stopped, as the pullup and filmdint filters appear to be much more accurate. . @@ -6765,9 +6765,6 @@ access to the field-flags set by the MPEG-2 decoder. Depending on the source MPEG, you may be fine ignoring this advice, as long as you do not see lots of "Bottom-first field" warnings. With no options it does normal inverse telecine. -When this filter is used with MPlayer, it will result in an uneven -framerate during playback, but it is still generally better than using -pp=lb or no deinterlacing at all. Multiple options can be specified separated by /. .RSs .IPs crop=<w>:<h>:<x>:<y> @@ -7510,6 +7507,197 @@ Using this filter together with any sort of seeking (including -ss and EDLs) may make demons fly out of your nose. .RE . +.\" -------------------------------------------------------------------------- +.\" encoding +.\" -------------------------------------------------------------------------- +. +.SH ENCODING OPTIONS +. +.TP +.B \-o <filename> +Enable encoding mode and specify the output file name. +.RE +. +.TP +.B \-of <format> +Specify the output format (overrides autodetection by the extension of the file specified by \-o). +See \-of help for a full list of supported formats. +.RE +. +.TP +.B \-ofopts <options> +Specify the output format options for libavformat. +See \-ofopts help for a full list of supported options. +.RE +.PP +.I NOTE: +To get a full list of available format options, see \-ofopts help. +.sp 1 +Options are managed in lists. +There are a few commands to manage the options list. +. +.TP +.B \-ofopts\-add <option1[,option2,...]> +Appends the options given as arguments to the options list. +. +.TP +.B \-ofopts\-pre <option1[,option2,...]> +Prepends the options given as arguments to the options list. +. +.TP +.B \-ofopts\-del <index1[,index2,...]> +Deletes the options at the given indexes. +Index numbers start at 0, negative numbers address the end of the +list (\-1 is the last). +. +.TP +.B \-ofopts\-clr +Completely empties the options list. +. +.RE +. +.TP +.B \-ofps <float value> +Specifies the output format time base (default: 24000). Low values like 25 limit video fps by dropping frames. +.RE +. +.TP +.B \-oautofps +Sets the output format time base to the guessed frame rate of the input video (simulates mencoder behaviour, useful for AVI; may cause frame drops). Note that not all codecs and not all formats support VFR encoding, and some which do have bugs when a target bitrate is specified - use +.B \-ofps +or +.B \-oautofps +to force CFR encoding in these cases. +.RE +. +.TP +.B \-oharddup +If set, the frame rate given by +.B \-ofps +is attained not by skipping time codes, but by duplicating frames (constant frame rate mode). +.RE +. +.TP +.B \-oneverdrop +If set, frames are never dropped. Instead, time codes of video are readjusted +to always increase. This may cause AV desync, though; to work around this, +use a high-fps time base using +.B \-ofps +and absolutely avoid +.B \-oautofps +.RE +. +.TP +.B \-oac <codec> +Specify the output audio codec. +See \-oac help for a full list of supported codecs. +.RE +. +.TP +.B \-oaoffset <value> +Shifts audio data by the given time (in seconds) by adding/removing samples at the start. +.RE +. +.TP +.B \-oacopts <options> +Specify the output audio codec options for libavcodec. +See \-oacopts help for a full list of supported options. +.RE +.PP +.I EXAMPLE: +.B \-oac libmp3lame \-oacopts b=128000 +selects 128kbps MP3 encoding. +.PP +.I NOTE: +To get a full list of available audio codec options, see \-oacopts help. +.sp 1 +Options are managed in lists. +There are a few commands to manage the options list. +. +.TP +.B \-oacopts\-add <option1[,option2,...]> +Appends the options given as arguments to the options list. +. +.TP +.B \-oacopts\-pre <option1[,option2,...]> +Prepends the options given as arguments to the options list. +. +.TP +.B \-oacopts\-del <index1[,index2,...]> +Deletes the options at the given indexes. +Index numbers start at 0, negative numbers address the end of the +list (\-1 is the last). +. +.TP +.B \-oacopts\-clr +Completely empties the options list. +. +.TP +.B \-ovc <codec> +Specify the output video codec. +See \-ovc help for a full list of supported codecs. +.RE +. +.TP +.B \-ovoffset <value> +Shifts video data by the given time (in seconds) by shifting the pts values. +.RE +. +.TP +.B \-ocopyts +Copies input pts to the output video (not supported by some output container formats, e.g. avi). +By default, audio pts are set to playback time and video pts are synchronized to match audio pts, as some output formats do not support anything else. +.RE +. +.TP +.B \-ovcopts <options> +Specify the output video codec options for libavcodec. +See \-ovcopts help for a full list of supported options. +.RE +.PP +.I EXAMPLE: +.B \-ovc mpeg4 \-ovcopts qscale=5 +selects constant quantizer scale 5 for MPEG-4 encoding. +.PP +.B \-ovc libx264 \-ovcopts crf=23 +selects VBR quality factor 23 for H.264 encoding. +.I NOTE: +To get a full list of available video codec options, see \-ovcopts help. +.PP +.sp 1 +Options are managed in lists. +There are a few commands to manage the options list. +. +.TP +.B \-ovcopts\-add <option1[,option2,...]> +Appends the options given as arguments to the options list. +. +.TP +.B \-ovcopts\-pre <option1[,option2,...]> +Prepends the options given as arguments to the options list. +. +.TP +.B \-ovcopts\-del <index1[,index2,...]> +Deletes the options at the given indexes. +Index numbers start at 0, negative numbers address the end of the +list (\-1 is the last). +. +.TP +.B \-ovcopts\-clr +Completely empties the options list. +. +.PP +.I NOTE for \-ovc libx264: +The x264 codec provides a set of presets/tunings/profiles which can be included with the ovcopts. +.PP +Available presets: preset=ultrafast, preset=superfast, preset=veryfast, preset=faster, preset=fast, preset=medium, preset=slow, preset=slower, preset=veryslow, preset=placebo (default: preset=medium) +.PP +Available tunings: tune=film, tune=animation, tune=grain, tune=stillimage, tune=psnr, tune=ssim, tune=fastdecode, tune=zerolatency (default: none) +.PP +Available profiles: profile=baseline, profile=main, profile=high (default: profile=high) +.PP +.I EXAMPLE: +.B mplayer \-o <outfile> <infile> \-ovc libx264 \-ovcopts preset=veryslow,crf=23,tune=animation,profile=main \-oac aac \-oacopts b=128000 . .\" -------------------------------------------------------------------------- .\" environment variables diff --git a/DOCS/man/en/mplayer.rst b/DOCS/man/en/mplayer.rst index 8485ee7064..89b03737c3 100644 --- a/DOCS/man/en/mplayer.rst +++ b/DOCS/man/en/mplayer.rst @@ -407,6 +407,8 @@ OPTIONS .. include:: vf.rst +.. include:: encode.rst + Taking screenshots ================== @@ -284,6 +284,7 @@ SRCS_MPLAYER-$(COREVIDEO) += libvo/vo_corevideo.m SRCS_MPLAYER-$(DIRECT3D) += libvo/vo_direct3d.c libvo/w32_common.c SRCS_MPLAYER-$(GL) += libvo/gl_common.c libvo/vo_gl.c libvo/vo_gl3.c \ pnm_loader.c +SRCS_MPLAYER-$(ENCODING) += libvo/vo_lavc.c libao2/ao_lavc.c encode_lavc.c SRCS_MPLAYER-$(GL_WIN32) += libvo/w32_common.c SRCS_MPLAYER-$(GL_X11) += libvo/x11_common.c diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 529df35caf..8278945c3d 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -245,6 +245,7 @@ const m_option_t msgl_config[]={ { "lirc", &mp_msg_levels[MSGT_LIRC], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, { "stream", &mp_msg_levels[MSGT_STREAM], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, { "cache", &mp_msg_levels[MSGT_CACHE], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, + { "encode", &mp_msg_levels[MSGT_ENCODE], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, { "xacodec", &mp_msg_levels[MSGT_XACODEC], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, { "tv", &mp_msg_levels[MSGT_TV], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, { "radio", &mp_msg_levels[MSGT_RADIO], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, @@ -289,6 +290,7 @@ const m_option_t msgl_config[]={ " lirc - lirc_mp.c and input lirc driver\n" " stream - stream.c\n" " cache - cache2.c\n" + " encode - encode_lavc.c and associated vo/ao drivers\n" " xacodec - XAnim codecs\n" " tv - TV input subsystem\n" " osdep - OS-dependent parts\n" @@ -739,6 +741,22 @@ const m_option_t mplayer_opts[]={ {"help", (void *) help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, {"h", (void *) help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, + OPT_STRING("o", encode_output.file, CONF_GLOBAL), + OPT_STRING("of", encode_output.format, CONF_GLOBAL), + OPT_STRINGLIST("ofopts*", encode_output.fopts, CONF_GLOBAL), + OPT_FLOATRANGE("ofps", encode_output.fps, CONF_GLOBAL, 0.0, 1000000.0), + OPT_STRING("ovc", encode_output.vcodec, CONF_GLOBAL), + OPT_STRINGLIST("ovcopts*", encode_output.vopts, CONF_GLOBAL), + OPT_STRING("oac", encode_output.acodec, CONF_GLOBAL), + OPT_STRINGLIST("oacopts*", encode_output.aopts, CONF_GLOBAL), + OPT_MAKE_FLAGS("oharddup", encode_output.harddup, CONF_GLOBAL), + OPT_FLOATRANGE("ovoffset", encode_output.voffset, CONF_GLOBAL, -1000000.0, 1000000.0), + OPT_FLOATRANGE("oaoffset", encode_output.aoffset, CONF_GLOBAL, -1000000.0, 1000000.0), + OPT_MAKE_FLAGS("ocopyts", encode_output.copyts, CONF_GLOBAL), + OPT_MAKE_FLAGS("orawts", encode_output.rawts, CONF_GLOBAL), + OPT_MAKE_FLAGS("oautofps", encode_output.autofps, CONF_GLOBAL), + OPT_MAKE_FLAGS("oneverdrop", encode_output.neverdrop, CONF_GLOBAL), + {NULL, NULL, 0, 0, 0, 0, NULL} }; @@ -298,6 +298,7 @@ Installation directories: Optional features: --disable-mplayer disable MPlayer compilation [enable] + --disable-encoding disable encoding functionality [enable] --enable-termcap use termcap database for key codes [autodetect] --enable-termios use termios database for key codes [autodetect] --disable-iconv disable iconv for encoding conversion [autodetect] @@ -436,6 +437,7 @@ _prefix="/usr/local" ffmpeg=auto ffmpeg_internals=no _mplayer=yes +_encoding=yes _x11=auto _xshape=auto _xss=auto @@ -620,6 +622,8 @@ for ac_option do --disable-cross-compile) _cross_compile=no ;; --enable-mplayer) _mplayer=yes ;; --disable-mplayer) _mplayer=no ;; + --enable-encoding) _encoding=yes ;; + --disable-encoding) _encoding=no ;; --enable-x11) _x11=yes ;; --disable-x11) _x11=no ;; --enable-xshape) _xshape=yes ;; @@ -3180,6 +3184,14 @@ else fi echores "$_sortsub" +echocheck "encoding" +if test "$_encoding" = yes ; then + def_encoding="#define CONFIG_ENCODING 1" +else + def_encoding="#undef CONFIG_ENCODING" +fi +echores "$_encoding" + ############################################################################# @@ -3382,6 +3394,7 @@ X11 = $_x11 XV = $_xv # FFmpeg +ENCODING = $_encoding FFMPEG_INTERNALS = $ffmpeg_internals FFMPEG_SOURCE_PATH = $_ffmpeg_source @@ -3599,6 +3612,7 @@ $def_xv /* FFmpeg */ +$def_encoding $def_ffmpeg_internals $def_fast_64bit diff --git a/defaultopts.c b/defaultopts.c index 672dbd5f5c..98abc00831 100644 --- a/defaultopts.c +++ b/defaultopts.c @@ -22,7 +22,7 @@ void set_default_mplayer_options(struct MPOpts *opts) .vo_gamma_contrast = 1000, .vo_gamma_saturation = 1000, .vo_gamma_hue = 1000, - .osd_level = 1, + .osd_level = -1, .osd_duration = 1000, .loop_times = -1, .ordered_chapters = 1, diff --git a/encode.h b/encode.h new file mode 100644 index 0000000000..f0f65f14c5 --- /dev/null +++ b/encode.h @@ -0,0 +1,21 @@ +#ifndef MPLAYER_ENCODE_H +#define MPLAYER_ENCODE_H + +#include <stdbool.h> +#include <libavutil/avutil.h> + +struct MPOpts; +struct encode_lavc_context; +struct encode_output_conf; + +// interface for mplayer.c +struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options); +void encode_lavc_finish(struct encode_lavc_context *ctx); +void encode_lavc_free(struct encode_lavc_context *ctx); +void encode_lavc_discontinuity(struct encode_lavc_context *ctx); +bool encode_lavc_showhelp(struct MPOpts *opts); +int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position, float playback_time); +void encode_lavc_expect_stream(struct encode_lavc_context *ctx, enum AVMediaType mt); +bool encode_lavc_didfail(struct encode_lavc_context *ctx); // check if encoding failed + +#endif diff --git a/encode_lavc.c b/encode_lavc.c new file mode 100644 index 0000000000..f8e04f99bc --- /dev/null +++ b/encode_lavc.c @@ -0,0 +1,1062 @@ +/* + * Raw video muxing using libavformat + * Copyright (C) 2010 Nicolas George <george@nsup.org> + * Copyright (C) 2011 Rudolf Polzer <divVerent@xonotic.org> + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +#include "encode_lavc.h" +#include "mp_msg.h" +#include "libmpcodecs/vfcap.h" +#include "options.h" +#include "osdep/timer.h" +#include "libvo/video_out.h" +#include "talloc.h" +#include "stream/stream.h" + +static int set_to_avdictionary(void *ctx, AVDictionary **dictp, void *octx, + const char *str, const char *key_val_sep, + const char *pairs_sep) +{ + int good = 0; + int errorcode = 0; + const AVOption *o; + + while (*str) { + char *key_ = av_get_token(&str, key_val_sep); + char *val_; + char *key, *val; + char valuebuf[1024]; + + if (*key_ && strspn(str, key_val_sep)) { + str++; + val_ = av_get_token(&str, pairs_sep); + } else { + av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value " + "separator found after key '%s'\n", key_); + av_free(key_); + if (!errorcode) + errorcode = AVERROR(EINVAL); + if (*str) + ++str; + continue; + } + + key = key_; + val = val_; + + if(!strcmp(key, "qscale") && val[0] != '+' && val[0] != '-' && !av_opt_find(octx, key, NULL, 0, AV_OPT_SEARCH_CHILDREN)) + { + // hack: support "qscale" key as virtual "global_quality" key that multiplies by QP2LAMBDA + key = "global_quality"; + snprintf(valuebuf, sizeof(valuebuf), "(%s)*QP2LAMBDA", val); + valuebuf[sizeof(valuebuf)-1] = 0; + val = valuebuf; + } + + av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", + val, key); + + if((o = av_opt_find(octx, key, NULL, 0, AV_OPT_SEARCH_CHILDREN))) { + if (av_dict_set(dictp, key, *val ? val : NULL, (o->type == FF_OPT_TYPE_FLAGS && (val[0] == '+' || val[0] == '-')) ? AV_DICT_APPEND : 0) >= 0) + ++good; + else + errorcode = AVERROR(EINVAL); + } else { + errorcode = AVERROR(ENOENT); + } + + av_free(key_); + av_free(val_); + + if (*str) + ++str; + } + return errorcode ? errorcode : good; +} + +static bool value_has_flag(const char *value, const char *flag) +{ + bool state = true; + bool ret = false; + while(*value) + { + size_t l = strcspn(value, "+-"); + if(l == 0) + { + state = (*value == '+'); + ++value; + } + else + { + if(l == strlen(flag)) + if(!memcmp(value, flag, l)) + ret = state; + value += l; + } + } + return ret; +} + +#define CHECK_FAIL(ctx, val) \ + if(ctx && (ctx->failed || ctx->finished)) { \ + mp_msg(MSGT_ENCODE, MSGL_ERR, "Called a function on a %s encoding context. Bailing out.\n", ctx->failed ? "failed" : "finished"); \ + return val; \ + } + +int encode_lavc_available(struct encode_lavc_context *ctx) +{ + CHECK_FAIL(ctx, 0); + return ctx && ctx->avc; +} + +int encode_lavc_oformat_flags(struct encode_lavc_context *ctx) +{ + CHECK_FAIL(ctx, 0); + return ctx->avc ? ctx->avc->oformat->flags : 0; +} + +struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options) +{ + struct encode_lavc_context *ctx; + + ctx = talloc_zero(NULL, struct encode_lavc_context); + encode_lavc_discontinuity(ctx); + ctx->options = options; + + ctx->avc = avformat_alloc_context(); + + if |