Using ffmpeg with the SS option to Extract Frames
The ffmpeg tool is a powerful, open-source multimedia processing program that can be used for a wide variety of tasks, including extracting frames from a video. One useful option for extracting frames is the "select" filter, which allows you to choose specific frames based on a variety of criteria. In this article, we will focus on using the "select" filter to extract frames at a regular interval using the SS option.
The SS Option
The SS option allows you to specify the start time for the filter in seconds. When used in combination with the "select" filter, you can extract frames at a regular interval by specifying the start time and then using the modulo operator to select every nth frame. For example, to extract every 10th frame starting at frame 0, you would use the following command:
ffmpeg -i input.ts -vf "select=not(mod(n\,10)),setpts=PTS-STARTPTS" -vsync vfr -frame\_pts true -r 1000 -vframes 40 output\_%04d<sup>d</sup>.pngIn this command, the "select" filter is used to select every 10th frame by using the modulo operator (n mod 10). The setpts filter is used to set the presentation timestamp for each frame, and the -frame\_pts true option is used to enable accurate timestamps for each frame. The -r 1000 option sets the output framerate to 1000 fps, and the -vframes 40 option specifies that 40 frames should be extracted.
Expanding the SS Option
If you want to extract frames starting at a specific time, you can use the SS option to specify the start time. For example, to extract every 10th frame starting at 674 seconds, you would use the following command:
ffmpeg -i input.ts -vf "select=not(mod(n\,10)),setpts=PTS+674/TB" -vsync vfr -frame\_pts true -r 1000 -vframes 40 output\_%04d<sup>d</sup>.pngIn this command, the SS option is used to specify the start time (674 seconds), and the TB option is used to set the time base to 1/1 (1 second). The "select" filter is then used to select every 10th frame starting at the specified time.
The ffmpeg tool is a powerful and versatile multimedia processing program that can be used for a wide variety of tasks, including extracting frames from a video. By using the SS option in combination with the "select" filter, you can extract frames at a regular interval, starting at a specific time. This can be useful for a variety of applications, such as creating time-lapse videos or analyzing specific frames in a video.
References
- ffmpeg documentation: https://ffmpeg.org/documentation.html
- ffmpeg filtering guide: https://ffmpeg.org/ffmpeg-filters.html
--