4

I am using this command to extract a series of images from a video to express them as a visual time-frame of the video.

ffmpeg -i inputfile.mp4 -r 1 -t 12 image-%d.jpeg

Most of my videos are in mp4 format. I am able to extract the images successfully but the time taken for extraction is too long.

Is there any way I could reduce the time for image extraction ?

EDIT: It is taking me 60 secs to get 8 thumbnails from a 15 sec long video encoded in MP4 format, I am doing this operation on my Galaxy Nexus(Android Phone) is there any way to improve the speed of operation, ideally I want it be less than ~10secs.

Arif Nadeem
  • 8,524
  • 7
  • 47
  • 78

2 Answers2

4

Hm, define "slow" :) I just did this and it took four seconds on a standard machine. There might be ways to speed that up, but ffmpeg has to decode the MP4 packet structure (GOP), extract the frame and store the JPG image - four seconds looks reasonable to me. I just see little room for improvement in your command-line:

ffmpeg -i inputfile.mp4 -r 1 -an -t 12 -s 512x288 -vsync 1 -threads 4 image-%d.jpeg

Play around with the threads and -s parameter (this one defines the target image size - it will not speed up the process, but if you don't want to keep the source image size it will save you an additional step).

Also, make sure that you have an ffmpeg build that matches your platform - there are great differences in speed there. Unfortunately, I can't give you a general advice here. For your scenario it may be an idea to compile the ffmpeg sources yourself.

Community
  • 1
  • 1
Jan Petzold
  • 1,561
  • 1
  • 15
  • 24
  • in my case it took 22 secs to extract images from a 14 sec clip and 67 secs on average for 30 secs clip. I am targetting mobiles, so is there a chance that things will speed up in a mobile device with decent processing power. – Arif Nadeem Aug 24 '12 at 05:54
  • See my modified answer. But if you really want to perform this operation on a Galaxy Nexus I doubt that it is possible < 10 sec. Is it possible to scale down the video before you do the image extraction? This would help. – Jan Petzold Aug 27 '12 at 09:06
  • do you mean its better to re-encode the video in some other format before getting frames from it, and is re-encoding fast enough? The reason I am asking this is that I've found that getting frames from mp4 videos takes longer but for 3gp and flv its lightening fast. – Arif Nadeem Aug 27 '12 at 09:25
  • I didn't exactly mean that, but if you notice differences between source formats thats something siginificant. But you'll also save time the smaller (meaning resolution) your source video is. Also, a video with a codec like Motion-JPEG will perform faster, because there is no frame structure (GOP) to decode. So, if it's possible in your scenario I'd recommend to re-encode the source video to Motion-JPEG with smaller resolution. – Jan Petzold Aug 27 '12 at 10:37
1

Here https://stackoverflow.com/a/18539500/2563051 is drama for this :))

The -ss parameter needs to be specified before -i:

ffmpeg -ss 00:03:00 -i Underworld.Awakening.avi -frames:v 1 out1.jpg

This example will produce one image frame (out1.jpg) somewhere around the third minute from the beginning of the movie. The input will be parsed using keyframes, which is very fast. The drawback is that it will also finish the seeking at some keyframe, not necessarily located at specified time (00:03:00), so the seeking will not be as accurate as expected.

KunMyt
  • 32
  • 5