简体   繁体   English

FFMpeg - 向已经包含声音的视频添加声音

[英]FFMpeg - add sound to video that already contain sound

Here is what I have: input1.avi - video that contain sounds.这是我所拥有的: input1.avi - 包含声音的视频。 input2.avi - video that doesn't contain sounds. input2.avi - 不包含声音的视频。 music.mp3 - audio file. music.mp3 - 音频文件。

I want to add background music(music.mp3 file) to the video.我想在视频中添加背景音乐(music.mp3 文件)。

C:\\input1.avi -i C:\\music.mp3 -shortest -c:v copy -c:a copy C:\\output1.avi then output1.avi is the same as input1 - movie with sounds but without the background music (music.mp3) C:\\input1.avi -i C:\\music.mp3 -shortest -c:v copy -c:a copy C:\\output1.avi 然后 output1.avi 与 input1 相同 - 电影有声音但没有背景音乐(音乐.mp3)

when I try to use the other file (video without sounds):当我尝试使用另一个文件(没有声音的视频)时:

C:\\input2.avi -i C:\\music.mp3 -shortest -c:v copy -c:a copy C:\\output2.avi then output2.avi is the same as input2 + it have the background music. C:\\input2.avi -i C:\\music.mp3 -shortest -c:v copy -c:a copy C:\\output2.avi 那么 output2.avi 和 input2 一样+有背景音乐。

I tried to execute this too:我也尝试执行此操作:

C:\ffmpeg\bin>ffmpeg -i C:\input.avi -i C:\music.mp3 -shortest -c:v copy -filter_ complex "[1]volume=1.5[1a];[0][1a]amerge[a]" -map 0:v -map "[a]" -ac 2 C:\output1.avi

but got the next error messsage:但收到下一条错误消息:

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:\output1.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 @ 00000000005abc20] 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
[Parsed_amerge_1 @ 0000000000610200] No channel layout for input 1
[Parsed_amerge_1 @ 0000000000610200] No channel layout for input 2
[AVFilterGraph @ 00000000005ddfe0] The following filters could not choose their
formats: Parsed_amerge_1
Consider inserting the (a)format filter near their input or output.
Error configuring complex filters.
I/O error

So why input1 does not contain the background music?那么为什么 input1 不包含背景音乐呢? and how can I decrease or increase the volume of music.mp3 file?以及如何减少或增加 music.mp3 文件的音量?

One way to do this is to use ffmpeg and Sox ( http://sox.sourceforge.net ) together:一种方法是同时使用 ffmpeg 和 Sox ( http://sox.sourceforge.net ):

  1. Extract the current soundtrack from the original video using ffmpeg使用 ffmpeg 从原始视频中提取当前音轨
  2. Use Sox to merge the extracted soundtrack and your background music使用 Sox 将提取的音轨和您的背景音乐合并
  3. Use ffmpeg to put the new merged audio track in place of the extracted original soundtrack使用 ffmpeg 将新合并的音轨代替提取的原始音轨

This sox command will allow you merge two audio files, setting the volumes as you wish:这个 sox 命令将允许您合并两个音频文件,根据需要设置音量:

sox -m -v videoVol ./temp/videoAudio.mp3 -v musicVol ./temp/tempMusic.mp3 ./temp/mixedAudio.mp3 sox -m -v videoVol ./temp/videoAudio.mp3 -v musicVol ./temp/tempMusic.mp3 ./temp/mixedAudio.mp3

There are a couple of thing to watch out for:有几点需要注意:

  • you need to check the sample rates match for the audio and if not then adjust them so they do (see below for sox syntax to change an audio rate)您需要检查音频的采样率是否匹配,如果不匹配,则对其进行调整(请参阅下面的 sox 语法以更改音频率)
  • you probably want to reduce or extend your music length so it matches the video soundtrack before you do the merge您可能希望在合并之前减少或延长音乐长度,使其与视频配乐相匹配

Sox syntax to change audio rate:用于更改音频速率的 Sox 语法:

sox ./temp/videoAudio.mp3 -r 44100 ./temp/videoAudioAdjusted.mp3 sox ./temp/videoAudio.mp3 -r 44100 ./temp/videoAudioAdjusted.mp3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM