The fastest way to extract a specific frame from a video (PHP / ffmpeg / anything)

I have a web page that (among other things) should extract a specific frame from a user uploaded video. The user searches for a specific part of .mp4 in the player, then presses the button, and the ajax call is launched on a php script that takes .mp4 and the exact time from the video, and uses this to extract the โ€œsketchโ€ frame.

My current solution uses the php exec command:

exec("ffmpeg -i $videoPath -ss $timeOffset -vframes 1 $jpgOutputPath");

... which works just fine, except that it is as slow as molasses. I assume that ffmpeg is too much to work with, and I could do better using basic libraries or something like that ... however, I have no idea how to do this.

Ideally, I do not want to install anything that requires a real "installation process" ... i.e. deleting the executable in the folder with my web application is fine, but I would not have to actually run the installer. In addition, the solution should be able to run on Mac, Linux, and Windows (although Linux is a top priority).

What can I do to speed up this process?

Thank.

+44
php ffmpeg video mp4 video-processing
Aug 30 '13 at 14:02
source share
1 answer

Of course, you can encode some C / C ++ and a link to -lav *, basically by creating a simplified version of ffmpeg just for extracting frames and maybe even do it as a php extension (also I would not run it as the same user, not to mention the same process). But the result is unlikely to be faster, because you will avoid some overhead and overhead, but your probable problem is actually a decryption, which will still be the same.

Instead, you should first study using ffmpeg in quick search mode (or fast / fine hybrid mode). Their wiki claims a quick search:

The -ss parameter must be specified before -i :

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

In this example, a single image frame (out1.jpg) will be created somewhere around the third minute from the start of the movie. Input will be analyzed using key frames, which is very fast. The disadvantage is that it will also complete the search on some keyframe, not necessarily at the indicated time (00:03:00), so the search will not be as accurate as expected.

A quick search is less accurate, but a hell of a lot faster, since ffmpeg doesn't really need to decode (most of) a movie during a search, while a fast / accurate hybrid mode is a good compromise. Read the wiki page for all available options.

Edit 06/14/10:

As with FFmpeg 2.1, when transcoding with ffmpeg (i.e. not streaming copy), -ss is now accurate even when used as an input option. You can restore previous behavior using the -noaccurate_seek option. (source)

Thus, with 2.1+, a โ€œhybridโ€ search is no longer required to get accurate results when it comes to re-encoding (and saving to .jpeg is a recoding). It is enough to do a regular quick search ( -ss ... -i ... ) instead of a slow search ( -i ... -ss ... ).

+67
Aug 30 '13 at 18:39
source share



All Articles