Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg split avi into frames with known frame rate

I posted this as comments under this related thread. However, they seem to have gone unnoticed =(

I've used

ffmpeg -i myfile.avi -f image2 image-%05d.bmp

to split myfile.avi into frames stored as .bmp files. It seemed to work except not quite. When recording my video, I recorded at a rate of 1000fps and the video turned out to be 2min29sec long. If my math is correct, that should amount to a total of 149,000 frames for the entire video. However, when I ran

ffmpeg -i myfile.avi -f image2 image-%05d.bmp

I only obtained 4472 files. How can I get the original 149k frames?

I also tried to convert the frame rate of my original AVI to 1000fps by doing

ffmpeg -i myfile.avi -r 1000 otherfile.avi

but this didn't seem to fix my concern.

like image 448
Myx Avatar asked Oct 12 '10 18:10

Myx


People also ask

How do I change fps in ffmpeg?

You can change the frame rate by adding the argument -vf fps or -filter:v fps with the number of frames to the basic command. It is a filter that will convert the video to the specified constant frame rate by duplicating or dropping frames as necessary.


2 Answers

ffmpeg -i myfile.avi -r 1000 -f image2 image-%07d.png 

I am not sure outputting 150k bmp files will be a good idea. Perhaps png is good enough?

like image 61
Dat Chu Avatar answered Sep 19 '22 08:09

Dat Chu


Part one of your math is good, the 2 minutes and 29 seconds is about 149 seconds. With 1000 fps that makes 149000 frames. However your output filename only has 5 positions for the number where 149000 has 6 positions, so try "image-%06d.bmp".

Then there is the disk size: Do your images fit on the disk? With bmp every image uses its own size. You might try to use jpeg pictures, they compress about 10 times better.

Another idea: If ffmpeg does not find a (reasonable) frame rate, it drops to 25 or 30 frames per second. You might need to specify it. Do so for both source and target, see the man page (man ffmpeg on unix):

   To force the frame rate of the input file (valid for raw formats
   only) to 1 fps and the frame rate of the output file to 24 fps:
           ffmpeg -r 1 -i input.m2v -r 24 output.avi

For what it's worth: I use ffmpeg -y -i "video.mpg" -sameq "video.%04d.jpg" to split my video to pictures. The -sameq is to force the jpeg in a reasonable quality, the -y is to avoid allow overwrite questions. For you:

ffmpeg -y -r 1000 -i "myfile.avi" -sameq "image.%06d.jpg"

like image 31
CBee Avatar answered Sep 23 '22 08:09

CBee