如何在ffmpeg中控制音量
How to manipulate audio volume in ffmpeg
我正在使用 ffmpeg 命令将背景音乐叠加到已有音频的视频上。
下面是命令-
ffmpeg -i video_with_audio.webm -stream_loop -1 -i overlay_music.mp3 -vcodec copy -filter_complex amix -acodec libopus -mapping_family 0 -b:a 96k -shortest -map 0:v:0 -map 1:a:0 output_video.webm
上述命令运行良好,但我还想控制两个音频的音量。
所以为了这个目的,我正在使用命令-
cmd = "ffmpeg -i {} -filter_complex 'amovie='{}':loop=0,asetpts=N/SR/TB,volume=1[audio];[0:a]volume=3[sa];[sa][audio]amix[fa]' -map 0:v -map [fa] -vcodec copy -acodec libopus -preset ultrafast -shortest {}".format(inp_video, bg, out_video)
os.system(cmd)
但是我在在线传递时遇到错误url-
ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from '/home/abc/Desktop/abc/input_video.webm':
Metadata:
COMPATIBLE_BRANDS: isomiso2avc1mp41
MAJOR_BRAND : isom
MINOR_VERSION : 512
ENCODER : Lavf58.45.100
Duration: 00:03:52.07, start: -0.007000, bitrate: 1179 kb/s
Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv), 854x480, SAR 1:1 DAR 427:240, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
Metadata:
HANDLER_NAME : ISO Media file produced by Google Inc.
ENCODER : Lavc58.91.100 libvpx-vp9
DURATION : 00:03:52.007000000
Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
HANDLER_NAME : ISO Media file produced by Google Inc.
ENCODER : Lavc58.91.100 libopus
DURATION : 00:03:52.068000000
[Parsed_amovie_0 @ 0x56189e8f9900] Failed to avformat_open_input 'https'
[AVFilterGraph @ 0x56189e947e00] Error initializing filter 'amovie' with args 'https://dapi.videowiki.pt/media/music-lib/2021/04/05/31/21/bensound-creativeminds.mp3:loop=0'
Error initializing complex filters.
No such file or directory
电影滤镜无需循环。只需像在原始命令中一样使用 -stream_loop -1
:
ffmpeg -i video_with_audio.webm -stream_loop -1 -i overlay_music.mp3 -filter_complex "[1:a]volume=3[a1];[0:a][a1]amix" -vcodec copy -acodec libopus -mapping_family 0 -b:a 96k -shortest output.webm
作为使用 volume filter you can use the weights
option in the amix 过滤器的替代方法:
ffmpeg -i video_with_audio.webm -stream_loop -1 -i overlay_music.mp3 -filter_complex "amix=weights='3 1'" -vcodec copy -acodec libopus -mapping_family 0 -b:a 96k -shortest output.webm
或者,如果您想要“回避”,请参阅 sidechaincompress 过滤器。
我正在使用 ffmpeg 命令将背景音乐叠加到已有音频的视频上。
下面是命令-
ffmpeg -i video_with_audio.webm -stream_loop -1 -i overlay_music.mp3 -vcodec copy -filter_complex amix -acodec libopus -mapping_family 0 -b:a 96k -shortest -map 0:v:0 -map 1:a:0 output_video.webm
上述命令运行良好,但我还想控制两个音频的音量。 所以为了这个目的,我正在使用命令-
cmd = "ffmpeg -i {} -filter_complex 'amovie='{}':loop=0,asetpts=N/SR/TB,volume=1[audio];[0:a]volume=3[sa];[sa][audio]amix[fa]' -map 0:v -map [fa] -vcodec copy -acodec libopus -preset ultrafast -shortest {}".format(inp_video, bg, out_video)
os.system(cmd)
但是我在在线传递时遇到错误url-
ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from '/home/abc/Desktop/abc/input_video.webm':
Metadata:
COMPATIBLE_BRANDS: isomiso2avc1mp41
MAJOR_BRAND : isom
MINOR_VERSION : 512
ENCODER : Lavf58.45.100
Duration: 00:03:52.07, start: -0.007000, bitrate: 1179 kb/s
Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv), 854x480, SAR 1:1 DAR 427:240, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
Metadata:
HANDLER_NAME : ISO Media file produced by Google Inc.
ENCODER : Lavc58.91.100 libvpx-vp9
DURATION : 00:03:52.007000000
Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
HANDLER_NAME : ISO Media file produced by Google Inc.
ENCODER : Lavc58.91.100 libopus
DURATION : 00:03:52.068000000
[Parsed_amovie_0 @ 0x56189e8f9900] Failed to avformat_open_input 'https'
[AVFilterGraph @ 0x56189e947e00] Error initializing filter 'amovie' with args 'https://dapi.videowiki.pt/media/music-lib/2021/04/05/31/21/bensound-creativeminds.mp3:loop=0'
Error initializing complex filters.
No such file or directory
电影滤镜无需循环。只需像在原始命令中一样使用 -stream_loop -1
:
ffmpeg -i video_with_audio.webm -stream_loop -1 -i overlay_music.mp3 -filter_complex "[1:a]volume=3[a1];[0:a][a1]amix" -vcodec copy -acodec libopus -mapping_family 0 -b:a 96k -shortest output.webm
作为使用 volume filter you can use the weights
option in the amix 过滤器的替代方法:
ffmpeg -i video_with_audio.webm -stream_loop -1 -i overlay_music.mp3 -filter_complex "amix=weights='3 1'" -vcodec copy -acodec libopus -mapping_family 0 -b:a 96k -shortest output.webm
或者,如果您想要“回避”,请参阅 sidechaincompress 过滤器。