我目前在使用ffmpeg和它的一个过滤器时有问题。
我正在尝试将视频的2个音频流合并为一个。为此,我尝试了以下命令:
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
但是我得到这个输出:
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
我认为最重要的部分在下面:
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)
它将视频流映射为第二流,音频首先获得。我该如何解决这个问题?-map
没有帮助。(也许我用错了)
示例
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
<标题> 指出你的问题中包含4个音频通道的输出,但我假设你实际上想把它调低到立体声。您可以使用泛音频滤波器或
-ac 2
来做到这一点,如上所示。参考FFmpeg音频通道操作:2 ×立体声→立体声的例子。如您所料,您可以使用
-map
控制映射。映射的顺序可以决定输出映射的输出libfdk_aac是
ffmpeg
支持的最好的AAC编码器,libvo_aacenc是最差的。我切换到libfdk_aac,因为你的构建支持它,它将允许更低的比特率,仍然听起来相当不错。参考FFmpeg AAC编码指南我将过滤输入从
[0:1]
更改为[0:a:0]
,这意味着"first input:audio stream type:first (audio) stream
"。在这种情况下,它映射到相同的流,但这允许您稍微偷懒。你可以添加
-movflags +faststart
,如果你的观众要看这个通过浏览器的渐进式下载。它将把moov原子从文件的末尾重新定位到开头,以允许观看者在更短的等待时间内开始播放。