ffmpeg命令

最近工作常用到ffmpeg 做一些视频数据的处理转换等,用来做测试,今天总结了一下,并参考了网上一些部分朋友的经验,一起在这里汇总了一下,有需要的朋友可以收藏测试一下,有问题可以回帖交流。

1、ffmpeg使用语法

命令格式:
ffmpeg -i [输入文件名] [参数选项] -f [格式] [输出文件]
ffmpeg [[options][`-i’ input_file]]… {[options] output_file}…
1、参数选项:
(1) -an: 去掉音频
(2) -acodec: 音频选项, 一般后面加copy表示拷贝
(3) -vcodec:视频选项,一般后面加copy表示拷贝
2、格式:
(1) h264: 表示输出的是h264的视频裸流
(2) mp4: 表示输出的是mp4的视频
(3)mpegts: 表示ts视频流
如果没有输入文件,那么视音频捕捉(只在Linux下有效,因为Linux下把音视频设备当作文件句柄来处理)就会起作用。作为通用的规则,选项一般用于下一个特定的文件。如果你给 –b 64选项,改选会设置下一个视频速率。对于原始输入文件,格式选项可能是需要的。缺省情况下,ffmpeg试图尽可能的无损转换,采用与输入同样的音频视频参数来输出。(by ternence.hsu)

2、视频转换

#mp4视频转flv
ffmpeg -i 123.mp4 -acodec copy -vcodec copy -f flv test1.flv
1.
2.
#rtsp转rtmp
ffmpeg -i rtsp://admin:Ab123456@172.19.12.113/h265/ch1/av_stream -f flv -r 25 -g 25 -s 640x360 -an rtmp://172.19.12.240/live/test123 -vcodec h264 -f flv -an rtmp://172.19.12.240/live/test123HD
1.
2.
#rtsp转hls
ffmpeg -i rtsp://admin:admin@172.19.12.192/cam/realmonitor?channel=1&subtype=1 -c copy -vcodec h264 -f hls -hls_time 2.0 -hls_list_size 5 -hls_wrap 5 E:\nginx-1.12.2\html\hls\test.m3u8
1.
2.
#本地文件推流(码流复制效率高)
ffmpeg -re -i “E:\ffmpeg-20180227-fa0c9d6-win64-static\bin\1234.mp4” -acodec copy -vcodec copy -f flv -an rtmp://172.19.12.240/MyVideo/stream_4HD
1.
2.
#rtsp转rtmp(码流复制效率高,“rtmp://192.168.174.200:1935/live/a”中live为Nginx的application live名称对应)
ffmpeg -i rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov -acodec copy -vcodec copy -f flv -an rtmp://192.168.174.200:1935/live/a
1.
2.
#mp4画中画
ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex “[1:v]scale=w=176:h=144:force_original_aspect_ratio=decrease[ckout];[0:v][ckout]overlay=x=W-w-10:y=0[out]” -map “[out]” -movflags faststart 3.mp4
1.
2.
​#视频流画中画及混音
ffmpeg.exe -i rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov -i rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov -filter_complex “[1:v]scale=w=176:h=144:force_original_aspect_ratio=decrease[ckout];[0:v][ckout]overlay=x=W-w-10:y=0[out];amix=inputs=2:duration=first:dropout_transition=2” -map “[out]” -f flv -an rtmp://192.168.3.56:1935/MyRed5/test
1.
2.
#从.mp4分离出单独音频和视频
ffmpeg -i 2.mp4 -vcodec copy -an out_video.mp4 -acodec copy -vn out_audio.aac
1.
2.
#保存视频mp4
ffmpeg -y -i rtsp://admin:hik12345@192.168.3.160/Streaming/Channels/1 -vcodec copy -f mp4 c://1.mp4
1.
2.
3、选项

登录后复制
a) 通用选项
-L license
-h 帮助
-fromats 显示可用的格式,编解码的,协议的。。。
-f fmt 强迫采用格式fmt
-I filename 输入文件
-y 覆盖输出文件
-t duration 设置纪录时间 hh:mm:ss[.xxx]格式的记录时间也支持
-ss position 搜索到指定的时间 [-]hh:mm:ss[.xxx]的格式也支持
-title string 设置标题
-author string 设置作者
-copyright string 设置版权
-comment string 设置评论
-target type 设置目标文件类型(vcd,svcd,dvd) 所有的格式选项(比特率,编解码以及缓冲区大小)自动设置,只需要输入如下的就可以了:
ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
-hq 激活高质量设置
-itsoffset offset 设置以秒为基准的时间偏移,该选项影响所有后面的输入文件。该偏移被加到输入文件的时戳,定义一个正偏移意味着相应的流被延迟了 offset秒。 [-]hh:mm:ss[.xxx]的格式也支持
b) 视频选项
-b bitrate 设置比特率,缺省200kb/s
-r fps 设置帧频 缺省25
-s size 设置帧大小 格式为WXH 缺省160X128.下面的简写也可以直接使用:
Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576
-aspect aspect 设置横纵比 4:3 16:9 或 1.3333 1.7777
-croptop size 设置顶部切除带大小 像素单位
-cropbottom size –cropleft size –cropright size
-padtop size 设置顶部补齐的大小 像素单位
-padbottom size –padleft size –padright size –padcolor color 设置补齐条颜色(hex,6个16进制的数,红:绿:兰排列,比如 000000代表黑色)
-vn 不做视频记录
-bt tolerance 设置视频码率容忍度kbit/s
-maxrate bitrate设置最大视频码率容忍度
-minrate bitreate 设置最小视频码率容忍度
-bufsize size 设置码率控制缓冲区大小
-vcodec codec 强制使用codec编解码方式。如果用copy表示原始编解码数据必须被拷贝。
-sameq 使用同样视频质量作为源(VBR)
-pass n 选择处理遍数(1或者2)。两遍编码非常有用。第一遍生成统计信息,第二遍生成精确的请求的码率
-passlogfile file 选择两遍的纪录文件名为file

c)高级视频选项
-g gop_size 设置图像组大小
-intra 仅适用帧内编码
-qscale q 使用固定的视频量化标度(VBR)
-qmin q 最小视频量化标度(VBR)
-qmax q 最大视频量化标度(VBR)
-qdiff q 量化标度间最大偏差 (VBR)
-qblur blur 视频量化标度柔化(VBR)
-qcomp compression 视频量化标度压缩(VBR)
-rc_init_cplx complexity 一遍编码的初始复杂度
-b_qfactor factor 在p和b帧间的qp因子
-i_qfactor factor 在p和i帧间的qp因子
-b_qoffset offset 在p和b帧间的qp偏差
-i_qoffset offset 在p和i帧间的qp偏差
-rc_eq equation 设置码率控制方程 默认tex^qComp
-rc_override override 特定间隔下的速率控制重载
-me method 设置运动估计的方法 可用方法有 zero phods log x1 epzs(缺省) full
-dct_algo algo 设置dct的算法 可用的有 0 FF_DCT_AUTO 缺省的DCT 1 FF_DCT_FASTINT 2 FF_DCT_INT 3 FF_DCT_MMX 4 FF_DCT_MLIB 5 FF_DCT_ALTIVEC
-idct_algo algo 设置idct算法。可用的有 0 FF_IDCT_AUTO 缺省的IDCT 1 FF_IDCT_INT 2 FF_IDCT_SIMPLE 3 FF_IDCT_SIMPLEMMX 4 FF_IDCT_LIBMPEG2MMX 5 FF_IDCT_PS2 6 FF_IDCT_MLIB 7 FF_IDCT_ARM 8 FF_IDCT_ALTIVEC 9 FF_IDCT_SH4 10 FF_IDCT_SIMPLEARM
-er n 设置错误残留为n 1 FF_ER_CAREFULL 缺省 2 FF_ER_COMPLIANT 3 FF_ER_AGGRESSIVE 4 FF_ER_VERY_AGGRESSIVE
-ec bit_mask 设置错误掩蔽为bit_mask,该值为如下值的位掩码 1 FF_EC_GUESS_MVS (default=enabled) 2 FF_EC_DEBLOCK (default=enabled)
-bf frames 使用frames B 帧,支持mpeg1,mpeg2,mpeg4
-mbd mode 宏块决策 0 FF_MB_DECISION_SIMPLE 使用mb_cmp 1 FF_MB_DECISION_BITS 2 FF_MB_DECISION_RD
-4mv 使用4个运动矢量 仅用于mpeg4
-part 使用数据划分 仅用于mpeg4
-bug param 绕过没有被自动监测到编码器的问题
-strict strictness 跟标准的严格性
-aic 使能高级帧内编码 h263+
-umv 使能无限运动矢量 h263+
-deinterlace 不采用交织方法
-interlace 强迫交织法编码仅对mpeg2和mpeg4有效。当你的输入是交织的并且你想要保持交织以最小图像损失的时候采用该选项。可选的方法是不交织,但是损失更大
-psnr 计算压缩帧的psnr
-vstats 输出视频编码统计到vstats_hhmmss.log
-vhook module 插入视频处理模块 module 包括了模块名和参数,用空格分开
D)音频选项
-ab bitrate 设置音频码率
-ar freq 设置音频采样率
-ac channels 设置通道 缺省为1
-an 不使能音频纪录
-acodec codec 使用codec编解码
E)音频/视频捕获选项
-vd device 设置视频捕获设备。比如/dev/video0
-vc channel 设置视频捕获通道 DV1394专用
-tvstd standard 设置电视标准 NTSC PAL(SECAM)
-dv1394 设置DV1394捕获
-av device 设置音频设备 比如/dev/dsp

F)高级选项
-map file:stream 设置输入流映射
-debug 打印特定调试信息
-benchmark 为基准测试加入时间
-hex 倾倒每一个输入包
-bitexact 仅使用位精确算法 用于编解码测试
-ps size 设置包大小,以bits为单位
-re 以本地帧频读数据,主要用于模拟捕获设备
-loop 循环输入流。只工作于图像流,用于ffserver测试

©著作权归作者所有:来自51CTO博客作者gmHappy的原创作品,请联系作者获取转载授权,否则将追究法律责任
ffmpeg 常用命令汇总
https://blog.51cto.com/u_15316394/3218642
查看libx264编码信息
ffmpeg -h encoder=libx264
Encoder libx264 [libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:
General capabilities: delay threads
Threading capabilities: auto
Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21 yuv420p10le yuv422p10le yuv444p10le nv20le
x264编码参数
libx264 AVOptions:
-preset E…V… Set the encoding preset (cf. x264 --fullhelp) (default “medium”)
-tune E…V… Tune the encoding params (cf. x264 --fullhelp)
-profile E…V… Set profile restrictions (cf. x264 --fullhelp)
-fastfirstpass E…V… Use fast settings when encoding first pass (default true)
-level E…V… Specify level (as defined by Annex A)
-passlogfile E…V… Filename for 2 pass stats
-wpredp E…V… Weighted prediction for P-frames
-a53cc E…V… Use A53 Closed Captions (if available) (default true)
-x264opts E…V… x264 options
-crf E…V… Select the quality for constant quality mode (from -1 to FLT_MAX) (default -1)
-crf_max E…V… In CRF mode, prevents VBV from lowering quality beyond this point. (from -1 to FLT_MAX) (default -1)
-qp E…V… Constant quantization parameter rate control method (from -1 to INT_MAX) (default -1)
-aq-mode E…V… AQ method (from -1 to INT_MAX) (default -1)
none E…V…
variance E…V… Variance AQ (complexity mask)
autovariance E…V… Auto-variance AQ
autovariance-biased E…V… Auto-variance AQ with bias to dark scenes
-aq-strength E…V… AQ strength. Reduces blocking and blurring in flat and textured areas. (from -1 to FLT_MAX) (default -1)
-psy E…V… Use psychovisual optimizations. (default auto)
-psy-rd E…V… Strength of psychovisual optimization, in : format.
-rc-lookahead E…V… Number of frames to look ahead for frametype and ratecontrol (from -1 to INT_MAX) (default -1)
-weightb E…V… Weighted prediction for B-frames. (default auto)
-weightp E…V… Weighted prediction analysis method. (from -1 to INT_MAX) (default -1)
none E…V…
simple E…V…
smart E…V…
-ssim E…V… Calculate and print SSIM stats. (default auto)
-intra-refresh E…V… Use Periodic Intra Refresh instead of IDR frames. (default auto)
-bluray-compat E…V… Bluray compatibility workarounds. (default auto)
-b-bias E…V… Influences how often B-frames are used (from INT_MIN to INT_MAX) (default INT_MIN)
-b-pyramid E…V… Keep some B-frames as references. (from -1 to INT_MAX) (default -1)
none E…V…
strict E…V… Strictly hierarchical pyramid
normal E…V… Non-strict (not Blu-ray compatible)
-mixed-refs E…V… One reference per partition, as opposed to one reference per macroblock (default auto)
-8x8dct E…V… High profile 8x8 transform. (default auto)
-fast-pskip E…V… (default auto)
-aud E…V… Use access unit delimiters. (default auto)
-mbtree E…V… Use macroblock tree ratecontrol. (default auto)
-deblock E…V… Loop filter parameters, in alpha:beta form.
-cplxblur E…V… Reduce fluctuations in QP (before curve compression) (from -1 to FLT_MAX) (default -1)
-partitions E…V… A comma-separated list of partitions to consider. Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all
-direct-pred E…V… Direct MV prediction mode (from -1 to INT_MAX) (default -1)
none E…V…
spatial E…V…
temporal E…V…
auto E…V…
-slice-max-size E…V… Limit the size of each slice in bytes (from -1 to INT_MAX) (default -1)
-stats E…V… Filename for 2 pass stats
-nal-hrd E…V… Signal HRD information (requires vbv-bufsize; cbr not allowed in .mp4) (from -1 to INT_MAX) (default -1)
none E…V…
vbr E…V…
cbr E…V…
-avcintra-class E…V… AVC-Intra class 50/100/200 (from -1 to 200) (default -1)
-me_method E…V… Set motion estimation method (from -1 to 4) (default -1)
dia E…V…
hex E…V…
umh E…V…
esa E…V…
tesa E…V…
-motion-est E…V… Set motion estimation method (from -1 to 4) (default -1)
dia E…V…
hex E…V…
umh E…V…
esa E…V…
tesa E…V…
-forced-idr E…V… If forcing keyframes, force them as IDR frames. (default false)
-coder E…V… Coder type (from -1 to 1) (default default)
default E…V…
cavlc E…V…
cabac E…V…
vlc E…V…
ac E…V…
-b_strategy E…V… Strategy to choose between I/P/B-frames (from -1 to 2) (default -1)
-chromaoffset E…V… QP difference between chroma and luma (from INT_MIN to INT_MAX) (default -1)
-sc_threshold E…V… Scene change threshold (from INT_MIN to INT_MAX) (default -1)
-noise_reduction E…V… Noise reduction (from INT_MIN to INT_MAX) (default -1)
-x264-params E…V… Override the x264 configuration using a :-separated list of key=value parameters
H.264编码举例:
x264 --full help

  1. 编码器预设参数设置preset
    –preset Use a preset to select encoding settings [medium]
    Overridden by user settings.
    - ultrafast:
    –no-8x8dct --aq-mode 0 --b-adapt 0
    –bframes 0 --no-cabac --no-deblock
    –no-mbtree --me dia --no-mixed-refs
    –partitions none --rc-lookahead 0 --ref 1
    –scenecut 0 --subme 0 --trellis 0
    –no-weightb --weightp 0
    - superfast:
    –no-mbtree --me dia --no-mixed-refs
    –partitions i8x8,i4x4 --rc-lookahead 0
    –ref 1 --subme 1 --trellis 0 --weightp 1
    - veryfast:
    –no-mixed-refs --rc-lookahead 10
    –ref 1 --subme 2 --trellis 0 --weightp 1
    - faster:
    –no-mixed-refs --rc-lookahead 20
    –ref 2 --subme 4 --weightp 1
    - fast:
    –rc-lookahead 30 --ref 2 --subme 6
    –weightp 1
    - medium:
    Default settings apply.
    - slow:
    –direct auto --rc-lookahead 50 --ref 5
    –subme 8 --trellis 2
    - slower:
    –b-adapt 2 --direct auto --me umh
    –partitions all --rc-lookahead 60
    –ref 8 --subme 9 --trellis 2
    - veryslow:
    –b-adapt 2 --bframes 8 --direct auto
    –me umh --merange 24 --partitions all
    –ref 16 --subme 10 --trellis 2
    –rc-lookahead 60
    - placebo:
    –bframes 16 --b-adapt 2 --direct auto
    –slow-firstpass --no-fast-pskip
    –me tesa --merange 24 --partitions all
    –rc-lookahead 60 --ref 16 --subme 11
    –trellis 2
    ultrafast:最快的编码方式
    superfast:超级快速的编码方式
    veryfast:非常快速的编码方式
    faster:稍微快速的编码方式
    fast:快速的编码方式
    medium:折中的编码方式
    slow:慢的编码方式
    slower:更慢的编码方式
    veryslow:非常慢的编码方式
    placebo:最慢的编码方式
    不同的预设参数对转码效率的影响不同。
    设置ultrafast参数:

ffmpeg -i 222.mp4 -vcodec libx264 -preset ultrafast -b:v 2000k 333.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘222.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.19.100
Duration: 00:00:30.32, start: 0.000000, bitrate: 397 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 261 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fc2f500fc00] using SAR=16/15
[libx264 @ 0x7fc2f500fc00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fc2f500fc00] profile Constrained Baseline, level 2.1
[libx264 @ 0x7fc2f500fc00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=abr mbtree=0 bitrate=2000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to ‘333.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], q=-1–1, 2000 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.35.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 0 vbv_delay: -1
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 aac
frame= 149 fps=0.0 q=16.0 size= 1536kB time=00:00:06.08 bitrate=2068.4kbits/frame= 288 fps=287 q=13.0 size= 2816kB time=00:00:11.60 bitrate=1987.0kbits/frame= 452 fps=301 q=11.0 size= 4608kB time=00:00:18.18 bitrate=2076.3kbits/frame= 613 fps=306 q=11.0 size= 5888kB time=00:00:24.61 bitrate=1959.7kbits/frame= 756 fps=309 q=-1.0 Lsize= 7582kB time=00:00:30.30 bitrate=2049.7kbits/s speed=12.4x
如上,转码速度为12.4倍速。
设置medium参数:

ffmpeg -i 222.mp4 -vcodec libx264 -preset medium -b:v 2000k 333.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘222.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.19.100
Duration: 00:00:30.32, start: 0.000000, bitrate: 397 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 261 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fd62c809200] using SAR=16/15
[libx264 @ 0x7fd62c809200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fd62c809200] profile High, level 2.1
[libx264 @ 0x7fd62c809200] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=2000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to ‘333.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], q=-1–1, 2000 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.35.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 0 vbv_delay: -1
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 aac
frame= 116 fps=0.0 q=9.0 size= 512kB time=00:00:04.73 bitrate= 885.5kbits/sframe= 190 fps=187 q=7.0 size= 1280kB time=00:00:07.70 bitrate=1360.2kbits/sframe= 273 fps=179 q=6.0 size= 2048kB time=00:00:11.02 bitrate=1521.2kbits/sframe= 347 fps=170 q=7.0 size= 3072kB time=00:00:13.97 bitrate=1800.4kbits/sframe= 424 fps=167 q=8.0 size= 3840kB time=00:00:17.06 bitrate=1843.2kbits/sframe= 497 fps=163 q=8.0 size= 4608kB time=00:00:19.96 bitrate=1890.4kbits/sframe= 571 fps=161 q=8.0 size= 5376kB time=00:00:22.91 bitrate=1921.7kbits/sframe= 647 fps=160 q=7.0 size= 6144kB time=00:00:25.98 bitrate=1937.1kbits/sframe= 718 fps=157 q=8.0 size= 6912kB time=00:00:28.81 bitrate=1965.0kbits/sframe= 756 fps=152 q=-1.0 Lsize= 7652kB time=00:00:30.30 bitrate=2068.6kbits/s speed= 6.1x
如上,转码速度为6.1倍速,但图像质量要比ultrafast高。

  1. H.264编码优化参数tune
    –tune Tune the settings for a particular type of source
    or situation
    Overridden by user settings.
    Multiple tunings are separated by commas.
    Only one psy tuning can be used at a time.
    - film (psy tuning):
    –deblock -1:-1 --psy-rd :0.15
    - animation (psy tuning):
    –bframes {+2} --deblock 1:1
    –psy-rd 0.4: --aq-strength 0.6
    –ref {Double if >1 else 1}
    - grain (psy tuning):
    –aq-strength 0.5 --no-dct-decimate
    –deadzone-inter 6 --deadzone-intra 6
    –deblock -2:-2 --ipratio 1.1
    –pbratio 1.1 --psy-rd :0.25
    –qcomp 0.8
    - stillimage (psy tuning):
    –aq-strength 1.2 --deblock -3:-3
    –psy-rd 2.0:0.7
    - psnr (psy tuning):
    –aq-mode 0 --no-psy
    - ssim (psy tuning):
    –aq-mode 2 --no-psy
    - fastdecode:
    –no-cabac --no-deblock --no-weightb
    –weightp 0
    - zerolatency:
    –bframes 0 --force-cfr --no-mbtree
    –sync-lookahead 0 --sliced-threads
    –rc-lookahead 0
    film
    animation
    grain
    stillimage
    psnr
    ssim
    fastdecode
    zerolatency
    如上,可使用以上几个参数进行调优编码,如使用zerolatency会提升效率,因为它降低了因编码导致的延迟。

  2. H.264的profile(档次)与level(等级)设置
    使用baseline profile编码一个H.264视频,不会包含B Slice:

ffmpeg -i input.mp4 -vcodec libx264 -profile:v baseline -level 3.1 -s 352x288 -an -y -t 10 output_baseline.ts
使用ffprobe查看output_baseline.ts中每帧包含B帧的情况:

aiputekiMacBook-Pro:bin aipu$ ffprobe -v quiet -show_frames -select_streams v output_baseline.ts |grep “pict_type=B”|wc -l
0
使用high profile编码一个H.264视频,包含B Slice:

ffmpeg -i input.mp4 -vcodec libx264 -profile:v high -level 3.1 -s 352x288 -an -y -t 10 output_high.ts
使用ffprobe查看output_high.ts中每帧包含B帧的情况:

aiputekiMacBook-Pro:bin aipu$ ffprobe -v quiet -show_frames -select_streams v output_high.ts |grep “pict_type=B”|wc -l
173
如上,baseline profile包含0个B帧,high profile包含173个B帧。

  1. 控制场景切换关键帧插入参数sc_threshold
    不使用ffmpeg命令控制编码时的GOP大小:

ffmpeg -i input.mp4 -c:v libx264 -g 50 output.mp4

如上,使用工具查看GOP间隔不是均匀的。

使用ffmpeg命令控制编码时的GOP大小:

ffmpeg -i input.mp4 -c:v libx264 -g 50 -sc_threshold 0 -y output.mp4

如上,使用工具查看GOP间隔是均匀的。

  1. 设置x264内部参数x264opts
    该参数可以控制帧的顺序及出现频率

设置GOP为50帧,并且不出现B帧:

ffmpeg -i input.mp4 -c:v libx264 -x264opts “bframes=0” -g 50 -sc_threshold 0 output.mp4

如图,使用工具查看output.mp4中并不包含B帧。

设置GOP中每2个P帧之间存放3个B帧:

ffmpeg -i input.mp4 -c:v libx264 -x264opts “bframes=3:b-adapt=0” -g 50 -sc_threshold 0 output.mp4

如图,使用工具查看output.mp4中每2个P帧之间存放了3个B帧。

  1. CBR恒定码率设置参数nal-hrd
    设置VBR(可变码率)、CBR(恒定码率),控制码率的波动,以及设置buffer的大小:

ffmpeg -i input.mp4 -c:v libx264 -x264opts “bframes=10:b-adapt=0” -b:v 1000k -maxrate 1000k -minrate 1000k -bufsize 50k -nal-hrd cbr -g 50 -sc_threshold 0 output.ts
以上命令的具体分析如下:

设置B帧的个数,并且是每2个P帧之间包含10个B帧
设置视频码率为1000kbit/s
设置最大码率为1000kbit/s
设置最小码率为1000kbit/s
设置编码的buffer大小为50KB
设置H.264的编码HRD信号形式为CBR
设置GOP为50帧
设置场景切换不强行插入关键帧

作者:Goning
链接:https://www.jianshu.com/p/49fcae61e58c
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值