`

在CentOS 6中使用mencoder/ffmpeg进行视频转码

阅读更多

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.

分享到:
评论

相关推荐

    linux下Java视频转码、截图开发包:ffmepg3-opencv-javacpp-javacv-centos6&7

    JAVA视频操作的最常用工具包的linux开发库,支持在linux下java调用ffmpeg进行视频操作、转码、截图等操作。如果你自己编译、寻找库费了很长时间而不成功,那么,希望这个资源能够帮到你。 里面的jar及linux动态库,...

    centos 6.5 安装 FFmpeg及转码插件(内附安装方法【自编】)

    在 CentOS 6.5 上安装 FFmpeg 及其转码插件,可以帮助用户完成各种多媒体处理任务,例如将视频格式转换为其他格式,调整视频质量,或者提取音频轨道等。以下是一个详细步骤的安装教程。 ### 一、更新系统 在安装新...

    ffmpeg版本的rpm,适用环境ky10、centos

    2、执行安装 rpm -ivh ffmpeg-6.0-1.el7.centos.x86_64.rpm --nodeps --force 3、安装完成后,目录在/usr/local/ffmpeg /usr/local/ffmpeg/bin/ffmpeg [root@localhost /usr/local/ffmpeg/bin]# ./ffmpeg ffmpeg ...

    Centos6.*一键安装ffmpeg(含赖包)

    在CentOS 6.*系统上安装FFmpeg时,由于该版本的系统相对较旧,可能需要手动解决一些依赖问题。本文将详细介绍如何在CentOS 6.5上一键安装FFmpeg,并包含所有必需的依赖包。 首先,我们需要更新系统的基本软件包,以...

    centos6安装ffmpeg

    OS:CentOS release 6 Kernel: 2.6.32-754.35.1.el6.x86_64 ffmpeg: 2.6.8 虽然下载速度慢点,但成功安装了多台机器

    Redhat 使用CentOS的yum源进行升级或软件安装

    Redhat 使用CentOS的yum源进行升级或软件安装 分类: linux 2012-07-19 15:54 1113人阅读 评论(0) 收藏 举报 Redhat默认的源不但速度不给力,而且软件版本陈旧,今天试着将Redhat默认源替换为CentOS的163源,发现...

    ffmpeg_installer:用于在CentOS中编译,安装和卸载FFmpegLinux Shell脚本

    用于在CentOS中编译,安装和卸载FFmpegLinux Shell脚本(已在7.0上测试)。 该脚本基于。 安装 cd ~ sudo yum -y install git git clone https://github.com/jnaqsh/ffmpeg_installer/ cd ffmpeg_installer chmod +x...

    静态编译的linux下ffmpeg-3.3.3版本及SDK库

    附件为Centos6.6环境下静态编译的ffmpeg-3.3.3版本linux可执行程序和SDK库,其中包含基本的x264、aac编解码库;还增加字幕渲染(drawtext参数)、水印叠加等功能;configure配置参数为: ./configure --target-os=...

    http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

    http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

    centos6.5下安装ffmpeg的详细步骤

    以上步骤提供了在 CentOS 6.5 中安装 FFmpeg 的详细指南,并解决了在实际应用中可能遇到的一些常见问题。通过以上步骤,不仅可以成功安装 FFmpeg,还能确保 FFmpeg 在系统中正常工作,满足多媒体处理的需求。

    docker-centos-ffmpeg:用于构建 FFmpeg 的 Docker 镜像

    CentOS 6 的 FFmpeg 构建 此 Docker 映像为 CentOS 6 构建静态 ffmpeg 库(和二进制文件)。其主要目标是提供将被编译为minidlna的静态库。 rpmforge 上 ffmpeg 的 RPM 非常过时,安装其中几个 RPM 最终会增加很多...

    CentOS配置本地yum源/阿里云yum源/163yuan源并配置yum源的优先级

    由于安装centos后的默认yum源为centos的官方地址,所以在国内使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源(下文介绍如何配置)。 但是以上的方法都是需要网络的...

    FFMPEG4.1 CentOS7 64位运行版

    综上所述,"FFMPEG4.1 CentOS7 64位运行版"是一个针对 CentOS 7 系统优化的 FFmpeg 实现,适合用于多媒体处理、视频转码、音频编码以及实时流媒体推流等任务。由于其内置了 h264 和 AAC 支持,用户可以在各种项目中...

    CentOS7.2 安装L2TP/IPSec 服务端/客户端 ( libreswan+xl2tpd )

    配套说明: http://blog.csdn.net/gogoytgo/article/details/79420745

    centos7 本地yum源配置

    3.下载yum源包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-...

    ffmpeg和mencoder自动安装方式

    CentOS 6.X手动安装最新版ffmpeg和mencoder,此处的ffmpeg_mencoder_install.sh是自动离线安装工具。

    中标麒麟v7/银河麒麟v10/uos20/centos7/centos8/其他linux系统在aarch64/arm64的cpu架构下可以使用的electron

    中标麒麟v7/银河麒麟v10/uos20/centos7/centos8/其他linux系统在aarch64/arm64的cpu架构下可以使用的electron。 该版本采用源码编译而来,解决electron在aarch64下白屏及崩溃等问题。 electron版本:7.1.4 ...

    centos 6.5 安装 FFmpeg及转码插件

    3. 安装FFmpeg 1) 指定第三方插件安装默认目录 [root@localhost ffmpeg]# vi /etc/ld.so.conf include ld.so.conf.d/*.conf /usr/local/bin /usr/local/lib 2) 安装各插件 安装lame [root@localhost ffmpeg]# tar -...

    安卓termux下Centos的 ffmpeg.tar.gz

    在Android的Termux环境中搭建CentOS并安装FFmpeg是一个对技术有一定要求的操作,涉及到的知识点广泛,涵盖了操作系统、终端模拟器、Linux发行版、软件编译与安装等多个方面。以下是对这一过程的详细阐述: 首先,...

    CentOS-7-Base.repo

    http://mirrors.btte.net/centos/7/isos/x86_64/ http://mirrors.cn99.com/centos/7/isos/x86_64/ http://mirrors.sohu.com/centos/7/isos/x86_64/ http://mirrors.aliyun.com/centos/7/isos/x86_64/ ...

Global site tag (gtag.js) - Google Analytics