Using ffmpeg to extract every n frames from a given range of an m2ts video

In summary, the person needs to use the -ss and -t options in ffmpeg to extract every second from 54 min to 55 min of a 2 hour long video at 60 fps. The exact code to use is "ffmpeg -ss 3240 -t 60 -i myvideo.m2ts -r 1 output_%04d.png" as described in the online manual.
  • #1
member 428835
Hi PF!

I have a video titled myvideo.m2ts that is 2 hours long at 60 fps. I would like to extract every second from 54 min to 55 min via ffmpeg. It looks like I would execute something similar to this: ffmpeg -i myvideo.m2ts -r 1 output_%04d.png except this will run the entire video. Any help is greatly appreciated!
 
Computer science news on Phys.org
  • #2
Use the -ss option before the -i option like:
Code:
ffmpeg -ss 3240 -i myvideo.m2ts -r 1 output_%04d.png
as described in the online manual: https://ffmpeg.org/ffmpeg.html#toc-Main-options

Edit: oh, you only want 1 minute: use the -t option as well:
Code:
ffmpeg -ss 3240 -t 60 -i myvideo.m2ts -r 1 output_%04d.png
 
  • Like
Likes sysprog and member 428835
  • #3
Amazing, thanks so much!
 

1. How do I specify the range of frames to extract in an m2ts video using ffmpeg?

To specify the range of frames to extract, you can use the -ss and -t flags in ffmpeg. The -ss flag is used to specify the starting point of the range, while the -t flag is used to specify the duration of the range. For example, to extract frames 50 to 100, you would use the command ffmpeg -i input.m2ts -vf select='between(n\,50\,100)' output_%03d.jpg.

2. Can I extract frames at regular intervals using ffmpeg?

Yes, you can use the select filter with the -vf flag to extract frames at regular intervals. For example, to extract every 10th frame, you would use the command ffmpeg -i input.m2ts -vf select='not(mod(n\,10))' output_%03d.jpg.

3. How can I specify the output file format when extracting frames with ffmpeg?

You can specify the output file format by using the -f flag in ffmpeg. For example, to extract frames in JPEG format, you would use the command ffmpeg -i input.m2ts -vf select='not(mod(n\,10))' -f image2 output_%03d.jpg.

4. Is it possible to extract frames from multiple m2ts videos at once using ffmpeg?

Yes, you can use the -pattern_type and -i flags in ffmpeg to extract frames from multiple m2ts videos at once. The -pattern_type flag specifies the type of pattern to use for the input files, while the -i flag specifies the input files. For example, to extract frames from all m2ts videos in a folder, you would use the command ffmpeg -pattern_type glob -i '*.m2ts' -vf select='not(mod(n\,10))' output_%03d.jpg.

5. Can I extract frames with a specific aspect ratio using ffmpeg?

Yes, you can use the scale filter with the -vf flag to extract frames with a specific aspect ratio. For example, to extract frames with an aspect ratio of 16:9, you would use the command ffmpeg -i input.m2ts -vf scale=16:9 output_%03d.jpg.

Similar threads

  • Electrical Engineering
Replies
15
Views
2K
Replies
19
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • High Energy, Nuclear, Particle Physics
Replies
6
Views
1K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • Sci-Fi Writing and World Building
Replies
21
Views
1K
  • General Discussion
Replies
20
Views
3K
  • Mechanical Engineering
Replies
5
Views
969
Back
Top