I'm using this piece of code in python to split a video into frames.
def ffmpeg(self, video_file, fps, start_number, **trim_kwargs):
ffmpeg.input(video_file) \
.filter('fps', fps=fps) \
.trim(**trim_kwargs) \
.output(os.path.join(self._output_dir, f"%0{NAME_PADDING}d.JPG"),
**{'qscale:v': 1, 'vsync': 'drop', 'start_number': start_number}) \
.run()
I sometimes use also trimming options more or less like this:
ffmpeg(video_file, fps, 0, start=XXX,end=YYY)
Additionally, I have a list with timestamps (starting from point zero) with some additional metadata at certain points. I'm trying to figure out what are the mechanics of ffmpeg of using fps for dividing into frames (for example fps = 1), because when I try to jump through my timestamped log manually with the same "fps", I often get less entries than ffmpeg by 1. It's like ffmpeg always took first and last frame or something. Can someone explain to me how it's done exactly, so I could match metadata with generate frames in the best manner?
An MPEG file is always recorded at a specific frame rate(*), usually 24 or 30 or 60. Because an MPEG frame depends on the frames before and after it, the decoder always has to decode ALL the frames in the file. If you ask for fps=1
, it's just going to throw out the frames between the recorded frame rate and the frame rate you ask for.
(*) -- Technically, a single MPEG file can include multiple frame rates, but that's less commonly used.