一、ffmpeg 常用参数
1. 指定时间截图
ffmpeg -ss 4750 -i input.mp4 -vframes 1 output.png -y ; open output.png
2. 设置编码IDR间隔,强制
强制idr间隔,参考:
ffmpeg -i in.mp4 -c:v libx264 -keyint_min 1 -g 1 -sc_threshold 0 -an -f mp4 out.mp4 -y
查看当前视频idr间隔:
ffprobe -i in.mp4 -show_frames -of compact -show_entries frame=pict_type | more
参数说明:
其中-keyint_min为最小关键帧间隔,我这里设置为60帧;-sc_threshold这个命令会根据视频的运动场景,自动为你添加额外的I帧,所以会导致你编出来的视频关键帧间隔不是你设置的长度,这是只要将它设为0;更多参考https://blog.csdn.net/u014006343/article/details/39858237
3. 提取 raw、yuv、rgb、h264、aac
提取h264:
ffmpeg -i 2018.mp4 -codec copy -bsf: h264_mp4toannexb -f h264 tmp.264
提取aac:
ffmpeg -i test.mp4 -acodec copy -vn output.aac
提取yuv:
ffmpeg -i out.mp4 -an -c:v rawvideo -pix_fmt yuv420p out.yuv
播放yuv:
ffplay -s 2880x1800 -pix_fmt uyvy422 screen.yuv
提取pcm:
ffmpeg -i 1.mp4 -vn -ar 44100 -ac 2 -f s16le out.pcm
播放pcm:
ffplay -ac 2 -ar 44100 -f s16le out.pcm
提取rgb:
ffmpeg -ss 00:17:15 -t 00:00:15-i 12.mkv -pix_fmt rgb24 11.rgb
更多参考https://www.jianshu.com/p/5702783153df
4. 不转码旋转视频
rotate 有一个注意点,在mp4容器封装可以支持,但是在hls和ts流里面是不支持rotate旋转的。
ffmpeg -i in.mp4 -map_metadata 0 -metadata:s:v rotate="90" -codec copy -y out.mp4
二、ffprobe 常用命令
1. 查看视频的某个字段
ffprobe -i test.mp4 -of compact -show_frames -show_entries frame=key_frame,pkt_pts_time,pict_type,coded_picture_number | grep pict_type=I
2. 查看视频封装信息
ffprobe -show_format -of json test.mp4
3. 查看每一路视频音频流的信息
ffprobe -show_streams -of json test.mp4
只看音频流:
ffprobe -show_streams -select_streams a -of json test.mp4
只看视频流:
ffprobe -show_streams -select_streams v:1 -of json test.mp4
4. 查看封装音视频包的信息
ffprobe -show_packets -select_streams a -of json test.mp4
5. 查看音视频帧信息,解码后数据
ffprobe -show_frames -select_streams a -of json test.mp4
6. 分析计算视频有多少帧数据
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 test.mp4
三、ffplay常用命令
1. ffplay 指定区域、指定时间播放视频
ffplay -ss 10 -i input.mp4 -vf crop=w=100:h=100:x=200:y=500