3

If I try to concat two mp4 video files via -filter_complex using command:

ffmpeg -i a.mp4 -i b.mp4 -filter_complex \
"[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]" \
-map [v] -map [a] -y testfull.mp4

It works fine but if I try similar with audio files like:

ffmpeg -i a.mp3 -i b.mp3 -filter_complex \
"[0:1] [0:0] [1:1] [1:0] concat=n=2:a=1 [a]" \
-map [a] -y testfull.mp3

Error arises:

Input #1, mp3, from 'b.mp3':   Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isomavc1mp42
    creation_time   : 2010-12-13 21:15:11
    encoder         : Lavf53.4.0   Duration: 00:02:01.61, start: 0.000000, bitrate: 64 kb/s
    Stream #1:0: Audio: mp3, 8000 Hz, stereo, s16p, 64 kb/s
Stream specifier ':1' in filtergraph description [0:1] [0:0] [1:1] [1:0] concat= n=2:a=1 [a] matches no streams.

If I modify -filter_complex argument and run command as:

ffmpeg -i a.mp3 -i b.mp3 -filter_complex \
"concat=n=2:a=1 [a]" -map [a] -y testfull.mp3

The following error arises

Input #1, mp3, from 'b.mp3':   Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isomavc1mp42
    creation_time   : 2010-12-13 21:15:11
    encoder         : Lavf53.4.0   Duration: 00:02:01.61, start: 0.000000, bitrate: 64 kb/s
    Stream #1:0: Audio: mp3, 8000 Hz, stereo, s16p, 64 kb/s
Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_concat_ 0

Can anyone help me how can I join two audio files via latest ffmpeg builds possibly with -filter_complex.


Update: Ok, resolved my issue with this ffmpeg command:

ffmpeg -i "concat:a.mp3|b.mp3" -c copy output.mp3
0

4 Answers 4

5

you have to tell the concat filter that there will be no video: v=0 and you don't need to address video stream [0:0] [1:0] either, so the command would be like:

ffmpeg -i a.mp3 -i b.mp3 -filter_complex \
"[0:a] [1:a] concat=n=2:v=0:a=1 [a]" \
-map [a] -c:a mp3 testfull.mp3
1
  • This won't work. MP3s are single stream, so [0:1][1:1] will fail. Use [0:a][1:a] Also, you can't copy stream when using filters, so it will be -c:a mp3
    – Gyan
    Sep 7, 2016 at 12:56
1

Just to make things clear [0:1] [0:0] [1:1] [1:0] refers to the streams from the 2 files.

In your case:

[0:1] is video from first file  
[0:0] is audio from first file  
[1:1] is video from second file  
[1:0] is audio from second file

In the case of mp3 files video streams do not exist. So you should drop the video stream references in the command.

In case of your last command that works- yes that is a valid solution for mp3 files.

1
  • yes i dropped but still get errors. resolved my issue by directly concatenating streams instead of using filters
    – irfanmcsd
    Nov 19, 2014 at 2:40
0

n is the number of STREAM SEGMENTS, NOT INPUT FILES

from the concat docs

The filter works on segments of synchronized video and audio streams. All segments must have the same number of streams of each type, and that will also be the number of streams at output.

The filter accepts the following options:

n - Set the number of segments. Default is 2.

I have been battling this the past few days and have been reading this question and its responses over and over. i was merging a PNG sequence (input 0) with a WAV file (input 1) and kept getting the same error

Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_concat_ 0

After upteen trials and fails, i fell upon n=1 (ie one desired output stream) with v=1:a=1 ... ie one video and one audio input stream.. aka concat ONE SEGMENT comprised of a video from input 0 and audio from input 1 and tada it worked just fine.

full cmdline

ffmpeg -i '/var/tmp/input.%04d.png -i '/var/tmp/input.wav' -filter_complex '[0:v:0] [1:a:0] concat=n=1:v=1:a=1 [vout] [aout]' -map '[vout]' -map '[aout]' -vcodec 'mjpeg' '/var/tmp/output.mov'

0
0

You have to mix the audio streams:

ffmpeg -i 1.mp4 -i 1.3gp -i 2.3gp -i 1.mp3
  -filter_complex "[2]adelay=10000|10000[s2];[3:a][1:a][s2]amix=3[a]"
  -map 0:v -map "[a]" -c:v copy result.mp4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .