Cynapsis Cynapsis - 3 months ago 52
Android Question

ffmpeg concat video fails on Android

I'm using this library to integrate ffmpeg to my android app.

I was able to successfully crop videos with the library but now I need to concatenate two videos that are exactly the same resolution.

The ffmpeg command I use is

-i input1.mp4 -i input2.mp4 -filter_complex concat=n=2:v=1:a=1 -f MP4 out.mp4


I'm getting the above error when I run that command on those 2 videos




ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/CameraDemo/1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-09-02 10:17:23
com.android.version: 7.0
Duration: 00:00:04.46, start: 0.000000, bitrate: 6078 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m), 720x480, 6010 kb/s, SAR 1:1 DAR 3:2, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 270
creation_time : 2016-09-02 10:17:23
handler_name : VideoHandle
Side data:
displaymatrix: rotation of 90.00 degrees
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 96 kb/s (default)
Metadata:
creation_time : 2016-09-02 10:17:23
handler_name : SoundHandle
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/CameraDemo/1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-09-02 10:17:23
com.android.version: 7.0
Duration: 00:00:04.46, start: 0.000000, bitrate: 6078 kb/s
Stream #1:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m), 720x480, 6010 kb/s, SAR 1:1 DAR 3:2, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 270
creation_time : 2016-09-02 10:17:23
handler_name : VideoHandle
Side data:
displaymatrix: rotation of 90.00 degrees
Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 96 kb/s (default)
Metadata:
creation_time : 2016-09-02 10:17:23
handler_name : SoundHandle
Cannot find a matching stream for unlabeled input pad 4 on filter Parsed_concat_0



edit 1: Fixin the n=3 to n=2 changed the error message to
Filter concat:out:v0 has a unconnected output

Answer

The n value is wrong. You have only two inputs.

-i input1.mp4 -i input2.mp4 -filter_complex concat=n=2:v=1:a=1 -f MP4 out.mp4

Also, in case ffmpeg complains about mapping, use

-filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map [v] -map [a] out.mp4