ffmpeg参数优化
kevin.Zhu 发布于:2017-10-11 1:36 分类:视频直播 有 15 人浏览,获得评论 0 条
http://blog.sina.com.cn/s/blog_80ce3a550102w1i3.html
http://www.cnblogs.com/wainiwann/p/4128154.html
http://blog.csdn.net/defonds/article/details/9274479/ #ffmpeg参数详解
http://blog.csdn.net/wutong_login/article/details/42292787 #使用Nginx+FFMPEG搭建HLS直播转码服务器
基本选项: http://keren.iteye.com/blog/1773536 |
|
---|---|
-formats | 输出所有可用格式 |
-f fmt | 指定格式(音频或视频格式) |
-i filename | 指定输入文件名,在linux下当然也能指定:0.0(屏幕录制)或摄像头 |
-y |
覆盖已有文件 |
-t duration | 记录时长为t |
-fs limit_size | 设置文件大小上限 |
-ss time_off | 从指定的时间(s)开始, [-]hh:mm:ss[.xxx]的格式也支持 |
-itsoffset time_off | 设置时间偏移(s),该选项影响所有后面的输入文件。该偏移被加到输入文件的时戳,定义一个正偏移意味着相应的流被延迟了 offset秒。 [-]hh:mm:ss[.xxx]的格式也支持 |
-title string | 标题 |
-timestamp time | 时间戳 |
-author string | 作者 |
-copyright string | 版权信息 |
-comment string | 评论 |
-album string | album名 |
-v verbose | 与log相关的 |
-target type | 设置目标文件类型("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...) |
-dframes number | 设置要记录的帧数 |
视频选项: | |
-b | 指定比特率(bits/s),似乎ffmpeg是自动VBR的,指定了就大概是平均比特率,指定码率注意单位是bit/s,所以我们一般要加k,比如 -b 1000k 就是1000kb/s |
-bitexact | 使用标准比特率,也支持M,比如4M |
-vb | 指定视频比特率(bits/s) |
-vframes number | 设置转换多少桢(frame)的视频 |
-r rate | 帧速率(fps) (可以改,确认非标准桢率会导致音画不同步,所以只能设定为15或者29.97) |
-s size | 指定分辨率 (320x240) |
-aspect aspect | 设置视频长宽比(4:3, 16:9 or 1.3333, 1.7777) |
-croptop size | 设置顶部切除尺寸(in pixels) |
-cropbottom size | 设置底部切除尺寸(in pixels) |
-cropleft size | 设置左切除尺寸 (in pixels) |
-cropright size | 设置右切除尺寸 (in pixels) |
-padtop size | 设置顶部补齐尺寸(in pixels) |
-paom size | 底补齐(in pixels) |
-padleft size | 左补齐(in pixels) |
-padright size | 右补齐(in pixels) |
-padcolor color | 补齐带颜色(000000-FFFFFF) |
-vn | 取消视频 |
-vcodec codec | 强制使用codec编解码方式('copy' to copy stream) |
-sameq | 使用同样视频质量作为源(VBR) |
-pass n | 选择处理遍数(1或者2)。两遍编码非常有用。第一遍生成统计信息,第二遍生成精确的请求的码率 |
-passlogfile file | 选择两遍的纪录文件名为file |
-newvideo | 在现在的视频流后面加入新的视频流 |
|
|
高级视频选项 | |
-pix_fmt format | set pixel format, 'list' as argument shows all the pixel formats supported |
-intra | 仅适用帧内编码 |
-qscale q | 以<数值>质量为基础的VBR,取值0.01-255,约小质量越好 |
-loop_input | 设置输入流的循环数(目前只对图像有效) |
-loop_output | 设置输出视频的循环数,比如输出gif时设为0表示无限循环 |
-g int | 设置图像组大小 |
-cutoff int | 设置截止频率 |
-qmin int | 设定最小质量,与-qmax(设定最大质量)共用,比如-qmin 10 -qmax 31 |
-qmax int | 设定最大质量 |
-qdiff int | 量化标度间最大偏差 (VBR) |
-bf int | 使用frames B 帧,支持mpeg1,mpeg2,mpeg4 |
音频选项: |
|
-ab | 设置比特率(单位:bit/s,也许老版是kb/s)前面-ac设为立体声时要以一半比特率来设置,比如192kbps的就设成96,转换 默认比特率都较小,要听到较高品质声音的话建议设到160kbps(80)以上。 |
-aframes number | 设置转换多少桢(frame)的音频 |
-aq quality | 设置音频质量 (指定编码) |
-ar rate | 设置音频采样率 (单位:Hz),PSP只认24000 |
-ac channels | 设置声道数,1就是单声道,2就是立体声,转换单声道的TVrip可以用1(节省一半容量),高品质的DVDrip就可以用2 |
-an | 取消音频 |
-acodec codec | 指定音频编码('copy' to copy stream) |
-vol volume | 设置录制音量大小(默认为256) <百分比> ,某些DVDrip的AC3轨音量极小,转换时可以用这个提高音量,比如200就是原来的2倍 |
-newaudio | 在现在的音频流后面加入新的音频流 |
字幕选项: | |
-sn | 取消字幕 |
-scodec codec | 设置字幕编码('copy' to copy stream) |
-newsubtitle | 在当前字幕后新增 |
-slang code | 设置字幕所用的ISO 639编码(3个字母) |
Audio/Video 抓取选项: | |
-vc channel | 设置视频捕获通道(只对DV1394) |
-tvstd standard | 设置电视标准 NTSC PAL(SECAM) |
The params (FPS is 25):
params->rc.b_cbr = TRUE;
params->rc.i_bitrate = 1500;
params->rc.i_vbv_max_bitrate = 1500;
params->rc.i_vbv_buffer_size = 1500;
params->rc.f_rate_tolerance = 0.05;
ffmpeg中VBR(可变率控制)的设置:
Additional Information & Tips
ABR (Average Bit Rate)
ffmpeg -i input -c:v libx264 -b:v 1000k output.mp4
This provides something of a "running average" target, with the end goal that the final file match this number "overall on average" (so basically, if it gets a lot of black frames, which cost very little, it will encode them with less than the requested bitrate, but then the next few seconds of (non-black) frames it will encode at very high quality, to bring the average back in line). Using 2-pass can help this method to be more effective. You can also use this in combination with a "max bit rate" setting in order to prevent some of the swings.
CBR (Constant Bit Rate)
There is no native CBR mode, but you can "simulate" a constant bit rate setting by tuning the parameters of ABR:
ffmpeg -i input -c:v libx264 -b:v 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
In the above example,
Of course, if it's all just empty/black frames then it will still serve less than that many bits/s but it will raise the quality level as much as it can, up to the crf level.
Creating a live stream with limited bit rate
In this case, you want to have a live stream with more/less constant bit rate (using the option
The typical example would be something like this (as shown in the documentation):
ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi
The key option here is
The suggestion is to play around with the combinations of
There are also
Creating the output file of specific size
For this scenario it is by far the best to use a
CBR simply means that vbv-maxrate is equal to bitrate and that bufsize is set to the appropriate value for the device.
http://qtoue.com/3Jrwd8m3/encoding-h264-cbr-videos-with-ffmpeg.html
Here is what I have for low-latency CBR video to an MPEG tranport stream:
ffmpeg -i sintel_trailer-720p.mp4 -an -tune zerolatency -x264opts bitrate=4000:vbv-maxrate=4000:vbv-bufsize=166 -vcodec libx264 -f mpegts -muxrate 4000K -y trailer.ts
According the x264 developer's blog you set:
- vbv-maxrate = bitrate = B = target bitrate
- vbv-bufsize = B / fps (in this video's case that's 24 fps)
Finally, set the ffmpeg switch for x264 of -tune zerolatency.
下面是一个在项目中使用的配置:
-s 1920*1080 -pix_fmt yuv420p -i xxx.yuv -vcodec libx264 -r 30 -nal-hrd cbr -bufsize 1835k -b:v 4M -bt 4M-minrate 4M -maxrate 4M
注意到设置不同的bitrate需要去调整bufsize来满足CBR的要求。实际得到的码率还是有一点波动,但是已经是非常的接近CBR了。
http://blog.yikuyiku.com/?p=2029