I need to upload video in 3 formate/resolution as 360p, 480p, 720p.
After some research i got to know that some paid service are there like Amazone Elastic Transcoder . But i want to do with open source so i found FFMPEG.
Also i want to upload video on Amazon s3 after transcode and video are in big size like video may contain 1GB size.
I got php library for FFMPEG Library Link
I have installed ffmpeg and it successfully generate new video. But i cannot figure out that how can i generate different formate/resolution as 360p, 480p, 720p.
My sample Code is
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        require 'vendor/autoload.php';
        //$ffmpeg = FFMpeg\FFMpeg::create();
        $video = $ffmpeg->open('assets/small.mp4');
        $video
            ->filters()
            ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
            ->synchronize();
        $video
            ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(2))
            ->save('assets/frame.jpg');
        $format = new FFMpeg\Format\Video\X264();
        $format->setAudioCodec("libmp3lame");
        $video->save($format, 'assets/new.mp4');
Can anyone suggest me any way that how can i achieve this ??
Am pretty sure you figured this out already but am putting this here for future reference.
// Create the formats in Kilo Bitrates
$_360p = (new FFMpeg\Format\Video\X264('libmp3lame'))->setKiloBitrate(500);
$_480p = (new FFMpeg\Format\Video\X264('libmp3lame'))->setKiloBitrate(750);
$_720p = (new FFMpeg\Format\Video\X264('libmp3lame'))->setKiloBitrate(1500);
// Open the video file
$video = $ffmpeg->open('assets/small.mp4')
                // Add all formats
                ->addFormat($_360p)
                ->addFormat($_480p)
                ->addFormat($_720p)
                // call the 'save' method with a filename...
                ->save('assets/new.mp4');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With