ffmpeg命令行工具的命令列表。翻译自FFmpeg cheat sheet
下载 FFmpeg: https://www.ffmpeg.org/download.html
完整文档: https://www.ffmpeg.org/ffmpeg.html
ffmpeg -i in.mp4 out.avi
ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4
Use the crf (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to -crf 18. Use the preset parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264
ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4
无重新编码:
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
-ssspecifies the start time, e.g.00:01:23.000or83(in seconds)-tspecifies the duration of the clip (same format).- Recent
ffmpegalso has a flag to supply the end time with-to. -ccopy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.
带重新编码:
如果不使用-c复制选项,则ffmpeg将根据您选择的格式自动对输出的视频和音频重新编码。要获得高质量的视频和音频,请阅读 x264 Encoding Guide 和 AAC Encoding Guide.
例如:
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4
从in0.mp4复制视频并从in1.mp4复制音频:
ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4
- With -c copy the streams will be
stream copied, not re-encoded, so there will be no quality loss. If you want to re-encode, see FFmpeg Wiki: H.264 Encoding Guide. - The
-shortestoption will cause the output duration to match the duration of the shortest input stream. - See the
-mapoption documentation for more info.
首先,制作一个文本文件
file 'in1.mp4'
file 'in2.mp4'
file 'in3.mp4'
file 'in4.mp4'
然后运行ffmpeg:
ffmpeg -f concat -i list.txt -c copy out.mp4
延迟影片3.84秒:
ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
延迟音频3.84秒:
ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
用 libass (确保您的ffmpeg安装在配置--enable-libass中具有该库).
首先将字幕转换为.ass格式:
ffmpeg -i sub.srt sub.ass
然后使用视频滤镜添加它们:
ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4
提取1到5秒之间以及11到15秒之间的所有帧:
ffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png
仅每秒提取一帧:
ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png
顺时针旋转90:
ffmpeg -i in.mov -vf "transpose=1" out.mov
对于transpose参数,您可以传递:
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
使用-vf“ transpose = 2,transpose = 2”180度.
- 找到播放列表文件, e.g. using Chrome > F12 > Network > Filter: m3u8
- 下载并连接视频片段:
ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
如果您收到“协议'https不在白名单'文件,密码'上!”错误,添加protocol_whitelist选项:
ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
用静音取代音频的前90秒:
ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='lte(t,90)':volume=0" out.mp4
用静音替换1'20“和1'30”之间的所有音频:
ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,80,90)':volume=0" out.mp4
使用“还有另一个反交错滤镜”进行反交错.
ffmpeg -i in.mp4 -vf yadif out.mp4
参数:-r标记图像帧速率(每个图像的倒数时间); -vf fps = 25标记输出的真实帧率
ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
- 提取所有帧:
ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner - 每秒提取一帧:
ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner - 仅提取一帧:
ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg