3

I have a MP4 movie filmed with a GoPRO.

The GoPRO split the movie in several files (I believe because of FAT32 size limitation).

What I'm trying to do is extract some specific frames of the FULL MOVIE. I don't need all frames, but I need a list of frames

Because all files is from same movie, I "merged" all files. To do this, I created a file called gopro.txt with the following content:

file 'GOPR0940.MP4'
file 'GP010940.MP4'
file 'GP020940.MP4'
file 'GP030940.MP4'
file 'GP040940.MP4'
file 'GP050940.MP4'

So, to extract a image from a movie, I used this command:

ffmpeg -ss 00:19:00 -f concat -i gopro.txt -qscale:v 2 -vframes 1 frame%d.jpg (where 00:19:00 is the time I want).

Edit: as @Mulvya said, on a demuxed input, the "fast seek" don't work (works, but is very slow). So, I merged all videos on a single file with the following command:

ffmpeg -f concat -safe 0 -i gopro.txt -c copy full_movie.mp4


Now, suppose I have a list of times I want to extract (I don't have the frame number, only the time), like:

  • 00:05:32
  • 00:12:49
  • 00:21:10
  • 00:32:23

and so on. My list will have more than 10.000 timestamps, so, if I make a batch file with:

ffmpeg -f concat -i gopro.txt -ss 00:05:32 -vframes 1 frame00001.jpg
ffmpeg -f concat -i gopro.txt -ss 00:12:49 -vframes 1 frame00002.jpg
ffmpeg -f concat -i gopro.txt -ss 00:21:10 -vframes 1 frame00003.jpg
...
ffmpeg -f concat -i gopro.txt -ss 01:38:42 -vframes 1 frame10000.jpg

This will work, but take a really long time, because I think that ffmpeg, at each line of my batch file, will seek from beggining of the file until at desired time.

Edit: after changes proposed by @Mulvya, the extract worked very fast, and I can use the batch file without any problem.

It's possible to pass a list of timestamps to ffmpeg?

I tried with select option, like:

ffmpeg -f concat -i gopro.txt -vf select='eq(t,332)+eq(t,769)+eq(t,1270)+eq(t,1943)' -vsync 0 -vframes 4 frames%d.jpg, (https://ffmpeg.org/ffmpeg-filters.html#Timeline-editing) but got no results.

After several minutes, ffmpeg return a warning message with the following content:

Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

And I thinking that solution it's not the best, because, if I have 10000 timestamps, this will generate a huge command.

PS: I'm using Windows

2
  • 1
    ffmpeg -f concat -i gopro.txt -ss 00:05:32 -vframes 1 frame00001.jpg --< this will take a long time, as this is a slow seek. ffmpeg -f concat -ss 00:05:32 -i gopro.txt -vframes 1 frame00001.jpg should not. Although since you are performing this on a concat demuxed input, it may amount to the same thing. But if you write the the concat to one MP4 and then set a seek time before the input, it's a fast seek and output will be quick. In a fast seek on a container like MP4, ffmpeg queries the index and jumps to the byte offset of the GOP start containing the sample.
    – Gyan
    Mar 22, 2017 at 15:08
  • @Mulvya, tested again! Yes, you're corrected. On a demuxed input, the results are the same. On a "merged" mp4, the second way is much faster. Mar 22, 2017 at 16:10

1 Answer 1

1

After @Mulvya reply, I made the following changes:

First, I must put all in a single file. According with the Mulvya answer, a "concat demuxed input" don't have a "fast seek", so, first I created a gopro.txt file with the following content:

file 'GOPR0940.MP4'
file 'GP010940.MP4'
file 'GP020940.MP4'
file 'GP030940.MP4'
file 'GP040940.MP4'
file 'GP050940.MP4'

Then, "merged" all MP4 files in a single file, with the following command:

ffmpeg -f concat -i gopro.txt -c copy full_movie.mp4

Source: https://trac.ffmpeg.org/wiki/Concatenate

Now, I can extract in a fast way individual frames, with the following command:

ffmpeg -ss 00:15:00 -i full_movie.mp4 -vframes 1 frame00001.jpg.

Source: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video (i put the -ss option first, like @Mulvya said).

Initially, I want to pass a list of timestamps to ffmpeg, but now, the extract of individual frames is very fast, that I don't need anymore. A simple batch file worked good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.