Search code examples
phplaravelamazon-s3ffmpegffmpeg-php

FFMPEG: How to use S3 url in FFMPEG Php


I'm generating an image frame from a video in a particular time using FFMPEG Laravel SDK in Laravel 5.6. If I used the local path for video file it's working fine but When I'm using URL directly it's giving an error. I want to use the video which is stored in the s3 bucket.

File not found at path: https:/xxxxx.cloudfront.net/uploaded_videos/filename.mp4

My code as below.

$videoFile = env('CLOUDFRONT')."/".$resultStatusValue[0]->video_url;

FFMpegFacade::fromDisk('s3')
->open($videoFile)   
->getFrameFromSeconds($timeToSecond)
->export()
->toDisk('s3')
->save($s3Path);

Hereafter generated image should be upload to the s3 bucket.

Thanks in advance.


Solution

  • If specify the disk as s3 just simply key name is enough.

    $videoFile = $resultStatusValue[0]->video_url;  //= upload/video1.mp4
    
    FFMpegFacade::fromDisk('s3')
    ->open($videoFile)   
    ->getFrameFromSeconds($timeToSecond)
    ->export()
    ->toDisk('s3')
    ->save($s3Path);
    

    In Additional if you want uploaded file to public. specify visibility on config/filesystems.php

    's3' => [
                'driver' => 's3',
                'key' => 'your-key',
                'secret' => 'your-secret',
                'region' => 'your-region',
                'bucket' => 'your-bucket',
                'visibility' => 'public',
            ],