Sep 23, 2009

Mencoder/Mplayer 笔记和例子

如果是简单的编码,考虑使用 Handbrake

下载 mplayer/mencoder,以及其他相关的 codes

man page 这个可以详细查找
guide 
encoding tip

使用帮助

mencoder -ovc help
mencoder -oac help
mencoder -of help (output format)
mencoder -vf help (video filter)

mencoder -vf help
列出 video filters 的名称

比如使用 format 这个滤波器
mencoder -vf format=help
列出 format 的参数 可以知道 format 有一个参数为 fmt
除了参数名,还会给出参数类型,和取值范围

mencoder -vf format=fmt=help
列出 fmt 参数的可选项


对于多个参数,多个滤波器
-vf Setup a chain of video filters.

Mencoder 命令格式


mencoder.exe
-ovc x264 -x264encopts crf=20
[-vf rotate=0]
-oac mp3lame -lameopts vbr=3:br=96
-of avi
AVSEQ08.DAT -o AVSEQ08.avi 

-ovc 视频编码器,x264encopts 说明后面接的是 x264 的参数,多个参数之间用':'隔开

ovc


常用的为 x264
x264encopts 有很多项,傻瓜式用法有两种
设置 crf,好一点设为 20,差一点设为 24
设置 bitrate,并使用 2 passes
crf 例:
mencoder -ovc x264 -x264encopts crf=20 -oac mp3lame -lameopts vbr=3:br=96 -of avi AVSEQ08.DAT -o AVSEQ08.avi

2 passes 例:
使用 2passes,要编码两次,两条命令,第一pass时,音频可以选择 copy,第二pass才编音频
mencoder -ovc x264 -x264encopts bitrate=384:pass=1 -oac copy -of avi AVSEQ08.DAT -o AVSEQ08.avi
mencoder -ovc x264 -x264encopts bitrate=384:pass=2 -oac mp3lame -lameopts vbr=3:br=96 -of avi AVSEQ08.DAT -o AVSEQ08.avi

oac

常用 mp3lame 以及 faac,后者需要一个 dll

mp3lame
-lameopts
vbr 参数:
0 cbr
1 mt
2 rh (default)
3 abr
4 mtrh
一般可以选择 vbr=3:br=128


of

目前 -of  lavf 的muxer还存在问题,所以请选择 avi。 avi 也可以封装 264

vf: 编码或播放时的视频处理

格式为
-vf filter=parameter1:parameter2

使用 vf,例如播放时旋转
mplayer -vf rotate=0 IMG_0744.MOV

编码时旋转
mencoder -ovc x264 -x264encopts bitrate=3000 -vf rotate=0 -oac faac -of lavf -lavfopts format=mp4 IMG_0744.MOV -o test2.mp4 

编码时缩放
mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000 -vf scale=320:240 -oac mp3lame -of avi IMG_0744.MOV -o test.avi


需要多个滤波器,使用',' 链接
-vf <filter1[=parameter1:parameter2:...],filter2,...>
比如 -vf rotate=0,scale=320:240


例子


d:\Software\MPlayer-p4-svn-34401\mencoder.exe -ovc x264 -x264encopts crf=20 -oac mp3lame -lameopts vbr=3:br=96 -of avi AVSEQ08.DAT -o AVSEQ08.avi

d:\Software\MPlayer-p4-svn-34401\mencoder.exe -ovc x264 -x264encopts bitrate=384:pass=1 -oac copy -of avi AVSEQ08.DAT -o AVSEQ08.avi
d:\Software\MPlayer-p4-svn-34401\mencoder.exe -ovc x264 -x264encopts bitrate=384:pass=2 -oac mp3lame -lameopts vbr=3:br=96 -of avi AVSEQ08.DAT -o AVSEQ08.avi



Example 1: 将多个名字顺序排列的png图片连成视频
mencoder.exe mf://*.png -mf type=png:fps=25 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2000 -o out3.avi

注意
Specify bitrate (default: 800).
WARNING:
1kbit = 1000 bits

4−16000

(in kbit)

16001−24000000

(in bit)


Example 2: raw video 将yuv4mpeg 格式的视频转化为 i420 的raw
mencoder -ovc raw -vf format=i420 -of rawvideo stefan_sif.y4m -o stefan_sif.yuv

Example 3: x264
mencoder -ovc x264 -x264encopts bitrate=192 -of  lavf -lavfopts format=mp4 -o foreman.mp4 foreman_qcif.y4m
在 man page 中查找  -x264encopts,知道更多选项

Example: 利用 mencoder 提取音频
mencoder Recording.mpg  -oac mp3lame -ovc frameno -o tmp.avi
mplayer tmp.avi -dumpaudio -dumpfile audio.mp3

muxing 视频和音频,假设音频已经处理并编码好了
mencoder -ovc x264 -x264encopts crf=20 -oac copy -mc 0 -noskip -audiofile fj.mp3 -of avi fj.mpg -o fj.avi
见该技巧更多讨论
mencoder -ovc copy -oac copy -mc 0 -noskip -audiofile trailer-audio.mp3 -audio-demuxer 20 -rawaudio format=0x2000:bitrate=448000:channels=6:rate=48000 -o sometest.avi xvid.avi  

