Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP FFmpeg video aspect ratio problem

i compiled the new version of FFMPEG and the padding commands have been deprecated.
As i try to get familiar with the new -vf pad= commands, i want to ask, how can i
convert a video without changing it's aspect ratio.

I've checked numerous solutions from stackoverflow, nothing seemed to work.
Can someone, please post a working PHP example or cmd line. I would be VERY happy.

Please note that the videos in question, could be 4:3 and also be 16:9

Let's say, i convert a 16:9 video to 640x480 format. It will need some bars at
the top and at the bottom. That is what i want to do.

Thanks

like image 852
Herr Avatar asked Jan 01 '26 07:01

Herr


1 Answers

thanks for sharing this code.

i had to do a variation:

//keep always the same video size 
//we need to add padding and then crop the same size to keep vieos with same WxH sizes    
$command = FLV_LITE_FFMPEG_PATH . ' -i ' . $original_video;
$command .= ' -s '.FLV_LITE_VIDEO_WIDTH . 'x' .FLV_LITE_VIDEO_HEIGHT;
$command .= ' -croptop ' . $pad_top;
$command .= ' -cropbottom ' . $pad_bottom;
$command .= ' -cropleft ' . $pad_left;
$command .= ' -cropright ' . $pad_right;
$command .= ' -padtop ' . $pad_top;
$command .= ' -padbottom ' . $pad_bottom;
$command .= ' -padleft ' . $pad_left;
$command .= ' -padright ' . $pad_right;
$command .= ' -padcolor 0x000000';
$command .= ' -ab 32 -f flv -ar 22050 -b 256 -r 24 -y';   
$command .= ' ' . $converted_video; 

exec($command, $output, $status);
like image 63
Carvalhar Avatar answered Jan 03 '26 21:01

Carvalhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!