Anyone knows a command to use ffmpeg in order to generate 10 images from one video file?

This command for example would generate a jpg image for every frame, but idealy I would like 10 images taken from the video, from 1%, 10%, 20% etc to use them as a preview that covers all video.

ffmpeg -i sample.mp4 images/sample_%d.jpg

That would make sample_1.jpg, sample2_jpg ... sample_300.jpg, too many images.

If there isn't such command then it would also help me a SSH command that does this: Loop over images directory, get the total images (e.g 300) and then remove all but 10 of them, in this case it would be image 1.jpg, 30.jpg, 60.jpg .. 300.jpg.

Any ideas (commands)? Thank you.

link|improve this question
feedback

migrated from serverfault.com Jan 17 at 18:22

This question came from our site for system administrators and desktop support professionals.

3 Answers

Whether -vframes will evenly space out the number of frames or will just give you 10 of them across 10 seconds is ambiguous. If it's the latter, then you'll need to get the video time and pass in the command 10 times with the appropriate time offsets.

Should be a simple scripting task.

man ffmpeg

For extracting images from a video:

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg

This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.

If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time.


-vframes number Set the number of video frames to record.

link|improve this answer
feedback
ffmpeg -i 1.mov -y -an -sameq  -vframes 5 -f image2 -vcodec mjpeg %03d.jpg

Creates 5 frames from the video.

link|improve this answer
This will output the first 5 frames from the input. Clearly not what adrianTNT wanted. – LordNeckbeard Feb 18 at 0:11
feedback

I think the best solution is using -r.

For example, -r 0.04 takes every 20th of a second (1/20). A little calculation is necessary, so basically you take 1/(length/10).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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