Answers.Body: <p>You need to use a canvas which can accommodate all inputs. To adapt this canvas during runtime, we can use the scale2ref filter.</p>
  
  <p><code>ffmpeg -i video1 -i video2 -f lavfi -i color -filter_complex "[2][0]scale2ref[canvas][vid1];[canvas][1]scale2ref='max(iw,main_w)':'max(ih,main_h)'[canvas][vid2];[canvas]split=2[canvas1][canvas2];[canvas1][vid1]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid1];[canvas2][vid2]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid2];[vid1][vid2]concat=n=2:v=1:a=0,setsar=1" out.mp4</code></p>
  
  <p>Audio is ignored.</p>
  
  <hr>
  
  <p>To fit within a fixed size, use</p>
  
  <p><code>ffmpeg -i video1 -i video2 -f lavfi -i color=s=854x480:r=30 -filter_complex "[0]scale=854x480:force_original_aspect_ratio=decrease[vid1];[1]scale=854x480:force_original_aspect_ratio=decrease[vid2];[2][vid1]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid1];[2][vid2]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid2];[vid1][vid2]concat=n=2:v=1:a=0,setsar=1" out.mp4</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T09:11:31.910Z
Answers.Text: thanks for the answer, but after i implement your answer i got error which is i added inside question, please check it
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T09:35:21.910Z
Answers.Text: Don't see any error in your logs.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T09:43:29.293Z
Answers.Text: it was gone in failure not completed in my android device
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T09:51:07.067Z
Answers.Text: First try with smaller sized videos closer to the sizes mentioned in the Q.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T10:15:31.880Z
Answers.Text: in smaller video it works but not higher resolution video.
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T10:23:26.893Z
Answers.Text: Insufficient resources - likely memory allocation failure
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T10:25:54.737Z
Answers.Text: thanks , if this doesnt work with it then i have one scenario if output height and width are fixed like 854*480 and videos are merge into that in center then how to do that?
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T10:44:18.787Z
Answers.Text: New command added
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T10:52:13.560Z
Answers.Text: thank you bro but i have error inside that please check updated question
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T11:11:23.523Z
Answers.Text: What's the command you executed?
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T11:25:37.333Z
Answers.Text: sorry it was my fault , thank you so much for your precious help . and any refrance for learning ffmpeg from scrach ? give me resources please
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-02T05:49:24.063Z
Answers.Text: second video's sound is gone while this command is running
Answers.UserDisplayName: Nikunj Paradva
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-01T08:38:15.490Z
Answers.LastActivityDate: 2019-05-01T10:44:09.450Z
Answers.LastEditDate: 2019-05-01T10:44:09.450Z
Answers.UserDisplayName: Gyan
Body: <p>I am confused how to do this thing with no-crop in android with ffmpeg,</p>
  
  <blockquote>
    <h3>Video details</h3>
    
    <p><strong>video 1</strong> </p>
    
    <p>size - 700*400(width*height)</p>
    
    <p>duration - 5 second</p>
    
    <p><strong>video 2</strong> </p>
    
    <p>size - 400*600(width*height)</p>
    
    <p>duration - 5 second</p>
  </blockquote>
  
  <p><strong>Output video detail</strong></p>
  
  <p>video size - 700*600 (width*height)</p>
  
  <p>Duration : 10second</p>
  
  <p>I need this type of output please help me how to do this type of output with ffmpeg, graphical design is in bottom picture.</p>
  
  <p>Tell me FFMPEG command .</p>
  
  <p><a href="https://i.sstatic.net/2o0aY.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2o0aY.jpg" alt="enter image description here"></a></p>
  
  <p>after @gyan's answer i got this Error </p>
  
  <pre><code> onFailure: ffmpeg version n4.0-39-gda39990 Copyright (c) 2000-2018 the FFmpeg developers
        built with gcc 4.9.x (GCC) 20150123 (prerelease)
        configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-ffprobe --enable-libopus --enable-libvorbis --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-libvpx --enable-libass --enable-yasm --enable-pthreads --disable-debug --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --enable-nonfree --pkg-config=pkg-config --pkg-config-flags=--static --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags=
        libavutil      56. 14.100 / 56. 14.100
        libavcodec     58. 18.100 / 58. 18.100
        libavformat    58. 12.100 / 58. 12.100
        libavdevice    58.  3.100 / 58.  3.100
        libavfilter     7. 16.100 /  7. 16.100
        libavresample   4.  0.  0 /  4.  0.  0
        libswscale      5.  1.100 /  5.  1.100
        libswresample   3.  1.100 /  3.  1.100
        libpostproc    55.  1.100 / 55.  1.100
      Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Download/Received/VID-20190404-WA0010.mp4':
        Metadata:
          major_brand     : mp42
          minor_version   : 1
          compatible_brands: mp41mp42isom
          creation_time   : 2018-11-24T20:20:48.000000Z
        Duration: 00:00:59.51, start: 0.066667, bitrate: 649 kb/s
          Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 640x640, 646 kb/s, 29.98 fps, 30 tbr, 15360 tbn, 60 tbc (default)
          Metadata:
            creation_time   : 2018-11-24T20:20:48.000000Z
            handler_name    : Core Media Video
      Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Download/Received/Video_20171219203619535_by_vimady.mp4':
        Metadata:
          major_brand     : isom
          minor_version   : 512
          compatible_brands: isomiso2avc1mp41
          encoder         : Lavf55.19.104
        Duration: 00:00:44.54, start: 0.000000, bitrate: 17132 kb/s
          Stream #1:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
          Metadata:
            handler_name    : SoundHandler
          Stream #1:1(eng): Video: h264 (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 17001 kb/s, 26.18 fps, 24.83 tbr, 90k tbn, 180k tbc (default)
          Metadata:
            rotate          : 90
            handler_name    : VideoHandler
          Side data:
            displaymatrix: rotation of -90.00 degrees
      Input #2, lavfi, from 'color':
        Duration: N/A, start: 0.000000, bitrate: N/A
          Stream #2:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
      Stream mapping:
        Stream #0:0 (h264) -&gt; scale2ref:ref (graph 0)
        Stream #1:1 (h264) -&gt; scale2ref:ref (graph 0)
        Stream #2:0 (rawvideo) -&gt; scale2ref:default (graph 0)
        setsar (graph 0) -&gt; Stream #0:0 (libx264)
        Stream #1:0 -&gt; #0:1 (aac (native) -&gt; aac (native))
      Press [q] to stop, [?] for help
      [swscaler @ 0xb11b0000] deprecated pixel format used, make sure you did set range correctly
      [libx264 @ 0xb543b100] using SAR=1/1
      [libx264 @ 0xb543b100] using cpu capabilities: ARMv6 NEON
      [libx264 @ 0xb543b100] profile High, level 4.0
      [libx264 @ 0xb543b100] 264 - core 152 r2851M ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_ran
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-05-01T08:55:58.300Z
Comments.Text: https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player
Comments.UserDisplayName: Sanjay Hadiya
Tags: <ffmpeg><aspect><android>
Title: Merge Video with aspect ratio in FFMPEG
UserDisplayName: Nikunj Paradva
ThreadText: # Merge Video with aspect ratio in FFMPEG
  
  (Asked by: username_0 on 2019-05-01)
  
  I am confused how to do this thing with no-crop in android with ffmpeg,
  
  > ### Video details
  >
  > **video 1**
  >
  > size - 700\*400(width\*height)
  >
  > duration - 5 second
  >
  > **video 2**
  >
  > size - 400\*600(width\*height)
  >
  > duration - 5 second
  
  **Output video detail**
  
  video size - 700\*600 (width\*height)
  
  Duration : 10second
  
  I need this type of output please help me how to do this type of output with ffmpeg, graphical design is in bottom picture.
  
  Tell me FFMPEG command .
  
  [![enter image description here](https://i.sstatic.net/2o0aY.jpg)](https://i.sstatic.net/2o0aY.jpg)
  
  after @username_2's answer i got this Error
  
  ```
   onFailure: ffmpeg version n4.0-39-gda39990 Copyright (c) 2000-2018 the FFmpeg developers
        built with gcc 4.9.x (GCC) 20150123 (prerelease)
        configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-ffprobe --enable-libopus --enable-libvorbis --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-libvpx --enable-libass --enable-yasm --enable-pthreads --disable-debug --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --enable-nonfree --pkg-config=pkg-config --pkg-config-flags=--static --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags=
        libavutil      56. 14.100 / 56. 14.100
        libavcodec     58. 18.100 / 58. 18.100
        libavformat    58. 12.100 / 58. 12.100
        libavdevice    58.  3.100 / 58.  3.100
        libavfilter     7. 16.100 /  7. 16.100
        libavresample   4.  0.  0 /  4.  0.  0
        libswscale      5.  1.100 /  5.  1.100
        libswresample   3.  1.100 /  3.  1.100
        libpostproc    55.  1.100 / 55.  1.100
      Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Download/Received/VID-20190404-WA0010.mp4':
        Metadata:
          major_brand     : mp42
          minor_version   : 1
          compatible_brands: mp41mp42isom
          creation_time   : 2018-11-24T20:20:48.000000Z
        Duration: 00:00:59.51, start: 0.066667, bitrate: 649 kb/s
          Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 640x640, 646 kb/s, 29.98 fps, 30 tbr, 15360 tbn, 60 tbc (default)
          Metadata:
            creation_time   : 2018-11-24T20:20:48.000000Z
            handler_name    : Core Media Video
      Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Download/Received/Video_20171219203619535_by_vimady.mp4':
        Metadata:
          major_brand     : isom
          minor_version   : 512
          compatible_brands: isomiso2avc1mp41
          encoder         : Lavf55.19.104
        Duration: 00:00:44.54, start: 0.000000, bitrate: 17132 kb/s
          Stream #1:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
          Metadata:
            handler_name    : SoundHandler
          Stream #1:1(eng): Video: h264 (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 17001 kb/s, 26.18 fps, 24.83 tbr, 90k tbn, 180k tbc (default)
          Metadata:
            rotate          : 90
            handler_name    : VideoHandler
          Side data:
            displaymatrix: rotation of -90.00 degrees
      Input #2, lavfi, from 'color':
        Duration: N/A, start: 0.000000, bitrate: N/A
          Stream #2:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
      Stream mapping:
        Stream #0:0 (h264) -> scale2ref:ref (graph 0)
        Stream #1:1 (h264) -> scale2ref:ref (graph 0)
        Stream #2:0 (rawvideo) -> scale2ref:default (graph 0)
        setsar (graph 0) -> Stream #0:0 (libx264)
        Stream #1:0 -> #0:1 (aac (native) -> aac (native))
      Press [q] to stop, [?] for help
      [swscaler @ 0xb11b0000] deprecated pixel format used, make sure you did set range correctly
      [libx264 @ 0xb543b100] using SAR=1/1
      [libx264 @ 0xb543b100] using cpu capabilities: ARMv6 NEON
      [libx264 @ 0xb543b100] profile High, level 4.0
      [libx264 @ 0xb543b100] 264 - core 152 r2851M ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_ran
  
  ```
  
  **Tags:** ffmpeg, aspect, android
  
  > **Comments:**
  > **username_1**: https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-05-01. Score: 2 | Accepted answer
  
  You need to use a canvas which can accommodate all inputs. To adapt this canvas during runtime, we can use the scale2ref filter.
  
  `ffmpeg -i video1 -i video2 -f lavfi -i color -filter_complex "[2][0]scale2ref[canvas][vid1];[canvas][1]scale2ref='max(iw,main_w)':'max(ih,main_h)'[canvas][vid2];[canvas]split=2[canvas1][canvas2];[canvas1][vid1]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid1];[canvas2][vid2]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid2];[vid1][vid2]concat=n=2:v=1:a=0,setsar=1" out.mp4`
  
  Audio is ignored.
  
  ---
  
  To fit within a fixed size, use
  
  `ffmpeg -i video1 -i video2 -f lavfi -i color=s=854x480:r=30 -filter_complex "[0]scale=854x480:force_original_aspect_ratio=decrease[vid1];[1]scale=854x480:force_original_aspect_ratio=decrease[vid2];[2][vid1]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid1];[2][vid2]overlay=x='(W-w)/2':y='(H-h)/2':shortest=1[vid2];[vid1][vid2]concat=n=2:v=1:a=0,setsar=1" out.mp4`
  
  > **Comments:**
  > **username_0**: thanks for the answer, but after i implement your answer i got error which is i added inside question, please check it  
  > **username_2**: Don't see any error in your logs.  
  > **username_0**: it was gone in failure not completed in my android device  
  > **username_2**: First try with smaller sized videos closer to the sizes mentioned in the Q.  
  > **username_0**: in smaller video it works but not higher resolution video.  
  > **username_2**: Insufficient resources - likely memory allocation failure  
  > **username_0**: thanks , if this doesnt work with it then i have one scenario if output height and width are fixed like 854*480 and videos are merge into that in center then how to do that?  
  > **username_2**: New command added  
  > **username_0**: thank you bro but i have error inside that please check updated question  
  > **username_2**: What's the command you executed?  
  > **username_0**: sorry it was my fault , thank you so much for your precious help . and any refrance for learning ffmpeg from scrach ? give me resources please  
  > **username_0**: second video's sound is gone while this command is running  
  
  ---
  
  