Answers.Body: <p>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.</p>
  
  <p>Anyway, here's the method:<br>
  <code>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</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-09T10:04:41.520Z
Answers.Text: 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]" `?
Answers.UserDisplayName: HB.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-09T11:45:33.303Z
Answers.Text: Assuming 13/6 is the required output DAR, replace 16/9 in my command with 13/6 and 9/16 with 6/13.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-09T12:18:31.807Z
Answers.Text: 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]`.
Answers.UserDisplayName: HB.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-09T12:18:39.033Z
Answers.Text: 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`?
Answers.UserDisplayName: HB.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-10T10:41:17.843Z
Answers.Text: I asked a new question, can you please have a look? https://video.stackexchange.com/questions/28036/ffmpeg-issue-with-aspect-ratio
Answers.UserDisplayName: HB.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-03T05:45:00.373Z
Answers.LastActivityDate: 2017-10-03T05:45:00.373Z
Answers.UserDisplayName: Gyan
Body: <p><code>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"</code></p>
  
  <p>using the above code I am able to successfully merge a.mov(1920x816) with b.mov(1920x816).  However, Youtube <code>end screens</code> require video to be <code>16:9 aspect ratio.</code> Thus I tried scale filter and setting SAR to <code>16:9</code>. however this leads to the output video stretching to fit the <code>16:9 ratio</code>. </p>
  
  <p>How can I output a video with <code>16:9</code> ratio with the actual video with resolution <code>1920x816</code>. Essentially The remaining vertical space should just be black without stretching the <code>816</code> height video to fit the <code>1080</code> height.  </p>
  
Tags: <ffmpeg><youtube><aspect>
Title: change aspect ratio without stretching video ffmpeg
UserDisplayName: jasan
ThreadText: # change aspect ratio without stretching video ffmpeg
  
  (Asked by: username_0 on 2017-10-02)
  
  `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.
  
  **Tags:** ffmpeg, youtube, aspect
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-03. Score: 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`
  
  > **Comments:**
  > **username_2**: 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]" `?  
  > **username_1**: Assuming 13/6 is the required output DAR, replace 16/9 in my command with 13/6 and 9/16 with 6/13.  
  > **username_2**: 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]`.  
  > **username_2**: 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`?  
  > **username_2**: I asked a new question, can you please have a look? https://video.stackexchange.com/questions/28036/ffmpeg-issue-with-aspect-ratio  
  
  ---
  
  