【问题标题】:How to save frame numbers with ffmpeg?如何使用 ffmpeg 保存帧号?
【发布时间】:2018-12-28 22:12:08
【问题描述】:

我正在使用 ffmpeg 扫描视频文件以查找场景变化并将结果保存到文本文件中。我在下面使用的代码有效,但我想简化结果,只输出发生场景变化的帧数,而不是该代码产生的所有数据。有什么建议吗?

ffprobe -show_frames -of compact=p=0 -f lavfi "movie=input.mov,select=gt(scene\,.02)" > results.txt

输出所有这些:

media_type=video    stream_index=0  key_frame=1 pkt_pts=31031   pkt_pts_time=1.292958   pkt_dts=31031   pkt_dts_time=1.292958   best_effort_timestamp=31031 best_effort_timestamp_time=1.292958 pkt_duration=N/A    pkt_duration_time=N/A   pkt_pos=82320   pkt_size=629760 width=640   height=328  pix_fmt=rgb24   sample_aspect_ratio=1:1 pict_type=I coded_picture_number=0  display_picture_number=0    interlaced_frame=0  top_field_first=0   repeat_pict=0   tag:lavfi.scene_score=0.025551  

【问题讨论】:

标签: ffmpeg


【解决方案1】:

要仅获取满足场景更改标准的帧索引号,请使用

 ffprobe -select_streams v -show_entries frame=pkt_pts -of compact=p=0:nk=1 \
         -f lavfi "movie=abc.mov,setpts=N+1,select=gt(scene\,.02)" > log.txt

日志文件将只包含帧索引号,例如每行一个

135
136
137
141
143
145 

setpts 从 1 开始编号。

【讨论】:

  • 谢谢。知道为什么它会提供更多我期待的场景吗?我上面的原始代码检测到 6 个场景。你给我一个 297 帧的列表。 ?
  • 检查场景变化值 - .020.2
  • 它按照您的原始代码工作。太好了,谢谢。
【解决方案2】:

您可以简单地使用命令:

ffmpeg inputvideo.mp4 -filter_complex "select='gt(scene,0.3)',metadata=print:file=time.txt" -vsync vfr img%03d.png

这将仅将相关信息保存在 time.txt 文件中,如下所示:

frame:0    pts:108859  pts_time:1.20954
lavfi.scene_score=0.436456
frame:1    pts:285285  pts_time:3.16983
lavfi.scene_score=0.444537
frame:2    pts:487987  pts_time:5.42208
lavfi.scene_score=0.494256
frame:3    pts:904654  pts_time:10.0517
lavfi.scene_score=0.462327
frame:4    pts:2533781 pts_time:28.1531
lavfi.scene_score=0.460413
frame:5    pts:2668916 pts_time:29.6546
lavfi.scene_score=0.432326

另外,为您的用例选择适当的阈值(此处为 0.3)以获得正确的输出

【讨论】:

  • 考虑将问题标记为重复问题,而不是复制和粘贴多个问题的相同答案。
猜你喜欢
  • 2023-03-07
  • 2021-09-12
  • 2016-06-26
  • 2012-11-09
  • 2016-10-10
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 2011-10-12
相关资源
最近更新 更多