How to change mp4 aspect ratio to 16:9 using ffmpeg?

10,295

Assuming the video looks acceptable after stretching, you can use the following command:

ffmpeg -ss 25:55 -t 4:02 -i input.mp4 -vf scale=ih*16/9:ih,scale=iw:-2,setsar=1 -crf 20 -c:a copy YT.mp4
Share:
10,295
user1788736
Author by

user1788736

Updated on June 04, 2022

Comments

  • user1788736
    user1788736 about 2 years

    I got an mp4 video that I copy 4 minute of it using ffmpeg. After uploading to YouTube I noticed the uploaded video has black bars on both side of video(right and left side)!After searching for a way to remove those black bars I found that I need to use yt:stretch=16:9!However,using yt:stretch=16.9 tag will not remove the black bars on iPhone and Samsung smart tv YouTube app!

    could an expert help me change the aspect ratio of original mp4 video to 16:9 using ffmpeg (without losing video quality) for re uploading to YouTube? Thanks in advance ?

    I got two types of source with following information:

    1)Resolution:720x576 ,Frame rate:25 . Codec:H264 - MPEG-4 AVC(part 10)(avc1),
    2)Resolution:848x480 , Frame rate:24.804393,Codec:H264 - MPEG-4 AVC(part 10)(avc1)
    

    ffmpeg code used to trim the original video:

       ffmpeg -i orginalVideo.mp4 -ss 00:25:55 -t 00:04:02 -acodec copy -vcodec copy videoForYoutube.mp4
    
  • user1788736
    user1788736 about 8 years
    I get these errors on ffmpeg window:[libx264 @ 04e67020] width not divisible by 2 (853x480) Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height How to fix them ?
  • SuperMar1o
    SuperMar1o over 2 years
    'ffmpeg -i input.mp4 -vf scale=854x480,setdar=16/9 output.mp4' worked for me without any errors. Make sure the dimensions you are using are divisible by the scale. Eg 16:9. '854x480' vs '853x480'