0

ffmpeg has a wiki on Concatenate at
https://trac.ffmpeg.org/wiki/Concatenate

It does concatenation without any conversion. I'm wondering if it is possible to do the concatenation WHILE doing the format conversion. I believe either the following two will do,

 ffmpeg -i Talk-A.MP4 -i Talk-B.MP4 -c:a libvorbis -q:a 5 -c:v libx264 -x264-params crf=22 -pix_fmt yuv420p -y -vf scale=960:-1 -af volume=2 Talk.mkv
 ffmpeg -i "concat:Talk-A.MP4|Talk-B.MP4" -c:a libvorbis -q:a 5 -c:v libx264 -x264-params crf=22 -pix_fmt yuv420p -y -vf scale=960:-1 -af volume=2 Talk.mkv

But both of them only give the result of the first part in the output file.

So I tried exactly as what the wiki suggested:

 ffmpeg -i "concat:Talk-A.MP4|Talk-B.MP4" -c copy Talk.mp4

But that as well produces an output file containing only the first part.

What could be possibly wrong?

UPDATE:

OK. I was hoping to avoid the most complicated one if possible, and I now know that I have to go for the most complicated solution, as explained in LordNeckbeard's reply.

My updated question is, how to combine more than two files together, say three? Because I'm not sure about the syntax. Please confirm if the following is correct:

ffmpeg -i input1.mp4 -i input2.webm  -i input3.avi \
-filter_complex "[0:0] [0:1] [1:0] [1:1] [2:0] [2:1] concat=n=3:v=1:a=1 [v] [a]" \
-map "[v]" -map "[a]" <encoding options> output.mkv

And explain how to do video scaling and audio volume adjustment in this case.

Thanks

PS my ffmpeg

$ ffmpeg --version
ffmpeg version 2.7.2-1~vivid1 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
  configuration: --prefix=/usr --extra-version='1~vivid1' --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --enable-shared --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libdcadec --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libxvid --enable-libzvbi --enable-opengl --enable-nonfree --enable-libfdk-aac --enable-libvo_aacenc --enable-version3 --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libsoxr --enable-openal --enable-libopencv --enable-libx265
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Unrecognized option '-version'.
1

Wrong concat

You're using the wrong concat (protocol, filter, and demuxer). You should use the filter or the demuxer, but in your case I recommend the filter since you're filtering and re-encoding anyway.

As mentioned in the wiki link you provided:

While the demuxer works at the stream level, the concat protocol works at the file level. Only certain files (mpg and mpeg transport streams, possibly others) can be concatenated with the concat protocol. This is analogous to using cat on UNIX-like systems or copy on Windows.

Example concat filter command

ffmpeg -i input0.mp4 -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[v0][a0]; \
 [v0]scale=960:-2,format=yuv420p[v]; \
 [a0]volume=2[a]" \
-map "[v]" -map "[a]" \
-c:v libx264 -crf 22 -c:a libvorbis -q:a 5 output.mkv
7
  • What an amazing reply. Thanks. Alright, I was hoping to avoid the most complicated one if possible. OK. Hmm..., hold on, I got this while trying to use -vf scale=960:-2: -vf/-af/-filter and -filter_complex cannot be used together for the same stream. Is there any way to get what I want to do in one step (concat & scale down)? Else, would that means concating with demuxer is the only pre-prepare option now? Thx
    – xpt
    Aug 11 '15 at 21:17
  • 1
    @xpt My example command has the scale in it. You can do everything in one filtergraph, so no need for multiple -vf, -af, -filter, or -filter_complex.
    – llogan
    Aug 11 '15 at 21:38
  • Perfect! I didn't look closely, :-) One more question, I'm still trying to figure out the exact syntax. Could you give another example that need to combine three files together? I got the part [0:0] [0:1] [1:0] [1:1] [2:0] [2:1], but moving onto the concat=n=... part I'm not sure there. Also, the wiki have more space, while yours have some extra ;. Neither of them matters right? THX!
    – xpt
    Aug 12 '15 at 21:47
  • @xpt Please provide a link to a pastebin site showing the complete output of ffmpeg -i input1 -i input2 -i input3
    – llogan
    Aug 13 '15 at 1:50
  • 1
    @xpt Added another input to the example to display how to concat 3 inputs (assuming each input has one video stream and one audio stream).
    – llogan
    Aug 14 '15 at 23:52

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.