![使用 FFMPEG 而不是 ffprobe 从 mp4 视频中提取帧的时间戳](https://linux22.com/image/1599140/%E4%BD%BF%E7%94%A8%20FFMPEG%20%E8%80%8C%E4%B8%8D%E6%98%AF%20ffprobe%20%E4%BB%8E%20mp4%20%E8%A7%86%E9%A2%91%E4%B8%AD%E6%8F%90%E5%8F%96%E5%B8%A7%E7%9A%84%E6%97%B6%E9%97%B4%E6%88%B3.png)
我正在尝试使用 ffmpeg 提取 mp4 视频的时间戳。
使用 ffprobe 如下。
命令:ffprobe -v quiet -f lavfi -print_format json -i "movie=test.mp4" -show_frames -show_entries frame=pkt_pts_time
以下是使用 ffprobe 的输出,但我需要使用 ffmpeg:
{ "frames": [ { "pkt_pts_time": "0.000000" }, { "pkt_pts_time": "0.033367" }, { "pkt_pts_time": "0.066733" } ] }
我需要使用 ffmpeg,因为我必须使用 ffmpeg.js(https://github.com/Kagami/ffmpeg.js) 浏览器端的库,要求提取帧的时间戳。
答案1
您可以使用showinfo
为每一帧打印一行的过滤器:
[Parsed_showinfo_0 @ 0x7ff710000000] n: 1 pts: 1 pts_time:0.04 pos: -1 fmt:rgb24 sar:1/1 s:320x240 i:P iskey:1 type:I checksum:C4740AD1 plane_checksum:[C4740AD1] mean:[127] stdev:[125.7]
这里,pts_time
是帧的显示时间戳。例如,像这样运行它:
ffmpeg -hide_banner -f lavfi -i testsrc -filter:v showinfo -f null /dev/null