ffmpeg-usage
ffmpeg常用命令参数
devices
show system devices/codecs/..
1 | ffmpeg -devices |
video
video encoder
1 | -c:v libx264 -v profile baseline -s 640x480 -b:v 512k -g 12 |
-c:v: codec of video
-b:v bitrate: bitrate of video(-b)
-s size: frame size(WxH)
-r rate: frame rate(HZ, e.g. 90000)
-g size: gop size(default 12)
-aspect aspect: aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-v profile baseline: codec profile
-keyint_min
-force_key_frames timestamps: force key frames at timestamps, e.g. -force_key_frames 0,2,4,6,8
-vn: diasbale video
if issues happen as below:
1). “ffmpeg Past duration 0.999992 too large”
due to uncertain framerates, fix it by setting -filter:v fps=(your framerate).
1 | -filter:v fps=20 |
2). “[video input] too full or near too full”
This is because h264 encoder requires yuv420 input
1 | -pix_fmt yuv420p |
audio
1 | -c:a aac -ar 44100 -ac 1 -ab 64k -strict -2 -f flv rtmp://localhost/hls/test |
-c:a codec: codec of audio
-b:a bitrate: audio bitrate(-ab)
-ar rate: audio sampling rate(HZ, default 0)
-ac channels: audio channels(default 0)
-f fmt: force format
-an: disable audio
outputs
duplicate outputs. One to file, second to nginx-rtmp.
1 | ffmpeg -i input1 -i input2 |
examples
ffmpeg examples
1 | ffmpeg -re -i test.mp4 -c copy -f flv rtmp://localhost/hls/test0 |
ffplay examples
1 | ffplay -fflags nobuffer rtmp://localhost/hls/mystream -loglevel verbose |

皖ICP备2026004021号-1