ffmpeg ffmpeg
安装
ffmpeg4.2编译选项
`` example
./configure --enable-libfreetype --enable-libx264 --enable-libx265 --enable-gpl --enable-cuda-nvcc --nvcc=/usr/local/cuda/bin/nvcc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
<h3 id="硬件加速">硬件加速</h3>
<https://trac.ffmpeg.org/wiki/HWAccelIntro>
<https://devblogs.nvidia.com/nvidia-ffmpeg-transcoding-guide/>
- nvenc
ffmpeg configured with –enable-nvenc (default if the drivers are
detected while configuring) Note: FFmpeg uses its own slightly
modified runtime-loader for NVIDIA's CUDA/NVENC/NVDEC-related
libraries. If you get an error from configure complaining about
missing ffnvcodec, this project is what you need. It has a working
Makefile with an install target: make install PREFIX=/usr. FFmpeg
will look for its pkg-config file, called ffnvcodec.pc. Make sure it
is in your PKG<sub>CONFIGPATH</sub>.
bash
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make
sudo make install
<h2 id="安装drawtext filter需要–enable-libfreetype">安装drawtext filter需要–enable-libfreetype</h2>
<h2 id="处理vob文件">处理vob文件</h2>
<h3 id="合并多个vob文件">合并多个vob文件</h3>
example
cat old1.vob old2.vob > new.vob
<h3 id="分割vob文件">分割vob文件</h3>
example
ffmpeg -ss 00:00:00 -t 00:15:00 -i file.vob -sameq file.mp4
ffmpeg -ss 00:00:00 -t 00:15:00 -i file.vob -threads 0 -vcodec libx264 -vpre lossless_fast -crf 17 -acodec libfaac file.mp4
<h2 id="转换成DVD的实例">转换成DVD的实例</h2>
下面的语句能执行,但字幕还有问题。
example
nice -n 0 ffmpeg -ss 3000 -t 60 -i Ratatouille.2007.REPACK.BDRip.X264-TLF.eng.srt -i Ratatouille.2007.REPACK.BDRip.X264-TLF.mkv -threads 4 -qmin 5 -qmax 31 -b 5400k -r 29.970 -vcodec mpeg2video -acodec copy "/home/luyanfei/Public/ratatouille.mpg" -scodec dvdsub -slang en -f srt -newsubtitle -map 1.0 -map 1.1 -map 0
下面是转换小泽征尔维也那新年音乐会用的命令,为最大限度保存原来的视频质量,使用了"-sameq"选项。使用"-qmin
5 -qmax
31"情况下,700M左右的xvid文件生成的mpg只有三百多兆,使用"-sameq"以后,文件变成1.8G。quantizer翻译成“量化器”,在视频中是什么用途?
example
ffmpeg -i 小泽征尔New.Year.Concert.2002.1CD.avi -threads 4 -r 24 -sameq -vcodec mpeg2video -acodec copy concert_cd1.mpg
帧率设置成与原始视频的帧率相同。
<h2 id="字幕处理">字幕处理</h2>
- subtitles filter As of Nov 29, 2012 you can also simply use the
subtitles filter:
example
ffmpeg -i video.avi -vf subtitles=subtitle.srt out.avi
This filter requires ffmpeg to be compiled with –enable-libass (if
you are building FFmpeg yourself, look for the libass-dev package on
Debian-like distributions).
- ass filter Using FFmpeg's ass video filter (see Wikipedia for
Advanced SubStation Alpha), we can draw text of the subtitles into
the movie, like this:
example
ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi
As with the subtitles filter, this filter requires ffmpeg to be
compiled with –enable-libass. If your subtitle is in SubRip,
MicroDVD or any other supported text subtitles, you have to convert
it to ASS before using the filter:
example
ffmpeg -i subtitle.srt subtitle.ass
For Windows users this link may be useful, as you have to setup font
paths just right to get libass to work
- picture based subtitles You can burn "picture based" subtitles into
a movie as well (for instance, dvdsub is a type of picture based
overlay subtitles), by using the overlay filter to overlay the
images. Here is an example - an MKV with dvdsub subtitles in a
separate stream:
example
ffmpeg -i input.mkv -filter_complex "[0:v][0:s]overlay[v]" -map [v] -map 0:a
If you have multiple subtitle streams, you can select which one to
use by replacing \[0:s\] with \[0:s:0\] to select the first subtitle
stream or \[0:s:1\] to select the second subtitle stream, and so on.
See also the official documentation; search for "hardcode".
<h2 id="资源">资源</h2>
<h1 id="Image <span class="tag" tag-name="image"><span class="smallcaps">image</span></span>">Image <span class="tag" tag-name="image"><span class="smallcaps">image</span></span></h1>
<h2 id="概念">概念</h2>
<h3 id="Alpha通道的概念与功能">Alpha通道的概念与功能</h3>
在计算机图形学中,一个RGB颜色模型的真彩图形,用由红、绿、蓝三个色彩信息通道合成的,每个通道用了8位色彩深度,共计24位,包含了所有彩色信息。为实现图形的透明效果,采取在图形文件的处理与存储中附加上另一个8位信息的方法,这个附加的代表图形中各个素点透明度的通道信息就被叫做Alpha通道。
Alpha通道使用8位二进制数,就可以表示256级灰度,即256级的透明度。白色(值为255)的Alpha像素用以定义不透明的彩色像素,而黑色(值为0)的Alpha通道像素用以定义透明像素,介于黑白之间的灰度(值为30-255)的Alpha像素用以定义不同程度的半透明像素。因而通过一个32位总线的图形卡来显示带Alpha通道的图形,就可能呈现出透明或半透明的视觉效果。
一个透明或半透明图形的数学模型应当如下:
为了便于下面的分析,设Alpha值\[0,255\]区间映射为\[0,1\]区间相对应的值表示,即Alpha值为0—1之间的数值。则图形文件中各个像素点可表示为:
Graphx(Redx,Greenx,Bulex,Alphax) 屏幕上相应像素点的显示值就转换为:
Dispx(Redx\*Alphax,Greenx\*Alphax,Bluex\*Alphax)
Alpha通道不仅用于单个图形的透明或半透明显示,更重要的是在图像合成中被广泛运用。
下面是如何根据Alpha通道数据进行图像混合的算法:
事实上,我们把需要组合的颜色计算出不含Alpha分量的原始RGB分量然后相加便可。如:两幅图像分别为A和B,由这两幅图像组合而成的图像称为C,则可用如下四元组表示图A和B,三元组表示图像C:
A:(Ra,Ga,Ba,Alphaa) B:(Rb,Gb,Bb,Alphab) C:(Rc,Gc,Bc)
根据上述算法,则: Rc=Ra\*Alphaa+Rb\*Alphab Gc=Ga\*Alphaa+Gb\*Alphab
Bc=Ba\*Alphaa+Bb\*Alphab
这就是两图像混合后的三原色分量。如果有多幅图像需要混合,则按照以上方法两幅两幅地进行混合。
<h3 id="改变图片大小(Raster Image)">改变图片大小(Raster Image)</h3>
把图片的长宽都缩小成原来的1/2,图片的像素数量会缩小3/4。矩形缩小到原来的1/4。
<h3 id="压缩">压缩</h3>
有损压缩需要注意累积损失的问题,A-\>A1,会有损失,A1-\>A2,这一步也许只是将图片做了一次旋转,由于要在前一次压缩的基础上再压缩,图像精度的损失就被累加上去了。
<h3 id="两种图片类型">两种图片类型</h3>
Vector Image & Raster Image
<h3 id="Sampling Factor">Sampling Factor</h3>
JPEG和MPEG将使用YUV颜色空间。RGB图片通常把红、绿、蓝三色交织在一起(interlaced,指用三个字节保存一种颜色,每个字节有255种取值)。YUV中的Y指luminance(亮度),相当于原图片的黑白照,而U和V均为chrominance(色度)信息。YUV颜色究竟中,Y,U,V的大小可以各不相同。有时Y可以是U或V的两倍,此时,YUV的比值可以表示成4:2:2。缩小U和V组件容量的操作,称为chroma
subsampling。imagemagick中的操作如下:
example
convert -sampling-factor 2x1 input.png output.jpg
转换完成后,output.jpg的颜色空间为YUV 4:2:2。
<h3 id="sample">sample</h3>
the number of bits per sample,每次抽样所用的比特位数。8 bits per
sample,则抽样值的范围为0-255. the number of samples per
pixel,每个像素包含的抽样数。RGB图像共有三个抽样值,分别是红、绿、蓝。加上透明度,就会是四个抽样值。如果使用palette,那就只有一个抽样值了。imagemagick中的抽样值也叫通道(channel)。
color space是像素的表现形式。RGB color
space就是用红、绿、蓝三种颜色来表示像素。imagemagick中,默认情况下,color
reduction发生在RGB颜色空间中。不过,YUV和YIQ的color
reduction效果更好些。
<http://www.faqs.org/faqs/graphics/colorspace-faq/> 可用的color
space有:CMYK, GRAY, HSL, HWB, OHTA, Rec601Luma, Rec709Luma,
RGB,Transparent, XYZ, YCbCr, YIQ, YPbPr, or YUV。
example
convert -colors numberofcolors -colorspace space input.jpg output.jpg
convert -depth 8 input.jpg output.jpg
图片中用于保存像素信息的方法有很多,包括: • Bilevel: A black-and-white
image where pixels are either on or off. • Grayscale: Pixels are able to
have only one sample, which is why they’re not color. • Palette: Colors
are stored elsewhere in the file, and each pixel references an entry in
this table. • PaletteMatte: A palette with an alpha (transparency)
channel. • TrueColor: A full RGB image. • TrueColorMatte: A full RGB
image with an alpha channel. Often known as RGBA. • ColorSeparation:
Colors are stored separately in the bitmap, so all the red values are
stored together, then all the green, and then all the blue, for example.
• ColorSeparationMatte: Same as ColorSeparation but with an alpha
channel. • Optimize: Whatever works best with the formats you’re working
with and the pixel values actually used in the image.
example
convert -type Palette input.jpg output.jpg
<h3 id="Gamma Correction">Gamma Correction</h3>
两个显示器显示同一幅图像,效果可能会不同,这就是需要gamma校正问题。
example
convert -gamma 1.7 input.png output.jpg
还可以为每个color channel设置不同的gamma校正值。
example
convert -gamma 1.7,2.3,0.7 input.png output.jpg
<h3 id="Color Intent and Profile">Color Intent and Profile</h3>
International Color Consortium (ICC)定义的Color Intent: • Perceptual:
The full range of possible colors in the output device should be used.
The relative spacing of colors is maintained, so if a color falls
outside the range of colors possible on the device, then the space
between all colors will be reduced. • Saturation: This preserves the
separation of colors. • Relative: If a color falls outside the range of
colors possible, the closest possible color is used. Other colors remain
unchanged. • Absolute: This is the same as relative, but the white point
of the image is preserved. 设置Color Intent:
example
mogrify -intent absolute input.jpg
图片中还可以存放profile,下面的命令移除profile:
example
mogrify +profile input.jpg
<h2 id="imagemagick">imagemagick</h2>
<h3 id="元数据">元数据</h3>
查看元数据:
example
identify -verbose input.jpg
删除部分元数据:
example
convert -strip input.jpg output.jpg
修改元数据信息:
example
convert -comment "Mary had a little lamb" input.jpg output.jpg
mogrify -comment "Mary had a little lamb" input.jpg
mogrify -comment "The size of the file is %b bytes" input.jpg
添加标签,图片浏览器中可以看到:
example
convert -label "This is an image" input.jpg output.jpg
<h3 id="图片缩放">图片缩放</h3>
利用ImageMagicK的convert命令,能很方便的实现图片的放大缩小,可以进行等比例缩放,也能缩放到指定的固定大小。缩放的参数resize,由它来指定缩放后图片的宽高,比如“200×100”。
等比缩放 例如把图片a.jpg缩放到200×100的尺寸,可以用命令:
example
convert -resize 200×100 src.jpg dest.jpg
注意:虽然明确指定了图片大小为200×100,但dest.jpg的不一定就是200×100,因为是等比缩放的,dest.jpg大小取决原始图片比例。假设src.jpg的大小是500×200,那么缩放后dest.jpg的真实大小为200×80,再比如src.jpg的大小是300×200,缩放后的尺寸为150×100。原则是缩放后的尺寸最少有一个是符合宽或高,且另外一个不能大于指定的参数中对应的宽或高。另外可以通过只指定宽或高的方式来进行缩放。例如:
example
convert -resize 200 src.jpg dest.jpg
得到图片宽为200,高根据原始图片比例计算而来
example
convert -resize x100 src.jpg dest.jpg
得到的图片高位100,宽根据原始图片比例计算而来
固定宽高缩放。即不考虑原是图宽高的比例,把图片缩放到指定大小。例如命令:
example
convert -resize 200x100! src.jpg dest.jpg
说明:区别是宽高后面多了一个叹号,此时不管原图片比例如何,缩放后的图片大小都是200×100,这样就可能导致图片变形。注意:在linux环境对参数需要用单引号引起来,而windows下又不能使用单引号。
有条件缩放。可以通过\>或\<符号来控制原始图片是否进行缩放,例如在处理一批尺寸大小各异的图片,只想把尺寸大于给定的值图片才进行缩小,如果没有指定条件,可能会把那些小的图片进行了放大处理。
convert -resize "200x100\>" src.jpg dest.jpg
注解:只有当src.jpg的宽大于200或高大于100时候,才进行缩小处理,
否则生成的dest.jpg和src.jpg具有一样的尺寸。
注意在linux下要用单引号替换成双引号,即'200x100\>'。
convert -resize "200x100\<" src.jpg dest.jpg
注解:只有当src.jpg的宽小于200或高小于100时候,才进行放大处理,
否则生成的dest.jpg和src.jpg具有一样的尺寸。
注意在linux下要用单引号替换成双引号,即'200x100\<'
上述两种有条件缩放是按原始图等比例缩放的,也就是对符合条件的图片进行等比缩放。同时有条件缩放也可以与固定大小缩放联合起来用。例如如下命令。
convert -resize "800x100\>!" src.jpg dest.jpg
注解:假设src.jpg尺寸是300x200。很显然src.jpg的高(200)是大于指定值高(100),
符合缩小的条件,由于执行的不是等比缩放,
所以dest.jpg的尺寸理论上是800x100,由于执行是缩小操作
显然800是超过原始图片宽的,故dest.jpg的宽只能是300
convert -resize "10x1000\<!" src.jpg dest.jpg
注解:假设src.jpg尺寸是300x200,src.jpg的高(200)小于指定值高(1000),
因此该命令将执行放大图片操作,dest.jpg的高将放到到1000,
由于目标图片宽比原始图片还小,但是执行的是放大操作,因此只能用原始图片的宽,
所以得到的dest.jpg的尺寸是300x1000。
<h3 id="压缩">压缩</h3>
- 用compress参数指定压缩算法
example
convert -compress zip input.jpg output.tif
可用的压缩算法还有: • None • Bzip • Fax (CCITT Group 3 fax
compression) • Group4 (CCITT Group 4 fax compression) • JPEG •
JPEG2000 • Lossless (lossless JPEG) • LZW • RLE (run-length
encoding) • Zip (also known as deflate compression)
- Quality
quality选项在不同文件格式中的含义是不同的。用于jpeg时,quality用于指定图片质量,表示丢弃的图片数据量。用于png,则只表示为减少容量而需要的工作量,quality越大,压缩花费的时间越多。
example
convert -quality 10% input.jpg output.jpg
- Creating Interlaced Images
interlaced图片可边下载边显示。
example
convert -interlace line input.jpg output.jpg
- 设定特殊参数
JPEG2000可设定compression factor,该参数会影响压缩比与图像质量:
example
convert input.jpg -define "jp2:rate=0.5" output.jp2
移除该参数的设置用下面的命令:
example
convert +define "jp2:rate" input.jpg output.jpg
移除所有参数定义:
example
convert input.jpg +define "*" output.ps
- 设置Dimensions
只有三种颜色空间的图片可能没有dimension:RGB, Gray, and CMYK。
example
convert -size widthxheight input.raw output.jpg
- 设置Resolution
打印机一般用Resolution来打印图片,而屏幕显示器一般直接忽略resolution。
example
convert -density widthxheight
还可以同时设定resolution的单位:
example
convert -density 72x72 -units PixelsPerInch
- 设置GIF的透明度
GIF的alpha通道与其它图片格式不同。每种颜色都可设定透明度。把蓝色设置为透明的命令如下:
example
convert -transparent blue input.gif output.gif
<h3 id="存储了多个图片的文件格式">存储了多个图片的文件格式</h3>
TIFF、PDF等均可包含多个图片文件。把PDF文件的页面抽取为PNG图片的命令如下:
example
convert input.pdf output-%d.png
输出文件的格式与printf相似,比如可以使用"%03d"。
往gif文件中添加新的图片:
example
convert -insert 4 newimage.gif input.gif output.gif
删除gif中指定的图片:
example
convert -delete 2,4,6 input.gif output.gif
交换gif中两个图片的位置:
example
convert -swap 3,4 input.gif, output.gif
创建多个图片组成的PDF文件:
example
convert image1.jpg image2.jpg image3.jpg output.pdf
处理加密过的PDF文件:
example
convert -authenticate password input.pdf output%d.png
<h3 id="图片动画">图片动画</h3>
设置延时:
example
convert -delay 100 frames-*.jpg output.mpg
Morphing Two Images:
example
convert -morph 1,2 one.png two.png output-%d.png
创建GIF动画:
example
convert -loop 0 frames-*.gif output.gif
convert -loop 3 -pause 5 frames-*.gif output.gif
<h2 id="抓图工具">抓图工具</h2>
<h3 id="Shutter(图形化抓图工具,与SnagIt相似,可抓网页)">Shutter(图形化抓图工具,与SnagIt相似,可抓网页)</h3>
<h3 id="结合cutycapt和xvfb抓取网页图片">结合cutycapt和xvfb抓取网页图片</h3>
example
xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url=http://www.google.com --out=example.png
cutycapt可以把整张网页截成图片,然而如果某个网页是受保护的页面的话,cutycapt就无法访问该网页了。
<h3 id="抓图办法总结">抓图办法总结</h3>
<http://tips.webdesign10.com/how-to-take-a-screenshot-with-ubuntu-linux>
<h1 id="Video <span class="tag" tag-name="video"><span class="smallcaps">video</span></span>">Video <span class="tag" tag-name="video"><span class="smallcaps">video</span></span></h1>
<h2 id="SWF和FLV的区别<http://www.video-to-flash.com/flash_video/>">SWF和FLV的区别<http://www.video-to-flash.com/flash_video/></h2>
SWF (acronym of “Shockwave Flash”) actually is a Flash movie, and it can
be viewed as a Flash animation format, while the FLV is Flash Video,
which is a Flash video format. Both of them can be created by Adobe
Flash. More specifically, SWF is a proprietary file format for
multimedia and especially for vector graphics. It can contain animations
or applets of varying degrees of interactivity and function in order to
be small enough for publication on the Web. Therefore, SWF is currently
the dominant format for displaying animated vector graphics on the web
which is very popular and be commonly used. What's more, SWF is
sometimes used for creating animated display graphics and menus for DVD
movies, and television commercials. FLV, as a Flash video format, is
also very popular on the web. You can always see the videos on the
website like YouTube, Google Video, MySpace TV. After you download the
video from YouTube, you will find the downloaded video's file extension
is .flv, which means it is the FLV video. It is also in a small size and
can be loaded on the web easily. We can take the YouTube video as an
example, the video on the website we can consider as a FLV files with a
player in it. Once you download it to your local computer, you just
download the content, that is the FLV, to your website, but the player
is still on the YouTube website. If you want to play the FLV on your
website, you need to embed it to a player. While the SWF can be seen as
a container and we can embed the FLV files into SWF and play it. So,
under some conditions, SWF file can be divided into two parts, the Flash
Video (animation content) and the SWF player (Adobe Flash Player is
commonly used to play the SWF). Generally, SWF file is a completed,
compiled and published file and can not be edited by Adobe Flash,
however, many SWF converters or FLV encoders do exist. These little
tools will help us convert the video to Flash Video (FLV) or Flash Movie
(SWF) to be published in the website for sharing. As we all know,
because of the widely use of Flash player 8 and Flash player 9, nearly
any Flash Movie can be easily played on every browser.
<h2 id="flv视频转换和flash播放的解决方案">flv视频转换和flash播放的解决方案</h2>
youtube
火起来以后,国内外跟进的一大把,不过技术和流程上没有任何突破,基本上就是服务器自动对用户上传的视频进行压缩,压成可以用flash在线播放的
flv,缩小尺寸并降低码率。然后再用Flash制作一个播放器,可以根据参数在线播放指定的flv视频,当然有些还会加上水印和跳自己网站等功能。
转换工具可以选择ffmpeg和mencoder,这2个都是gnu项目,并且可以非常完美的在linux/Mac/Win32等平台下使用。不过
ffmpeg支持的视频格式较少(不能很方便的支持rmvb,mov等,不过据说Google
Video用的是这个),而mencoder则不能进行截图,所以可以考虑2者结合使用,mencoder负责转换,ffmpeg负责截图。
关于下载和安装,ffmpeg烦一点,官方网站上只提供了svn,需要自己编译。具体可以参考这篇文章,Windows还需要装MinGW来MSYS模拟linux环境,偷懒的话可以直接找个编译好的版本,不过功能可能会不全。
mencoder则很简单,本来就是mplayer的一部分,会装mplayer就成。注意把codecs都装全了
首先通过mencoder把普通视频转化为flv格式,命令如下
example
mencoder test.avi -o test.flv -of lavf -oac mp3lame -lameopts abr:br=32:mode=3 -ovc lavc -lavcopts vcodec=flv:vbitrate=150:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -vf scale=350:-3 -sws 2
mencoder
的参数超级复杂,视音频压缩本身又是一门非常高深的学问,本人略知皮毛,下面只对自己了解的一些参数做些说明,详细解释请看手册
test.avi 输入文件路径,是Mplayer能支持的格式即可 -o test.flv 输出路径
-of lavf 输出格式 lavf表示libavcodec -oac mp3lame
输出音频编码方式,lame是最好的mp3编码器 -lameopts abr:br=32:mode=3
lame的选项
abr代表平均码率,相对于cbr(固定码率)和vbr(可变码率,貌似不支持)
br就是音频的码率,越高音质越好 mode=3,0-3分别代表Stereo,Joint
Stereo,Force
ms<sub>stereo</sub>,Mono(默认为自动,事实上1和3对文件大小的影响并不是很大)
另外可选的还有 vol(音量,取值0-10,数值越大音量越大,不建议修改)等 -srate
22050 声音采样频率设置,也可以选11025,文件可以稍小一点 -ovc lavc
输出视频编码 lavc就是libavcodec -lavcopts lavc的的选项 codec=flv
flv格式压缩 vbitrate=150 视频码率
其他几个选项一概不懂,请看手册(一般来说看了还是不懂) -vf scale=350:-3
-sws 2
缩放视频,指定宽度为350,高度按比例来。质量由-sws选项控制,具体看手册
-ofps 23
设定帧数,缩小帧数对节约文件大小效果不明显,且可能造成画面声音同步。建议不设置
mencoder压缩后生成的flv缺少meta信息,会造成播放时没有进度条等问题,需要再用flvmdi修复一下
example
flvmdi test.flv
生成后的flv通过MPC就可以预览。
example
ffmpeg -i test.flv -ss 10 -vframes 1 -r 1 -ac 1 -ab 2 -s 320×240 -f image2 test.jpg
-ss 10 就是说1秒后的那一帧
然后生成flash视频播放器的话,网上例子很多,自己对Flash研究也不深,也就不多说了,要自定义播放器界面的参考这里
唯一需要补充一下的是视频的smoothing属性,现在的在线播放器尺寸一般都回比实际压缩后的视频尺寸大一些,smoothing=true可以保证放大的质量(包括全屏后的),具体的文章见这里。
很长时间没在技术方面做些研究了,难得在晚上可以清静些。我所了解的内容都已列出,也不会再作进一步研究,所以其他的问题就不要问我了,Google一下会比问我更有效率。
<h2 id="MSS2 decoder">MSS2 decoder</h2>
<http://git.videolan.org/?p=ffmpeg.git;a=commit;h=ee769c6a7c1d4ec6560f5e5a6f457b770b10fb33>
<h2 id="linux-FFmpeg+mencoder支持多种格式转换flv">linux-FFmpeg+mencoder支持多种格式转换flv</h2>
- 所需的 RPM 包
引用: gcc, gcc-c++, gcc-g77, glibc, glibc-devel, autoconf, automake,
libtool, libtool-libs, freetype freetype-devel, libvorbis,
libvorbis-devel, libogg, libogg-devel 上述 RPM 包可以通过 yum (仅限
CentOS Linux)自动安装,如果是 Red Hat Linux,请从安装光盘中提取这些 RPM
包手动安装。
- 以 root 身份登录服务器
- 创建软件包存放处理目录
复制内容到剪贴板 代码:
二、安装播客视频/音频环境
- 下载并解压 FFmpeg 集合包
复制内容到剪贴板 代码:
- 安装 MP3 编码器
复制内容到剪贴板 代码:
- 安装 XVid 编码器
复制内容到剪贴板 代码:
- 安装 yasm 汇编器
复制内容到剪贴板 代码:
将 yasm 加入系统环境变量 复制内容到剪贴板 代码:
- 安装 x264 编码器
\*注:截至本文档发布日期止,x264 官方最新版存在问题,无法在 2 路以上 CPU
的 Intel 系统架构(如:双至强 CPU,四至强 CPU
服务器)中正常编译安装。Comsenz 为此特别对软件进行了修正,请下载 Comsenz
修正版的 x264 软件包! 复制内容到剪贴板 代码:
- 安装 LibDTS 编码器
复制内容到剪贴板 代码:
- 安装 MPEG-4 AAC 编码器
\*注:截至本文档发布日期止,MPEG-4 AAC 编码支持所需的 faad 和 faac
最新软件代码存在问题,无法正常编译安装成功。Comsenz
为此特别对软件进行了修正,请下载 Comsenz 修正版的 faad 和 faac!
复制内容到剪贴板 代码:
\(1\) 安装 faad 复制内容到剪贴板 代码:
\(2\) 安装 faac 复制内容到剪贴板 代码:
- 安装 FFmpeg 编码器
复制内容到剪贴板 代码:
'–prefix=/usr' \\ '–enable-gpl' \\ '–enable-shared' \\ '–enable-mp3lame'
\\ '–enable-amr<sub>nb</sub>' \\ '–enable-amr<sub>wb</sub>' \\
'–enable-amr<sub>if2</sub>' \\ '–enable-libogg' \\ '–enable-vorbis' \\
'–enable-xvid' \\ '–enable-a52' \\ '–enable-a52bin' \\ '–enable-faadbin'
\\ '–enable-dts' \\ '–enable-pp' \\ '–enable-faad' \\ '–enable-faac' \\
'–enable-x264' \\ '–enable-pthreads' \\ '–disable-ffserver' \\
'–disable-ffplay'
至此,博客视频/音频转码支持安装完毕! 三、设定视频转换计划任务
- 下载视频文件转换脚本程序
复制内容到剪贴板 代码:
- 准备脚本程序
复制内容到剪贴板 代码:
mencoder安装篇 1、下载主程序: MPlayer-1.0rc1.tar.bz2
2、下载essential-20061022.tar.bz2,安装: tar vjxf
essential-20061022.tar.bz2 mv essential-20061022 /usr/lib/codes chmod
644 /usr/lib/codes/\* chown root.root /usr/lib/codes/\*
3、下载windows-essential-20061022.zip,安装: unzip
windows-essential-20061022.zip mv windows-essential-20061022
/usr/lib/wincodes chmod 644 /usr/lib/wincodes/\* chown root.root
/usr/lib/wincodes/\* 4、安装mplayer tar vjxf MPlayer-1.0rc1.tar.bz2 cd
MPlayer-1.0rc1 ./configure –prefix=/usr/local/mplayer/ –enable-freetype
–with-codecsdir=/usr/lib/codes/ –with-win32libdir=/usr/lib/wincodes/
–disable-gcc-check –language=zh<sub>CN</sub> make make install
如果你需要使用mplayer在linux下播放视频,还需要加上–enable-gui(图形界面),不过这样就要安装多很多东西了,这里我们只使用它的mencoder,所以–enable-gui可以省略
<h2 id="屏幕录像软件">屏幕录像软件</h2>
- istanbul
- wink (ubuntu 8.04以后不可用)
<http://www.debugmode.com/wink/download.htm>
- xvidcap
在启用compiz的情况下,如果在使用xvidcap过程中选择的边框是某个程序的边框,就会出现下面的提示信息
The program 'xvidcap' received an X Window System error. This
probably reflects a bug in the program. The error was 'BadColor
(invalid Colormap parameter)'.
该问题在<https://bugs.launchpad.net/ubuntu/+source/xvidcap/+bug/244191>" target="_blank">https://bugs.launchpad.net/ubuntu/%2Bsource/xvidcap/%2Bbug/244191"><https://bugs.launchpad.net/ubuntu/+source/xvidcap/+bug/244191>
中有描述。
- vnc2swf pyvnc2swf
- recordmydesktop
<h2 id="mplayer <span class="tag" tag-name="mplayer"><span class="smallcaps">mplayer</span></span>">mplayer <span class="tag" tag-name="mplayer"><span class="smallcaps">mplayer</span></span></h2>
<h3 id="从视频文件中提取音频">从视频文件中提取音频</h3>
- 用dumpaudio选项
example
mplayer -dumpaudio source.rmvb -dumpfile a.mp3
这种办法对音频流为MPEG/AC3的格式会特别有用,某些音频提取出来后可能会无法直接播放。
- 提取PCM流
example
mplayer source.rmvb -ao pcm:file=destination_sound.wav -vo null -vc null
这种办法的缺点是提取的文件特别大,可再用lame等工具压缩。
- 使用mencoder
example
mencoder -o out.mp3 -ovc frameno -oac mp3lame -lameopts cbr:br=128 -of rawaudio -ss 1:30 -endpos 2:45 test.rmvb
<h3 id="碰到过的问题">碰到过的问题</h3>
- 用-oac copy -ovc copy提取出的文件出现音频和视频不同步的情况
在提取过程中不断出现duplicate
frame的信息,最后提出来的文件播放时发现声音和画面不同步。解决的办法是搞清楚是音频出现"duplicate
frame",还是视频出现"duplicate frame",对出现"duplicate
frame"的流用某种压缩算法重新处理。
<h3 id="mencoder制作flv并增大音量">mencoder制作flv并增大音量</h3>
example
mencoder out-1.ogv -o out.flv -of lavf -oac mp3lame -lameopts preset=standard:vol=6 -ovc lavc -lavcopts vcodec=flv
<h3 id="xvidenc">xvidenc</h3>
通过xvidenc可以很方便地配置更好的xvid参数,只要配置合理,xvid也能做出很清晰的影片。
家里用的先科966DVD可以直接播放xvid格式影片,但在压制时可用xvidenc生成mencoder命令,然后再做修改,修改注意点如下:
- 分辨率按480P(720x480)配置,需要注意保持长宽比(-aspect)。
- xvidenc -fq -p nlq 可以比较好地保留原始影片的清晰度。
- AC3或DTS音轨用-oac copy保留。
- 音画不同步是需要加-mc 0。
example
/usr/bin/mencoder "Ratatouille.2007.REPACK.BDRip.X264-TLF.mkv" -o "/home/luyanfei/Xvid_1080.avi" -sub "Ratatouille.2007.REPACK.BDRip.X264-TLF.eng.srt" -subfont-autoscale 2 -unicode -ss 00:02:00 -endpos 00:01:00 -vf softskip,scale=720:480:0,harddup -sws 10 -aspect 2.4138 -channels 6 -oac copy -ovc xvid -xvidencopts fixed_quant=2:threads=4:me_quality=6:vhq=2:max_bframes=2:bvhq=1:trellis:chroma_me:chroma_opt:hq_ac:closed_gop:noqpel:nogmc:nopacked:rc_reaction_delay_factor=0:rc_averaging_period=100:autoaspect:threads=4:nointerlacing -mc 0
<h2 id="libav <span class="tag" tag-name="libav"><span class="smallcaps">libav</span></span>">libav <span class="tag" tag-name="libav"><span class="smallcaps">libav</span></span></h2>
<h3 id="用avconv剪切视频片断">用avconv剪切视频片断</h3>
example
avconv -i [input file] -ss [start time] -t [duration] -codec copy [output file]
avconv -i input.mkv -ss 00:00:42 -t 00:03:26 -codec copy output.mkv
avconv -i input.mkv -ss 00:00:42 -t 00:03:26 -c:v copy -c:a flac output.mkv
<h2 id="tovid <span class="tag" tag-name="tovid"><span class="smallcaps">tovid</span></span>">tovid <span class="tag" tag-name="tovid"><span class="smallcaps">tovid</span></span></h2>
<h3 id="菜单字体">菜单字体</h3>
tovid制作DVD的菜单的字体由imagemagick决定,通过下面的命令可以查看到系统中支持的字体:
example
convert -list font
example
tovid disc -pal -files ./201303happy/201302happy.vob yingcd2/vts_01_1.vob yingcd3/vts_01_1.vob -titles "巧连智2013年2月快乐版" "打败大恐龙(影音2)" "热闹的下雨天(影音3)" -menu-title "巧虎" -menu-font "微软雅黑-Normal" -titles-font "微软雅黑-Normal" -titles-fontsize 14 -out qiao.iso
<h3 id="dvdauthor">dvdauthor</h3>
dvdauthor 0.7版有小bug,可能出现下面的错误
example
ERR: no video format specified for VMGM
解决方法是指定视频的格式:
example
echo 'NTSC' > .config/video_format
或者
example
export VIDEO_FORMAT=NTSC
``上面两个命令也可以设置成PAL。
soft
cinelerra-cv非线性视频编辑软件
<http://cinelerra.org/>genisoimage
说起genisoimage和mkisofs,其实里面是有点故事的。在几年前,genisoimage还没登场,在linux的世界里,大部分发行都是使用cdrtools套件,cdrtools是一位叫Jörg
Schilling的老大而mkisofs就是cdrtools里面的一个子工具,由于mkisofs是GPL发行,于是深受各Linux发行喜欢,当然普及也很广了。而当时cdrtools的Debian维护人员最为卖力,跟Jörg
Schilling关系非常好。
天有不测风云,Sun搞了个叫CDDL的许可,CDDL跟GPL最大的区别是有些专利保护之类的东西在里面。Jörg
Schilling看到有商机,于是把cdrtools一部分改为CDDL许可(不知mkisofs是否也改成CDDL),并且说CDDL跟GPL区别不大,都是免费的嘛。Debian当然不干了,说Sun的人跟他们当面解释过,就别忽悠人了,Jörg
Schilling恼羞成怒,不再理会Debian的要求。
对GPL有严格要求的Debian于是让维护组自行开发了一个叫cdrkit新版本,cdrkit是基于cdrtools的,并且把所有非GPL代码全部剔除,里面的mkisofs也用genisoimage代替了。刚开始genisoimage还不太稳定,不过经过那么长时间,现在的genisoimage已经很成熟了,由于mkisofs已经被Debian废除,其他如ubuntu等当然唯马首是瞻了.
dvdstyler
dvdstyler是图形化的前端工具,很方便使用。
十个非常流行的Linux视频编辑软件
<http://www.csdn.net/article/2011-08-31/303852>流媒体
流化mp4文件被darwin流媒体服务器支持
正常的MP4文件应该是没有被流化,如果要被darwin stream server支持,必须
hint该MP4文件。
关于hint的解释,如下面一段英文:
Hint tracks are a series of instructions in a mp4 container file that
tell a server how to transmit packets. Hint tracks always refer to
another track, most likely an audio or video media track. This series of
instructions tells the server when to send the packet, what type of RTP
header to add, if there is any extra data in the packet, and how much
data to send in the packet. To save on space, a hint can contain a
pointer to the media track, instead of duplicating that data. It will
also tell what SDP to add for the track that is referenced. So a file
that is hinted should have a media track, and an associated hint track
for that media track. There are some mp4 container files that just have
hint tracks - these are called "fat hints" and are usually not playable
locally. These are illegal in ISMA, so we won 't talk about them. To
create hint tracks for a mp4 file is fairly simple with the mp4creator
program. Just execute the: mp4creator -hint= \
例如:
1)被hint之前mp4文件的信息,用mp4info查看文件信息如下:
mp4info ./1.mp4 mp4info version 1.6 ./1.mp4: Track Type Info 1 audio
MPEG-4 AAC LC, 662.165 secs, 121 kbps, 48000 Hz 2 video H264 Main@5.1,
662.562 secs, 1756 kbps, 640x368 @ 29.970025 fps
2)hint 音频
mp4creator -hint=1 ./1.mp4
3)hint视频
mp4creator -hint=2 ./2.mp4
4)查看hint之后的mp4文件信息
mp4info ./1.mp4 mp4info version 1.6 ./1.mp4: Track Type Info 1 audio
MPEG-4 AAC LC, 662.165 secs, 121 kbps, 48000 Hz 2 video H264 Main@5.1,
662.562 secs, 1756 kbps, 640x368 @ 29.970025 fps 3 hint Payload
mpeg4-generic for track 1 4 hint Payload H264 for track 2 Tool:
mp4creator 1.5.0.1