0

I'm trying to generate thumbnails from video uploads and upload them directly to S3 without re-opening the file after it's uploaded.

I'm not sure how to really do this since php-ffmpeg documentation isn't good. Here's the code I'm trying but not sure what's wrong. I'm trying to upload using $disk->put since I'm not sure how to implement S3 into this.

$thumbnailPath = 'bucket.s3.eu-west-1.amazonaws.com/thumbnails/' . $id . '.' . $fileExtension;

$ffmpeg = FFMpeg::create();
$video = $ffmpeg->open($file);
$frame = $video->frame(TimeCode::fromSeconds(5));
$img = $frame->save($thumbnailPath);
$disk->put($thumbnailPath, fopen($img, 'r+'));

I wrote the above code based off of how I'm generating thumbnails for normal images (which works perfectly):

$img = Image::make($file)->resize(150, null, function ($constraint) {
    $constraint->aspectRatio();
});
$disk->put($thumbnailPath, $img->stream());
kryz
  • 79
  • 11
  • 1
    You can't do `$frame->save()` to `bucket.s3.eu-west-1.amazonaws.com` like that; it won't know what to do with it. `$disk->put()` uses a S3 driver behind the scenes. Save the ffmpeg thumb to a temporary file, and use `$disk->put()` to send it to S3. Remove the temporary file when done. – ceejayoz Sep 20 '22 at 00:48

0 Answers0