0

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

after @gyan'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
1

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

| improve this answer | |
  • thanks for the answer, but after i implement your answer i got error which is i added inside question, please check it – Nikunj Paradva May 1 '19 at 9:11
  • Don't see any error in your logs. – Gyan May 1 '19 at 9:35
  • it was gone in failure not completed in my android device – Nikunj Paradva May 1 '19 at 9:43
  • First try with smaller sized videos closer to the sizes mentioned in the Q. – Gyan May 1 '19 at 9:51
  • in smaller video it works but not higher resolution video. – Nikunj Paradva May 1 '19 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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