skip to Main Content

I have a functionality to upload videos in laravel.
Now I have to crop the uploaded video first 20 seconds and need to save the cropped video into different directory.

I went through this package.

https://github.com/protonemedia/laravel-ffmpeg

I have installed the package. But not getting the code for crop. Can any one help?

2

Answers


  1. Chosen as BEST ANSWER

    I have got another solution. I have run this command:

    $video_path = storage_path('app/public/uploads/vide_Upload2_image/' . $single_video_details->uploaded_video);
    $croppedVideoPath = storage_path('app/public/uploads/vide_Upload2_image/cropped_video.mp4');
       
    $ffmpegCommand = "C:/FFmpeg/bin/ffmpeg -i " . $video_path . " -ss 00:00:00 -t 00:00:10 " . $croppedVideoPath;
    $test = exec($ffmpegCommand);
    

    And it works.

    I have removed the package.


  2. use FFMpeg;
    
    // ...
    
    public function handleVideoUpload(Request $request)
    {
        $video = $request->file('video');
    
        // Generate a unique filename for the cropped video
        $croppedVideoPath = 'path/to/save/cropped/' . uniqid('cropped_video_') . '.mp4';
    
        // Crop the first 20 seconds of the video
        FFMpeg::open($video)
            ->crop(new FFMpegCoordinateTimeCode(0), new FFMpegCoordinateTimeCode(20))
            ->export()
            ->toDisk('public') // You can change the disk as needed
            ->inFormat(new FFMpegFormatVideoX264)
            ->save($croppedVideoPath);
    
        // Now you can save the $croppedVideoPath to your database or perform any other actions
    
        // ...
    }
    

    Ensure that you have configured your filesystem disk properly in the config/filesystems.php file. You might want to use the public disk for storing the cropped videos.

    'disks' => [
        // ...
    
        'public' => [
            'driver' => 'local',
            'root' => public_path(),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
    
        // ...
    ]
    

    ,

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search