这是我所拥有的: input1.avi - 包含声音的视频。 input2.avi - 不包含声音的视频。 music.mp3 - 音频文件。
我想在视频中添加背景音乐(music.mp3文件)。
C:\input1.avi -i C:\music.mp3 -shortest -c:v copy -c:a copy C:\output1.avi
然后output1.avi与input1相同 - 带声音的电影但没有背景音乐(music.mp3)
当我尝试使用其他文件(没有声音的视频)时:
C:\input2.avi -i C:\music.mp3 -shortest -c:v copy -c:a copy C:\output2.avi
然后output2.avi与input2相同+它有背景音乐。
为什么input1不包含背景音乐? 以及如何减少或增加music.mp3文件的音量?
感谢。
控制台输出:
C:\motionbee\ffmpeg\bin>ffmpeg -i C:\input.avi
-i C:\music.mp3 -shortest -c:v copy -filter_
complex "[0:a]aformat=fltp:44100:stereo[0a];[1]aformat=fltp:44100:stereo,volume=
1.5[1a];[0a][1a]amix[a]" -map 0:v -map "[a]" -ac 2 C:\output1.avi
ffmpeg version N-78949-g6f5048f Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopenc
ore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --ena
ble-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable
-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --ena
ble-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx
264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable
-lzma --enable-decklink --enable-zlib
libavutil 55. 19.100 / 55. 19.100
libavcodec 57. 27.101 / 57. 27.101
libavformat 57. 28.100 / 57. 28.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 39.100 / 6. 39.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, avi, from 'C:\input.avi':
Metadata:
encoder : Lavf57.28.100
Duration: 00:02:05.76, start: 0.000000, bitrate: 450 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (XVID / 0x44495658), yuv420p, 720
x480 [SAR 1:1 DAR 3:2], 440 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, s16p, 128 k
b/s
[mp3 @ 00000000005c8020] Skipping 0 bytes of junk at 32370.
Input #1, mp3, from 'C:\music.mp3':
Metadata:
title : Broadcast News Package - News Intro
artist : After Effects News Template
Duration: 00:01:57.89, start: 0.025057, bitrate: 194 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 192 kb/s
Metadata:
encoder : Lavc56.26
File 'C:\output1.avi' already exists. Overwrite
? [y/N] y
Output #0, avi, to 'C:\output1.avi':
Metadata:
ISFT : Lavf57.28.100
Stream #0:0: Video: mpeg4 (XVID / 0x44495658), yuv420p, 720x480 [SAR 1:1 DAR
3:2], q=2-31, 440 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 44100 Hz, stereo
, fltp (default)
Metadata:
encoder : Lavc57.27.101 libmp3lame
Stream mapping:
Stream #0:1 (mp3) -> aformat
Stream #1:0 (mp3) -> aformat
Stream #0:0 -> #0:0 (copy)
amix -> Stream #0:1 (libmp3lame)
Press [q] to stop, [?] for help
frame= 3118 fps=0.0 q=-1.0 Lsize= 6917kB time=00:02:05.76 bitrate= 450.6kbits
/s speed= 867x
video:6754kB audio:74kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 1.307944%
答案 0 :(得分:9)
当有多个流可用且未指定地图时,ffmpeg从输入中选择一个视频和一个音频流。
由于您可能需要重新编码音频,因此可以使用
ffmpeg -i C:\input1.avi -i C:\music.mp3 -c:v copy \
-filter_complex "[0:a]aformat=fltp:44100:stereo,apad[0a];[1]aformat=fltp:44100:stereo,volume=1.5[1a];[0a][1a]amerge[a]" \
-map 0:v -map "[a]" -ac 2 C:\output1.avi
答案 1 :(得分:0)
我尝试过此命令似乎有效。
ffmpeg -i audio.mp3 -i input.mp4 -filter_complex "[0:a][1:a]amerge,pan=stereo|c0<c0+c2|c1<c1+c3[out]" -map 1:v -map "[out]" -c:v copy -shortest output.mp4
事物发生了变化:
('stereo|c0<c0+c2|c1<c1+c3' instead of 'stereo|c0<c0+c2:c1<c1+c3')