I'll explain better what is going on: mplayer has a native mp3/mp2/mp1
demuxer that automatically identifies the properties of these streams
and assigns bitrate, channels and samplerate accordingly;
in order to demux ac3 mplayer relies on libavformat, that in this
particular case does not assign those properties, so it has to be
replaced with -demuxer 20 (rawaudio).

Consequently, that command line is valid if the audiofile is ac3, but if (as the name implies) it is in mp3 format you either don't need 
-audio-demuxer 20 -rawaudio format=0x2000:bitrate=448000:channels=6:rate=48000 
or you should replace it with the correct parameters for audio,
in which case format=0x55.

I assumed that you were trying to mux ac3 audio, and forgot that 
you also mentioned you attempted to mux mp3, that's why I only suggested to use format=0x2000, sorry.


参数

Available video codecs:
   copy     - frame copy, without re-encoding. Doesn't work with filters.
   frameno  - special audio-only file for 3-pass encoding, see DOCS.
   raw      - uncompressed video. Use fourcc option to set format explicitly.
   nuv      - nuppel video
   lavc     - libavcodec codecs - best quality!
   vfw      - VfW DLLs, read DOCS/HTML/en/encoding-guide.html.
   qtvideo  - QuickTime DLLs, currently only SVQ1/3 are supported.
   xvid     - XviD encoding
   x264     - H.264 encoding

选了某种视频编解码器后,相应的有 xxxopts 选项
比如 -ovc lavc -lavcopts ....

Available audio codecs:
   copy     - frame copy, without re-encoding (useful for AC3)
   pcm      - uncompressed PCM audio
   mp3lame  - cbr/abr/vbr MP3 using libmp3lame
   lavc     - FFmpeg audio encoder (MP2, AC3, ...)
   twolame  - Twolame MP2 audio encoder
   faac     - FAAC AAC audio encoder

Available output formats:
   avi      - Microsoft Audio/Video Interleaved
   mpeg     - MPEG-1/2 system stream format
   lavf     - FFmpeg libavformat muxers
   rawvideo - (video only, one stream only) raw stream, no muxing
   rawaudio - (audio only, one stream only) raw stream, no muxing


Available video filters:
  rectangle      : draw rectangle
  crop           : cropping
  expand         : expanding & osd
  pp             : postprocessing
  scale          : software scaling
  vo             : libvo wrapper
  format         : force output format
  noformat       : disallow one output format
  yuy2           : fast YV12/Y422p -> YUY2 conversion
  flip           : flip image upside-down
  rgb2bgr        : fast 24/32bpp RGB<->BGR conversion
  rotate         : rotate
  mirror         : horizontal mirror
  palette        : 8bpp indexed (using palette) -> BGR 15/16/24/32 conversion
  pp7            : postprocess 7
  lavc           : realtime mpeg1 encoding with libavcodec
  lavcdeint      : libavcodec's deinterlacing filter
  screenshot     : screenshot to file
  dvbscale       : calc Y scaling for DVB card
  cropdetect     : autodetect crop size
  test           : test pattern generator
  noise          : noise generator
  yvu9           : fast YVU9->YV12 conversion
  eq             : soft video equalizer
  eq2            : Software equalizer
  halfpack       : yuv planar 4:2:0 -> packed 4:2:2, half height
  dint           : drop interlaced frames
  1bpp           : 1bpp bitmap -> YUV/BGR 8/15/16/32 conversion
  2xsai          : 2xSai BGR bitmap 2x scaler
  unsharp        : unsharp mask & gaussian blur
  swapuv         : UV swapper
  il             : (de)interleave
  fil            : fast (de)interleaver
  boxblur        : box blur
  sab            : shape adaptive blur
  smartblur      : smart blur
  perspective    : perspective correcture
  down3dright    : convert stereo movie from top-bottom to left-right field
  field          : extract single field
  denoise3d      : 3D Denoiser (variable lowpass filter)
  hqdn3d         : High Quality 3D Denoiser
  detc           : de-telecine filter
  telecine       : telecine filter
  tinterlace     : temporal field interlacing
  tfields        : temporal field separation
  ivtc           : inverse telecine, take 2
  ilpack         : 4:2:0 planar -> 4:2:2 packed reinterlacer
  dsize          : reset displaysize/aspect
  decimate       : near-duplicate frame remover
  softpulldown   : mpeg2 soft 3:2 pulldown
  pullup         : pullup (from field sequence to frames)
  filmdint       : Advanced inverse telecine filer
  framestep      : Dump one every n / key frames
  tile           : Make a single image tiling x/y images
  delogo         : simple logo remover
  remove-logo    : Removes a tv logo based on a mask image.
  hue            : hue changer
  spp            : simple postprocess
  uspp           : ultra simple/slow postprocess
  fspp           : fast simple postprocess
  qp             : QP changer
  mcdeint        : motion compensating deinterlacer
  geq            : generic equation filter
  yuvcsp         : yuv colorspace converter
  kerndeint      : Kernel Deinterlacer
  rgbtest        : rgbtest
  phase          : phase shift fields
  divtc          : inverse telecine for deinterlaced video
  harddup        : resubmit duplicate frames for encoding
  softskip       : soft (post-filter) frame skipping for encoding
  ass            : Render ASS/SSA subtitles
  yadif          : Yet Another DeInterlacing Filter
  blackframe     : detects black frames
  ow             : overcomplete wavelet denoiser
  fixpts         : Fix presentation timestamps

0 comments: