FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见的数据封装格式、多媒体传输协议以及音视频编解码器,提供了录制、转换以及流化音视频的完整解决方案。
ffmpeg命令行参数解释
ffmpeg -i [输入文件名] [参数选项] -f [格式] [输出文件]
ffmpeg [[ options ][ -i input_file ]]... {[ options ] output_file}...
参数选项:
- (1) -an: 去掉音频 -vn:去掉视频 -t:持续时长 -ss:起始时间 -r:帧率(默认为25) -s:帧大小(W*H) -aspect:横纵比(4:3,16:9等)
- (2) -acodec: 音频选项, 一般后面加copy表示拷贝
- (3) -vcodec:视频选项,一般后面加copy表示拷贝
- 格式选项:
- (1) h264: 表示输出的是h264的视频裸流
- (2) mp4: 表示输出的是mp4的视频
- (3) mpegts: 表示ts视频流
ffmpeg命令格式转换
视频格式转换:
ffmpeg -i test.h264 -vcodec copy -f mpegts test.ts # 将h264格式转为ts格式
ffmpeg -i test.h264 -vcodec copy -f mp4 test.mp4 # 将h264格式转为MP4格式
视频拼接:
ffmpeg -i "concat:test1.h264|test2.h264" -vcodec copy -f h264 out12.h264
# 将test1.h264和test2.h264视频拼接起来,输出out12.h264视频
视频截图:
ffmpeg -i test.mp4 -t 0.001 -s 352x240 1.jpg # 在test.mp4中截图
ffmpeg -i test.mp4 -vframes 30 -y -f gif 1.gif # 将test.py前30帧做成gif动图
ffmpeg -i test.mp4 -t 10 -r 1 pic-%03d.jpg # 从视频前10s中取图像,1s提取一帧
常用应用例子
#强制显示宽高
ffplay -i -volume 1 -x 800 -y 480 test_1920x1080.mp4
-framerate 25 :指定帧率
-fs :全屏播放
-an :禁用音频
-vn :禁用视频
-sn :禁用字幕
-ss pos :根据设置的秒进行定位
#在5分 55秒的位置进行播放
ffplay -i -volume 1 -x