设为首页 收藏本站
查看: 950|回复: 0

[经验分享] 在CentOS 6中使用mencoder/ffmpeg进行视频转码

[复制链接]

尚未签到

发表于 2016-5-13 07:16:29 | 显示全部楼层 |阅读模式
  MPlayer http://www.mplayerhq.hu/
  FFmpeg http://ffmpeg.org/
  
  使用mencoder转码
  安装mplayer和mencoder
  # yum install mplayer
  
  RPMForge Repository Dependencies Resolved:
  ===============================================================
  Package                       Arch     Version                                    Repository    Size
===============================================================
  Installing:                           
 mplayer                       x86_64   1.0-0.48.svn20100703.el6.rf   rpmforge     4.0 M
Installing for dependencies:          
 mplayer-common        x86_64   1.0-0.48.svn20100703.el6.rf   rpmforge     1.3 M
 mplayer-fonts              noarch    1.1-3.0.rf                                 rpmforge     1.0 M
  
  RPM Fusion Dependencies Resolved:
  ===================================================================
  Package          Arch      Version                                      Repository                      Size
===================================================================
  Installing:
 mplayer          x86_64   1.0-0.140.20120205svn.el6.1   rpmfusion-free-updates   1.1 M
Installing for dependencies:
 mplayer-common   x86_64   1.0-0.140.20120205svn.el6.1   rpmfusion-free-updates   1.2 M
  
  # yum install mencoder
  
  RPMForge Repository Dependencies Resolved:
  ==============================================================
  Package                      Arch         Version                                   Repository    Size
==============================================================
  Installing:                                                                     
 mencoder                     x86_64   1.0-0.48.svn20100703.el6.rf   rpmforge     3.5 M
  
  RPM Fusion Dependencies Resolved:
  ===================================================================
  Package     Arch          Version                                         Repository                      Size
===================================================================
  Installing:
 mencoder    x86_64    1.0-0.140.20120205svn.el6.1      rpmfusion-free-updates    829 k 
  
  查看mencoder版本(官网最新版为4.8)
  RPMForge Repository:
  $ mencoder
MEncoder SVN-r31628-4.4.6 (C) 2000-2010 MPlayer Team
  
  RPM Fusion:
  $ mencoder
MEncoder SVN-r34652-4.4.6 (C) 2000-2012 MPlayer Team
  
  将wmv转换为flv
  $ mencoder -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:last_pred=3:cmp=3:trell:v4mv:cbp:qprd:mv0 -oac mp3lame -lameopts aq=3:preset=64 -lavdopts er=2 -pp 6 -of lavf -srate 44100 -ofps 12 -mc 0 ~/Videos/Wildlife.wmv -o ~/Videos/Wildlife.flv
  
  输出:
  ...
  Skipping frame!
Pos:  30.1s    900f (100%) 27.15fps Trem:   0min   2mb  A-V:0.000 [688:63]
Flushing video frames.
Writing index...
  Video stream:  688.359 kbit/s  (86044 B/s)  size: 2588516 bytes  30.083 secs  900 frames
  Audio stream:   63.874 kbit/s  (7984 B/s)  size: 239852 bytes  30.041 secs
 
  播放转码后的视频
  $ mplayer /boke/Wildlife.flv
  使用RPMForge安装的能正常转码和播放,使用RPM Fusion安装的播放时只有声音。
  
  从官网下载最新源码编译,根据提示对脚本做了修改,如下:
  $ mencoder -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:last_pred=3:cmp=3:trell:v4mv:o=mpv_flags=+cbp_rd:o=mpv_flags=+qp_rd:mv0 -oac mp3lame -lameopts aq=3:preset=64 -lavdopts er=2 -pp 6 -of lavf -srate 44100 -ofps 12 -mc 0 ~/Videos/Wildlife.wmv -o ~/Videos/Wildlife.flv
  转码依然有问题,求有经验的同学指点下编译时要注意的问题及脚本要做怎样的修改。
  
  安装mplayer可选包
  mplayer-doc - MPlayer documentation in various languages
mplayer-gui - GUI for MPlayer
mplayer-tools - Useful scripts for MPlayer
  
  使用FFmpeg转码
  从官网http://ffmpeg.org/download.html下载编译好的tar,解压后直接运行如下命令:
  $ ./ffmpeg -y -i  ~/Videos/Wildlife.wmv -ar 44100 -vcodec libx264  ~/Videos/Wildlife.flv
  播放转码后的视频比mencoder的更清晰,只是速度稍慢,ffmpeg使用更简单。
  
  也可从github https://github.com/FFmpeg/FFmpeg下载源码编译,在INSTALL文件中有安装说明,注意末尾有:
  - Non system dependencies (e.g. libx264, libvpx) are disabled by default.
  因此若要启用x264和lame,在运行./configure时要附加必要的参数,如:
  ./configure --enable-gpl --enable-libx264 --enable-libmp3lame
  
  x264和lame下载地址 
  x264 git clone git://git.videolan.org/x264.git (./configure --enable-shared)
  lame http://sourceforge.net/projects/lame/
  
  编译安装完毕后,执行ffmpeg命令时如出现如下错误:
  ffmpeg: error while loading shared libraries: libx264.so.142: cannot open shared object file: No such file or directory
  解决办法:
  # vi /etc/ld.so.conf
