Search code examples
ffmpegdetectframesscene

FFMPEG: output scene change times in frames


I'm successfully using the -vf select='gte(scene,0.4)',metadata=print:file=shotcuts.txt command to get FFMPEG to detect scene changes and output the results to file. Is it possible to force the pts field to be in frames rather than the default, which seems to vary depending on the video format (e.g. frames for AVI files, nanosecs for MOV/MP4)?

Processing an AVI file, for example, outputs time stamps in frames:

frame 0 pts 151
frame 1 pts 206

Whereas an MP4 file outputs as media time:

frame 0 pts 540000
frame 1 pts 738000


Solution

  • PTS stands for Presentation Timestamps and so cannot be in frames. However, PTS are denominated in terms of a timebase, and so if the timebase is set to 1/fps, then the PTS and frame index will coincide. This will work well only for streams which are constant frame rate and have an integer framerate.

    Set the timebase by using the settb filter before select. For a 30 fps CFR stream,

    -vf settb=1/30,select='gte(scene,0.4)',metadata=print:file=shotcuts.txt