Grab frame without downloading whole file?

351 views Asked by At

Is this possible using php + ffmpeg?

ffmpeg-php has the ability to:

Ability to grab frames from movie files and return them as images that can be manipulated using PHP's built-in image functions. This is great for automatically creating thumbnails for movie files.

I just don't want to download the whole file before doing so. So lets say i want to grab a frame @ 10% of the movie:

First lets get the size of remote file:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_URL, $url); //specify the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$head = curl_exec($ch);

$size = curl_getinfo($ch,CURLINFO_CONTENT_LENGTH_DOWNLOAD);

Then it's quite easy to download only 10% of the .flv or .mov file using curl.

But the framegrab trick using ffmpeg-php probably won't work because the file probably is corrupted?

Any other ideas?

1

There are 1 answers

0
BrianC On BEST ANSWER

Yes I believe this will work. For video files as long as you do have the start of the file, processing like this should be possible. (If you only had, for example, a chunk of the file from the middle, it probably wouldn't work.)

On the command line I downloaded the first part of an .FLV file with Curl, then grabbed frames using ffmpeg and it worked correctly. Doing the same in PHP should work as well.