加入:/usr/local/lib
  更改完毕执行:ldconfig
  
  安装其他视频播放器测试
  # yum install smplayer
  # yum install vlc
  
  删除视频播放器
  删除mplayer(注意有个*哦,这样一次把mplayer, mplayer-common, mplayer-fonts, mencoder都删除了)
  # yum erase mplayer*
  
  系统自带的Movie Player不好用,可以考虑删除:
  # yum erase totem
  
  附录转码参数说明(4.8版):
  
  mencoder -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:last_pred=3:cmp=3:trell:v4mv:cbp:qprd:mv0 -oac mp3lame -lameopts aq=3:preset=64 -lavdopts er=2 -pp 6 -of lavf -srate 44100 -ofps 12 -mc 0 {0} -o {1}
  
  −ovc <codec name>
Encode with the given video codec (no default set).
  
  -lavcopts
vcodec=<value> Employ the specified codec (default: mpeg4).
flv
Sorenson H.263 used in Flash Video
  vbitrate=<value> Specify bitrate (default: 800).
WARNING: 1kbit = 1000 bits
4−16000 (in kbit)
16001−24000000 (in bit)
  mbd=<0−2> (also see *cmp, qpel)
Macroblock decision algorithm (high quality mode), encode each macro block in all modes and choose the best. This is slow but results in better quality and file size. When mbd is set to 1 or 2, the value of mbcmp is ignored when comparing macroblocks (the mbcmp value is still used in other places though, in particular the motion search algorithms). If any comparison setting (precmp, subcmp, cmp, or mbcmp) is nonzero, however, a slower but better half-pel motion search will be used, regardless of what mbd is set to. If qpel is set, quarter-pel motion search will be used regardless.
0 Use comparison function given by mbcmp (default).
1 Select the MB mode which needs the fewest bits (=vhq).
2 Select the MB mode which has the best rate distortion.
  last_pred=<0−99>
amount of motion predictors from the previous frame
0 (default)
a Will use 2a+1 x 2a+1 macroblock square of motion vector predictors from the previous frame.
  cmp=<0−2000>
Sets the comparison function for full pel motion estimation (default: 0).
  trell
Trellis searched quantization. This will find the optimal encoding for each 8x8 block. Trellis searched quantization is quite simply an optimal quantization in the PSNR versus bitrate sense (Assuming that there would be no rounding errors introduced by the IDCT, which is obviously not the case.). It simply finds a block for the minimum of error and lambda*bits.
lambda
quantization parameter (QP) dependent constant
bits
amount of bits needed to encode the block
error
sum of squared errors of the quantization
  v4mv  
Allow 4 motion vectors per macroblock (slightly better quality). Works better if used with mbd>0.
  cbp   
Rate distorted optimal coded block pattern. Will select the coded block pattern which minimizes distortion + lambda*rate. This can only be used together with trellis quantization.
  qprd (mbd=2 only)
rate distorted optimal quantization parameter (QP) for the given lambda of each macroblock
  mv0
Try to encode each MB with MV=<0,0> and choose the better one. This has no effect if mbd=0.
  
  -lameopts
aq=<0−9> algorithmic quality (0 − best/slowest, 9 − worst/fastest)
  preset=<value>
medium
VBR encoding, good quality, 150−180 kbps bitrate range
standard
VBR encoding, high quality, 170−210 kbps bitrate range
extreme
VBR encoding, very high quality, 200−240 kbps bitrate range
insane
CBR encoding, highest preset quality, 320 kbps bitrate
<8−320>
ABR encoding at average given kbps bitrate
  
  −lavdopts <option1:option2:...> (DEBUG CODE)
Specify libavcodec decoding parameters. Separate multiple options with a colon.
  er=<value>
Set error resilience strategy.
0: disabled
1: careful (Should work with broken encoders.)
2: normal (default) (Works with compliant encoders.)
3: aggressive (More checks, but might cause problems even for valid bitstreams.)
4: very aggressive
  
  −pp <quality>
Set the DLL postprocess level. This option is no longer usable with −vf pp. It only works with Win32 DirectShow DLLs with internal postprocessing routines. The valid range of −pp values varies by codec, it is mostly 0−6, where 0=disable, 6=slowest/ best.
  
  −of <format>
Encode to the specified container format (default: AVI).
EXAMPLE:
−of avi
Encode to AVI.
−of mpeg
Encode to MPEG (also see −mpegopts).
−of lavf
Encode with libavformat muxers (also see −lavfopts).
−of rawvideo
raw video stream (no muxing − one video stream only)
−of rawaudio
raw audio stream (no muxing − one audio stream only)
  
  −srate <Hz>
Select the output sample rate to be used (of course sound cards have limits on this). If the sample frequency selected is different from that of the current media, the resample or lavcresample audio filter will be inserted into the audio filter layer to compensate for the difference. The type of resampling can be controlled by the −af−adv option. The default is fast resampling that may cause distortion.
  
  −ofps <fps>
Specify a frames per second (fps) value for the output file, which can be different from that of the source material. Must be set for variable fps (ASF, some MOV) and progressive (30000/1001 fps telecined MPEG) files.
  
  −mc <seconds/frame>
maximum A-V sync correction per frame (in seconds)
−mc 0 should always be combined with −noskip for mencoder, otherwise it will almost certainly cause A-V desync.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-216228-1-1.html 上篇帖子: centos 下面/etc/fstab 错误修复方法 下篇帖子: Problem installing RMagick rubygem on Centos 6.3
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表