Streams are mixed when using -filter_complex amerge in FFmpeg

I am having problems with ffmpeg and one of its filters.

I am trying to combine 2 audio video streams into one. for that i tried this command:

ffmpeg -i /home/maniaplanet/Videos/ManiaPlanet\ 2014-08-21\ 20-09-13-082.avi.output.mkv -filter_complex "[0:1][0:2] amerge=inputs=2"-c:v copy -c:a libvo_aacenc -b:a 256k /var/www/files/output.mp4

      

But I am getting this output:

ffmpeg version 1.0.10 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 25 2014 07:50:40 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libfdk-aac --enable-libdc1394 --disable-altivec --dis  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, matroska,webm, from '/home/maniaplanet/Videos/ManiaPlanet 2014-08-21 20-09-13-082.avi.output.mkv':
  Metadata:
    ISRC            : Video:RGB24 Audio0:Headset (2- Plantronics .Audio 655 DSP) Audio1:Headset (2- Plantronics .Audio 655 DSP)
    ENCODER         : Lavf55.37.100
  Duration: 01:49:48.47, start: 0.000000, bitrate: 3867 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 1280x1024, SAR 1:1 DAR 5:4, 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
    Stream #0:1: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s (default)
    Stream #0:2: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s (default)
File '/var/www/files/output.mp4' already exists. Overwrite ? [y/N] y
Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[libvo_aacenc @ 0x7ae800] Unable to set encoding parameters
Output #0, mp4, to '/var/www/files/output.mp4':
  Metadata:
    ISRC            : Video:RGB24 Audio0:Headset (2- Plantronics .Audio 655 DSP) Audio1:Headset (2- Plantronics .Audio 655 DSP)
    ENCODER         : Lavf55.37.100
    Stream #0:0: Audio: aac, 48000 Hz, 4.0, s16, 256 kb/s
    Stream #0:1: Video: h264, yuv420p, 1280x1024 [SAR 1:1 DAR 5:4], q=2-31, 30 fps, 90k tbn, 1k tbc (default)
Stream mapping:
  Stream #0:1 (mp3) -> amerge:in0
  Stream #0:2 (mp3) -> amerge:in1
  amerge -> Stream #0:0 (libvo_aacenc)
  Stream #0:0 -> #0:1 (copy)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

      

I think the important part is at the bottom:

Stream mapping:
  Stream #0:1 (mp3) -> amerge:in0
  Stream #0:2 (mp3) -> amerge:in1
  amerge -> Stream #0:0 (libvo_aacenc)
  Stream #0:0 -> #0:1 (copy)

      

It displays the video stream as the second stream and the audio becomes the first. How to solve this? -map

did not help. (Maybe I was just using it wrong)

+3


source to share


1 answer


Example

ffmpeg -i input -filter_complex "[0:a:0][0:a:1] amerge=inputs=2 [a]" \
-map [0:v] -map "[a]" -c:v copy -c:a libfdk_aac -ac 2 -b:a 128k output.mp4

      



Notes

  • Your result in your question contained 4 channels of audio, but I'm assuming you really wanted to downgrade it to stereo. You can do this with the pan audio filter or -ac 2

    as shown above. See FFmpeg Audio Channel Manipulation: 2 × stereo → stereo for an example using panning.

  • As you may have guessed, you can control the display with -map

    . The display order can determine the output of the output display.

  • libfdk_aac is the best AAC encoder supported ffmpeg

    and libvo_aacenc is the worst. I switched to libfdk_aac since your build supports it and it will slow down the transfer rate and still sounds good. See the FFmpeg AAC Encoding Guide .

  • I changed the filtering input from [0:1]

    to [0:a:0]

    which means " first input:audio stream type:first (audio) stream

    ". In this case, it maps to the same stream, but that allows you to be a little lazy.

  • You can add -movflags +faststart

    if your viewers will watch this through progressive loading in a browser. It will move the moov atom from the end of the file to the beginning so that playback starts with less expectation from the viewer.

+6


source







All Articles