FFMPEG操作指南
文章目录
ffmpeg基本命令
1.分离视频音频流
ffmpeg -i input_file -vcodec copy -an output_file_video //分离视频流
ffmpeg -i input_file -acodec copy -vn output_file_audio //分离音频流
2.视频解复用
ffmpeg –i test.mp4 –vcodec copy –an –f m4v test.264
ffmpeg –i test.avi –vcodec copy –an –f m4v test.264
3.视频转码
ffmpeg –i test.mp4 –vcodec h264 –s 352278 –an –f m4v test.264 //转码为码流原始文件
ffmpeg –i test.mp4 –vcodec h264 –bf 0 –g 25 –s 352278 –an –f m4v test.264 //转码为码流原始文件
ffmpeg –i test.avi -vcodec mpeg4 –vtag xvid –qsame test_xvid.avi //转码为封装文件
4.视频封装
ffmpeg –i video_file –i audio_file –vcodec copy –acodec copy output_file
5.视频剪切
ffmpeg –i test.avi –r 1 –f image2 image-%3d.jpeg //提取图片
ffmpeg -ss 0:1:30 -t 0:0:20 -i input.avi -vcodec copy -acodec copy output.avi //剪切视频
6.视频录制
ffmpeg –i rtsp://192.168.3.205:5555/test –vcodec copy out.avi
7.YUV序列播放
ffplay -f rawvideo -video_size 1920x1080 input.yuv
8.YUV序列转AVI
ffmpeg –s w*h –pix_fmt yuv420p –i input.yuv –vcodec mpeg4 output.avi
9.截取视频的第一帧保存为JPG图片
格式:ffmpeg -i 视频文件名 -y -f image2 -ss 00:00:01 -vframes 1 图片名.jpg
ffmpeg -i lesson001.mp4 -y -f image2 -ss 00:00:01 -vframes 1 firstFrame.jpg
ffmpeg -i lesson002.mpg -y -f image2 -ss 00:00:01 -vframes 1 firstFrame.jpg
ffmpeg -i 1.mp4 -y -f image2 -ss 00:00:01 -vframes 25 firstFrame%d.jpg
10.获取视频时长
格式:ffmpeg -i 视频文件名 2>&1 | grep ‘Duration’ | cut -d ’ ’ -f 4 | sed s/,//
ffmpeg -i lesson003.mpg 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//
11.图片转视频
图片像素必须为偶数,大小最好与原视频完全相同
ffmpeg -y -f image2 -i capture%3d.jpg -r 23.98 img.mp4
12.视频转gif
1.使用ffmpeg自带的转换功能
ffmpeg -y -ss 25 -t 10 -i D:\video_test\gif\1.mp4 -s 134x154 -f gif -r 4 D:\video_test\g