Note that there are some explanatory texts on larger screens.

plurals
  1. POFFmpegPHP get thumbnail from external URL
    primarykey
    data
    text
    <p>I'm trying to create thumbnails from external videos, mostly MP4s and FLVs. I'm using <a href="https://github.com/char0n/ffmpeg-php" rel="nofollow">FFmpegPHP</a>. I already have the thumbnail generation working fine, however, I need to load the video entirely on my server first. Would it be possible to stream only a small part of the video then extract the thumbnail from that?</p> <p>Here's the code I have so far:</p> <pre><code>require_once PRIV . 'Vendor/FFmpegPHP/FFmpegAutoloader.php'; // Download the whole video. $video = file_get_contents($_PUT['video']); $file = 'path_to_cache'; file_put_contents($file, $video); $movie = new FFmpegMovie($file); // Generate the thumbnail. $thumb = $movie-&gt;getFrame($movie-&gt;getFrameCount() / 2); $thumb-&gt;resize(320, 240); imagejpeg($thumb-&gt;toGDImage(), 'path_to_thumb'); </code></pre> <p>Anyone has a suggestion?</p> <p><strong>EDIT</strong></p> <p>As Brad suggested, here is the updated code: </p> <pre><code>$file = CACHE . 'moodboard_video_' . rand(); $fh = fopen($file, 'w'); $size = 0; curl_setopt($ch, CURLOPT_URL, $_PUT['video']); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $data) use($fh, &amp;$size){ $length = fwrite($fh, $data); if($length === FALSE) { return 0; } else { $size += $length; } // Downloads 1MB. return $size &lt; 1024 * 1024 * XXXXXX ? $length : 0; }); curl_exec($ch); fclose($fh); curl_close($ch); // Create the thumbnail. $thumb = $movie-&gt;getFrame(XXXXXX); $thumb-&gt;resize(static::DEFAULT_THUMBNAIL_WIDTH, $thumb-&gt;getHeight() / $thumb-&gt;getWidth() * static::DEFAULT_THUMBNAIL_WIDTH); $image = $thumb-&gt;toGDImage(); imagejpeg($image, PRIV . static::THUMBNAILS_PATH . $item-&gt;getLastInsertIdentifier() . '_' . static::DEFAULT_THUMBNAIL_WIDTH); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload