ffmpeg -i "a.mov" -i "b.mp4" -filter_complex "[0:v]setsar=sar=${SAR}[a]; [1:v]setsar=sar=${SAR}[b]; [a][0:a] [b][1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -preset veryfast -crf 18 "merged.mp4"

using the above code I am able to successfully merge a.mov(1920x816) with b.mov(1920x816). However, Youtube end screens require video to be 16:9 aspect ratio. Thus I tried scale filter and setting SAR to 16:9. however this leads to the output video stretching to fit the 16:9 ratio.

How can I output a video with 16:9 ratio with the actual video with resolution 1920x816. Essentially The remaining vertical space should just be black without stretching the 816 height video to fit the 1080 height.

1 Answer 1


Have you tried uploading it to Youtube? Their player window will be a fixed 16:9 ratio (on YT.com), but they should accept source videos of any ratio, and simply center it in their window during playback.

Anyway, here's the method:
ffmpeg -i "a.mov" -i "b.mp4" -filter_complex "[0:v]scale=iw*sar:ih,pad=if(gt(dar,16/9),iw,2*trunc(ih*16/9/2)):if(gt(dar,16/9),2*trunc(iw*9/16/2),ih):(ow-iw)/2:(oh-ih)/2,setsar=1[a]; [1:v]scale=iw*sar:ih,pad=if(gt(dar,16/9),iw,2*trunc(ih*16/9/2)):if(gt(dar,16/9),2*trunc(iw*9/16/2),ih):(ow-iw)/2:(oh-ih)/2,setsar=1[b]; [a][0:a] [b][1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -preset veryfast -crf 18 "merged.mp4

  • Same question as the other comment, what if the aspect ratio is, for example 13 : 6. Will it work if I change the command to - "-filter_complex", "[0:v]pad=iw:if(lte(ih\\,iw)\\,ih\\,2*trunc(iw*13/6/2)):(ow-iw)/2:(oh-ih)/2[v0];[1:v][v0]scale2ref[v1][v0];[v0][v1]overlay=x=(W-w)/2:y=(H-h)/2[v]" ?
    – HB.
    Jul 9, 2019 at 10:04
  • Assuming 13/6 is the required output DAR, replace 16/9 in my command with 13/6 and 9/16 with 6/13.
    – Gyan
    Jul 9, 2019 at 11:45
  • This is the filter I used for a video that has 16/9 aspect ratio [0:v]pad=iw:if(lte(ih\\,iw)\\,ih\\,2trunc(iw*16/9/2)):(ow-iw)/2:(oh-ih)/2[v0];[1:v][v0]scale2ref[v1][v0];[v0][v1]overlay=x=(W-w)/2:y=(H-h)/2[v] Am I correct in changing the filter to the following if the aspect ratio is 13/6 [0:v]pad=iw:if(lte(ih\\,iw)\\,ih\\,2*trunc(iw*13/6/2)):(ow-iw)/2:(oh-ih)/2[v0];[1:v][v0]scale2ref[v1][v0];[v0][v1]overlay=x=(W-w)/2:y=(H-h)/2[v].
    – HB.
    Jul 9, 2019 at 12:18
  • The first filter mentioned above works perfectly for video's that has an aspect ratio of 16/9 (without using DAR), that is why I was wondering if I could just change the trunc value to iw*13/6/2 instead of iw*16/9/2?
    – HB.
    Jul 9, 2019 at 12:18
  • I asked a new question, can you please have a look? video.stackexchange.com/questions/28036/…
    – HB.
    Jul 10, 2019 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.