FFmpeg h264 编码支持
- See http://ubuntuforums.org/showthread.php?t=786095 for configuration of FFmpeg and libx264 on ubuntu 10.04
FFmpeg 参数选项简要说明
main options
-i filename
– 指定输入文件-y
– Overwrite output files-target
– Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", etc.). All the format options (bitrate, codecs, buffer sizes) are then set automatically. It is one of the most useful options of FFmpeg. It instructs FFmpeg to just "do what it takes" for the target file to be usable.
视频剪辑相关参数
-ss
– 设定剪辑开始时间(支持[hh --mm --ss[.xxx]
)格式-t
– 设定剪辑长度(支持[hh --mm --ss[.xxx]
)格式-fs
– 设定文件大小限制
video options
-b bitrate
– 设定比特率(默认为 200 kb/s)-r fps
– frame rate(默认为 25)-s size
– set frame size- wxh (width x height) or
- abbreviations (qcif(176x144), vga(640x480), wvga(852x480)
-aspect aspect
– 设定 aspect ratio(4:3, 16:9, 30:9, 1:3 or 1.333, 1.777 etc.)-sameq
– use same video quality as source (implies VBR).-vcodec
– codec: force video codec to codec. Use the copy special value to tell that the raw codec data must be copied as is.-newvideo
– add a new video stream to the current output stream.-pass n
– 选择处理遍数(1 或者 2)。两遍编码非常有用。第一遍生成统计信息,第二遍生成精确的请求的码率-map input_{streamid[}:sync_{streamid]}
– Set stream mapping from input streams to output streams.-itsoffset offset
– Set the input time offset in seconds.[-]hh:mm:ss[.xxx]
syntax is also supported. This option affects all the input files that follow it.
crop options(视频剪裁选项说明)
-crop x:y:width:height
– Crop the input video to x:y:width:height.-croptop
-cropbottom
-cropleft
-cropright
ad and filter options
-vf filter_graph
-vf pad=width:height:x:y:color
(这个命令可以给裁剪后的视频增加上下两个 pad,形成电影似的效果)
audio options
-ar freq
– set the audio sampling frequency(default=44100Hz)-ab bitrate
– 设定比特率(默认为 64 K)-aq q
– set the audio quality-ac channels
– set the number of audio channels(default=1)-acodec codec
– force audio codec to codec. Use the copy special value to specify that the raw codec data must be copied as is.-newaudio
– add a new audio track to the output file. If you want to specify parameters, do so before -newaudio (-acodec
,-ab
, etc.).
subtitle options
-scodec codec
– force subtitle codec ('copy' to copy stream).-newsubtitle
– add a new subtitle stream to the current output stream.
disable options
-an
– disable audio recording.-vn
– disable video recording.-sn
– disable subtitle recording.
frames
-dframes number
– set the number of data frames to record-vframes number
– set the number of video frames to record-aframes number
– set the number of audio frames to record
preset files
-vpre
-apre
-spre
-fpre
FFmpeg 用法示例
See http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs for more examples
- Basic Usage:
ffmpeg [input options] -i [input file] [output options] [output file]
- Normally the minimum one should specify in an ffmpeg command line would be something like:
ffmpeg -i INFILE -acodec ACODEC -ab 96k -vcodec VCODEC -b 500k OUTFILE
– replacing the capitalised values as appropriate. When using x264, we need to add some extra bits as the defaults are bad. - Getting infos from a video file –
ffmpeg -i video.avi
- Turn X images to a video sequence –
ffmpeg -f image2 -i image%d.jpg video.mpg
- Turn a video to X images:
ffmpeg -i video.mpg image%d.jpg
- Extracting sound from a video, and save it as MP3 –
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
- Convert .avi video to .mpg –
ffmpeg -i video_origine.avi video_finale.mpg
- Convert .avi to animated gif(uncompressed) –
ffmpeg -i video_origine.avi -pix_fmt rgb24 gif_anime.gif
- Mix a video with a sound file –
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
- Compress .avi to VCD mpeg2 NTSC format –
ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg
- Multi-pass encoding with ffmpeg –
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2
- Crop top 30 pixels and bottom 30 pixels to get a new video file – =ffmpeg -i inputfile.flv -croptop 30 -cropbottom 30 -target ntsc-dvd -aspect 16:9 outputfile.mpg=
- Delaying the audio or the video –
ffmpeg -i input_{1} -itsoffset 00:00:03.5 -i input_{2} ...........
FFmpeg learning resources
- Using FFmpeg to manipulate audio and video files – you should see this page at first
- Video/Audio Encoding Cheat Sheet – then you must know this cheat sheet
- A FFmpeg Tutorial For Beginners – so so a tutorial after you see the first tutorial
- Some useful parameters related to h264 using FFmpeg – to be studied.
- How to Write a Video Player in Less Than 1000 Lines – deep into the FFmpeg source code
- Making movies from image files using FFmpeg/mencoder – enjoy it.
- Category:FFmpeg – a wiki about FFmpeg.
Related tools
- transcode
- mencode(from mplayer)
yamdi 给视频增加关键帧
- Yet Another MetaData Injector, see http://yamdi.sourceforge.net/
- options:
-i
– 输入文件-o
– 输出文件-x
– An XML file with the resulting metadata information.-l
– Adds the onLastSecond event(?).
- other tools:
- flvtool2 – written by Ruby, slow, need more memory
- flvmdi – not open source
ffmpegthumbnailer 截取视频的 thumbnail
- ubuntu:
sudo apt-get install ffmpegthumbnailer
- options:
-i<s>
– input file-o<s>
– output file-s<n>
– thumbnail size (default: 128)-q<n>
– image quality (0 = bad, 10 = best) (default: 8) (only for jpeg)-c<s>
– override image format (jpeg or png) (default: determined by filename)-t<n|s>
– time to seek to (percentage or absolute time hh:mm:ss) (default: 10%)-a
– ignore aspect ratio and generate square thumbnail-f
– create a movie strip overlay
Youku 的一些探索
- Youku 网站上的大部分视频都是分段的,一般每段视频在 5–10 分钟之内
- 目前 Youku 网上的视频格式大概有三种:
- 高清 mp4 格式(h264 编码)
- 高清 flv 格式(h264 编码)
- 普通 flv 格式(应该是 h263 编码)