laravel-ffmpeg
laravel-ffmpeg copied to clipboard
I need help to post an instagram story
i need to apply this in php
ffmpeg -i input.mp4 \
-c:v libx264 -aspect 16:9 -crf 18 \
-vf "scale=iw*min(1280/iw\,720/ih):ih*min(1280/iw\,720/ih),pad=1280:720:(1280-iw)/2:(720-ih)/2" \
-fpsmax 60 -preset ultrafast -c:a aac -b:a 128k -ac 1 -pix_fmt yuv420p -movflags +faststart -t 59 -y output.mp4```
that is my code to make the video for upload
$video = $request->file('video');
// Step 1: Upload the original video to Amazon S3
$originalVideoPath = Storage::disk('s3')->putFile('videos', $video, 'public');
// Step 2: Generate a URL for the uploaded video
$originalVideoUrl = Storage::disk('s3')->url($originalVideoPath);
// Step 3: Transcode the video with FFmpeg
$ffmpeg = FFMpeg::fromDisk('s3');
/* -fpsmax 60 -preset ultrafast -c:a aac -b:a 128k -ac 1 -pix_fmt yuv420p -movflags +faststart -t 59 -y */
$format = (new \FFMpeg\Format\Video\X264())->setAdditionalParameters(['-pix_fmt', 'yuv420p']);
$randomStr = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
$ffmpeg->open($originalVideoPath)
->export()
/* \ */
->addFilter(function (VideoFilters $filters) {
$filters->custom('scale=iw*min(1280/iw\,720/ih):ih*min(1280/iw\,720/ih)')->resize(new Dimension(1024, 490), $mode = \FFMpeg\Filters\Video\ResizeFilter::RESIZEMODE_INSET, true)
->crop(new \FFMpeg\Coordinate\Point(0, 0), new \FFMpeg\Coordinate\Dimension(1024, 490));
})
->addFilter(function (VideoFilters $filters) {
$filters->custom('pad=1280:720:(1280-iw)/2:(720-ih)/2');
})
->addFilter('-fpsmax', '60', '-preset', 'ultrafast', '-c:a', 'aac', '-b:a', '128k', '-ac', '1', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', '-t', '59', '-y')
->toDisk('s3')
->inFormat($format)
->save('transcoded/' . pathinfo($originalVideoPath, PATHINFO_FILENAME) . $randomStr . '.mp4');
// Step 4: Generate the URL for the transcoded video
$transcodedVideoPath = 'transcoded/' . pathinfo($originalVideoPath, PATHINFO_FILENAME) . $randomStr . '.mp4';
// Make the transcoded video public
Storage::disk('s3')->setVisibility($transcodedVideoPath, 'public');
$transcodedVideoUrl = Storage::disk('s3')->url($transcodedVideoPath);
return $transcodedVideoUrl;
what am i doing wrong ?