本文共 2652 字,大约阅读时间需要 8 分钟。
ffmpeg 在转码 -ss accurate_seek 参数分析,是否可以精准的seek视频流。
重新编码片源,设置片源gop间隔为10秒,帧率30fps,同时为每帧图像添加时间戳水印,素材时长为5分钟
转码命令: ffmpeg -t 5:00 -i input.mp4 -vf “drawtext=fontsize=120:text=’%{pts:hms}’” -c:v libx264 -r 30 -g 300 -s 1280x720 -preset veryfast -crf 23 -an -f mp4 test.mp4 -yffmpeg -t 5:00 -i input.mp4 -vf "drawtext=fontsize=120:text='%{pts\:hms}'" -c:v libx264 -r 30 -g 300 -s 1280x720 -preset veryfast -crf 23 -an -f mp4 test.mp4 -y
校验:
ffprobe -i test.mp4 -of compact -show_frames -show_entries frame=key_frame,pkt_pts_time,pict_type,coded_picture_number | grep pict_type=Iffprobe -i test.mp4 -of compact -show_frames -show_entries frame=key_frame,pkt_pts_time,pict_type,coded_picture_number | grep pict_type=I
查看关键帧信息
frame|key_frame=1|pkt_pts_time=0.000000|pict_type=I|coded_picture_number=0frame|key_frame=1|pkt_pts_time=3.766667|pict_type=I|coded_picture_number=113frame|key_frame=1|pkt_pts_time=13.433333|pict_type=I|coded_picture_number=403frame|key_frame=1|pkt_pts_time=20.433333|pict_type=I|coded_picture_number=613frame|key_frame=1|pkt_pts_time=29.033333|pict_type=I|coded_picture_number=871frame|key_frame=1|pkt_pts_time=35.466667|pict_type=I|coded_picture_number=1064frame|key_frame=1|pkt_pts_time=42.166667|pict_type=I|coded_picture_number=1265frame|key_frame=1|pkt_pts_time=47.866667|pict_type=I|coded_picture_number=1436frame|key_frame=1|pkt_pts_time=53.700000|pict_type=I|coded_picture_number=1611frame|key_frame=1|pkt_pts_time=63.700000|pict_type=I|coded_picture_number=1911frame|key_frame=1|pkt_pts_time=67.500000|pict_type=I|coded_picture_number=2025frame|key_frame=1|pkt_pts_time=77.500000|pict_type=I|coded_picture_number=2325frame|key_frame=1|pkt_pts_time=87.200000|pict_type=I|coded_picture_number=2616frame|key_frame=1|pkt_pts_time=96.433333|pict_type=I|coded_picture_number=2893frame|key_frame=1|pkt_pts_time=101.666667|pict_type=I|coded_picture_number=3050frame|key_frame=1|pkt_pts_time=107.300000|pict_type=I|coded_picture_number=3219frame|key_frame=1|pkt_pts_time=114.466667|pict_type=I|coded_picture_number=3434frame|key_frame=1|pkt_pts_time=120.633333|pict_type=I|coded_picture_number=3619frame|key_frame=1|pkt_pts_time=130.633333|pict_type=I|coded_picture_number=3919frame|key_frame=1|pkt_pts_time=137.400000|pict_type=I|coded_picture_number=4122frame|key_frame=1|pkt_pts_time=142.666667|pict_type=I|coded_picture_number=4280frame|key_frame=1|pkt_pts_time=150.100000|pict_type=I|coded_picture_number=4503
time ffmpeg -ss 145 -i test.mp4 -vframes 1 test.jpg -y; open test.jpgtime ffmpeg -accurate_seek -i test.mp4 -ss 145 -vframes 1 test.jpg -y; open test.jpg
感兴趣可以试试
参考:
https://trac.ffmpeg.org/wiki/Seeking转载地址:http://nqfli.baihongyu.com/