PHP code example of mikeambait / ffmpeglaravel

1. Go to this page and download the library: Download mikeambait/ffmpeglaravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mikeambait / ffmpeglaravel example snippets


'FFMpegLaravel' => FFMpegLaravel\FFMpegLaravel\FFmpegLaravel::class


use FFMpegLaravel;

$FFMpegLaravelInstance = FFMpegLaravel::open(public_path() . '/egg.mp4');

$FFMpegLaravelInstance->save(public_path() . '/NewEgg.mp4', [
    'bitrate' => 500,
    'audio' => 256
]);



$mp3 = FFMpegLaravel::open(public_path() . '/egg.mp4');

$mp3->save(public_path() . '/egg.mp3');


// params> width: integer( value in resize() to force the use of the nearest aspect ratio standard.
$resizedVideo = FFMpegLaravel::open(public_path() . '/egg.mp4')
            ->resize(640, 480)
            ->save(public_path() . '/resized_egg.mp4', [
                        'bitrate' => 500,
                        'audio' => 256
                    ]);

$mutedVideo = FFMpegLaravel::open(public_path() . '/egg.mp4')
            ->mute()
            ->save(__DIR__ . '/output/muted_egg.mp4');


// getThumbnail() , generates thumbnail at 10 secs mark, when no params passed
FFMpegLaravel::open('videos.mp4')
      ->getThumbnail(public_path() . '/filename.jpg');

// returns a integer of duration in seconds
$duration = FFMpegLaravel::open(public_path() . '/egg.mp4')
      ->getDuration();

echo $duration;

// parameters: new filepath.gif | duration of GIF file : int(nullable) | from seconds: int(nullable)
$gif = FFMpegLaravel::open(public_path() . '/egg.mp4')
            ->generateGif(public_path() . '/sample.gif', 2 );

return $gif;

// returns an array of resolution of the video: 'width' & 'height'
$resolution = FFMpegLaravel::open(public_path() . '/egg.mp4')
      ->getResolution();

echo $resolution['width'] .' x '.$resolution['height'];

// returns a string of codec used by the video
$codec = FFMpegLaravel::open(public_path() . '/egg.mp4')
      ->getCodec();

echo $codec;