Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ffmpeg change height with fixed width

I'm trying to change video dimensions using ffmpeg. For example, user is uploading video 1280*960.

And i need to get video 640*480 in return.

I tried this code and it works

exec($ffmpegPath." -i ".$srcFile." -ar 22050 -ab 32 -f flv -s 640x480".$destFile,$tmp);

but this method d't keep width/height balance of video (i.e. video 5000*480 becomes 640*480 and looks compressed from left and right).

In case of this dimensions (5000*480) i need to get video on exit like 640*61 i mean fixed height is not suitable for me.

I look over the internet and found this topics https://superuser.com/questions/201051/resize-videos-with-different-widths-to-a-fixed-height-preserving-aspect-ratio-wi http://delogics.blogspot.com/2011/11/ffmpeg-maintain-aspect-ratio-with-fixed.html

but neither of them works for me (ffmpeg even not works with this code, maybe i've made mistake when adding theirs code parts in my ffmpeg string)

Help me to improve my code pls

Thanks

like image 898
Dmitry Avatar asked Jun 13 '26 15:06

Dmitry


1 Answers

If the ffmpeg supports video filters then you can use scale filter and resize the video to 640 pixel width and proportionally changed height as the following:

exec($ffmpegPath." -i ".$srcFile." -ar 22050 -ab 32 -f flv -vf scale=640:ih*640/iw ".$destFile,$tmp);

like image 90
Dmitry Shkuropatsky Avatar answered Jun 16 '26 07:06

Dmitry Shkuropatsky



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!