🎬 FFmpeg 命令速查
基本信息
查看版本bash
ffmpeg -version查看支持的编码器/解码器bash
ffmpeg -encoders
ffmpeg -decoders
ffmpeg -codecs查看文件信息bash
ffprobe input.mp4
ffprobe -v quiet -print_format json -show_streams input.mp4格式转换
MP4 → MKV(拷贝流,秒转)bash
ffmpeg -i input.mp4 -c copy output.mkvMP4 → AVI(重新编码)bash
ffmpeg -i input.mp4 output.aviWAV → MP3bash
ffmpeg -i input.wav -codec:a libmp3lame -q:a 2 output.mp3提取音频bash
ffmpeg -i input.mp4 -vn -acodec copy output.aac提取视频(去掉音频)bash
ffmpeg -i input.mp4 -an -vcodec copy output.mp4编码参数
H.264 编码 + AAC 音频bash
ffmpeg -i input.avi -c:v libx264 -c:a aac output.mp4指定 CRF 质量(0~51,越小质量越高,推荐 18~28)bash
ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4指定码率bash
ffmpeg -i input.mp4 -b:v 2M -b:a 128k output.mp4指定分辨率bash
ffmpeg -i input.mp4 -s 1280x720 output.mp4
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4H.265 编码(体积更小)bash
ffmpeg -i input.mp4 -c:v libx265 -crf 28 output.mp4裁剪与拼接
截取片段(从第10秒开始,持续30秒)bash
ffmpeg -i input.mp4 -ss 00:00:10 -t 30 -c copy output.mp4截取到指定时间点bash
ffmpeg -i input.mp4 -ss 10 -to 40 -c copy output.mp4拼接多个文件bash
# 先创建 filelist.txt
# file 'input1.mp4'
# file 'input2.mp4'
ffmpeg -f concat -i filelist.txt -c copy output.mp4截图与 GIF
截取某一帧(第10秒)bash
ffmpeg -i input.mp4 -ss 10 -vframes 1 output.jpg每隔 N 秒截一张图bash
ffmpeg -i input.mp4 -vf fps=1/10 thumb_%03d.jpg
# fps=1/10 表示每10秒1张转 GIFbash
ffmpeg -i input.mp4 -ss 0 -t 5 -vf "fps=10,scale=320:-1" output.gif滤镜
调整亮度bash
ffmpeg -i input.mp4 -vf "eq=brightness=0.1" output.mp4调整对比度bash
ffmpeg -i input.mp4 -vf "eq=contrast=1.2" output.mp4调整音量bash
ffmpeg -i input.mp3 -af "volume=1.5" output.mp3添加文字水印bash
ffmpeg -i input.mp4 -vf "drawtext=text='Hello':x=10:y=10:fontsize=24:fontcolor=white" output.mp4添加图片水印bash
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4视频旋转bash
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
# 0=90度逆时针+垂直翻转 1=90度顺时针 2=90度逆时针 3=90度顺时针+垂直翻转RTSP / RTMP 推流拉流
拉流并保存bash
ffmpeg -i rtsp://192.168.1.100:554/live -c copy output.mp4拉流并播放(使用 ffplay)bash
ffplay rtsp://192.168.1.100:554/live文件推流到 RTMPbash
ffmpeg -re -i input.mp4 -c copy -f flv rtmp://server/live/streamRTSP 转 RTMPbash
ffmpeg -i rtsp://src/live -c copy -f flv rtmp://dst/live/stream循环推流bash
ffmpeg -re -stream_loop -1 -i input.mp4 -c copy -f flv rtmp://server/live/stream原始 YUV 处理
播放 YUV 原始文件bash
ffplay -f rawvideo -pix_fmt nv12 -s 1920x1080 input.nv12
ffplay -f rawvideo -pix_fmt yuyv422 -s 1920x1080 input.yuyv
ffplay -f rawvideo -pix_fmt yuv420p -s 1920x1080 input.yuvYUV → MP4bash
ffmpeg -f rawvideo -pix_fmt nv12 -s 1920x1080 -i input.nv12 -c:v libx264 output.mp4MP4 → YUVbash
ffmpeg -i input.mp4 -pix_fmt nv12 -f rawvideo output.nv12性能优化
使用硬件加速(NVIDIA)bash
ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc output.mp4多线程编码bash
ffmpeg -i input.mp4 -c:v libx264 -threads 4 output.mp4快速编码(牺牲压缩率)bash
ffmpeg -i input.mp4 -c:v libx264 -preset ultrafast output.mp4
# preset: ultrafast / superfast / veryfast / faster / fast / medium / slow / slower / veryslow