【问题标题】:FFMPEG set volume in amixFFMPEG 在 amix 中设置音量
【发布时间】:2017-11-26 12:40:35
【问题描述】:

我一直在尝试将音频 mp3 与视频 mp4 混合,同时保留 mp4 音频。这是与 .

ffmpeg -y  -i video.mp4 -i audio.mp3
 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest[out]" 
 -map 0:v -map [out] output.mp4

我现在正在尝试调整声音文件(视频 0.5,音频 1)的音量,作为混音的一部分。

我一直在尝试类似的事情

ffmpeg  -i 020c276b-face-4bb3-9169-e8969c1232ba.mp4 -i test.mp3 -filter_complex 
 "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1]; 
  [1:a]aformat=sample_fmts fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2]; 
  [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]"-map 1:v -map [out]
  -c:v copy -c:a aac -strict -2  output2.mp4`

我收到诸如

之类的错误

[Parsed_aformat_2 @ 037f8620] 解析样本格式时出错:sample_fmts ftp。 [AVFilterGraph @ 038be620] 初始化过滤器“aformat”时出错 带 args '样本 _fmts fltp:sample_rates=44100:channel_layouts=stereo' 初始化复杂过滤器时出错。无效参数

有谁知道如何使我上面的代码正常工作,同时改变输入的音量?

谢谢

【问题讨论】:

  • 谢谢,我试过了。它用于混合音频,不涉及视频。我收到此错误 [AVFilterGraph @ 04f289a0] 以下过滤器无法选择其格式: Parsed_amerge_2 考虑在其输入或输出附近插入 (a) 格式过滤器。配置复杂过滤器时出错。发生错误号 -5

标签: audio video ffmpeg


【解决方案1】:

如果你想使用amix,我建议你这样使用:

ffmpeg -i video.mp4 -i audio.mp3 -filter_complex \
"[0:a]volume=0.8[a0]; \
[1:a]volume=0.8[a1]; \
[a0][a1]amix=inputs=2[a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -shortest output.mp4 ;

对于amerge 方法:

ffmpeg -i video.mp4 -i audio.mp3 -filter_complex \
"[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a0]; \
[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a1]; \
[a0][a1]amerge,pan=stereo|c0<c0+c2|c1<c1+c3 [a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -strict -2 -shortest output.mp4 ;

Mulvya 的每个 cmets 需要记住的事项:

amerge 以最短输入(总是)和amix 终止 默认情况下,以最长的输入终止。所以前者会 当流的长度不同时总是截断。

-y 为测试目的而省略。

【讨论】:

  • 两种方法的输出应该产生相同(或非常接近)的文件 --> 不。 amix 缩放每个输入。见stackoverflow.com/a/38714779/5726027
  • @Mulvya:我想你可能误解了我的意思。在这个特定的例子中,这些方法本质上是做同样的事情——生成的文件可能是相同的;也许检查哈希。如果使用更多的输入和退出,你肯定会看到不同,是的。
  • 即使有两个输入,如果一个较短,你会得到不同的。
  • @Mulvya:“更短”是什么意思?
  • 默认情况下,amerge 以最短的输入(总是)终止,而 amix 以最长的输入终止。因此,当流的长度不同时,前者总是会截断。
【解决方案2】:

这个答案有效https://superuser.com/questions/715254/the-following-filters-could-not-choose-their-formats-parsed-amerge-5-consider-i

> ffmpeg -i audio.mp3 -i  video.mp4 -filter_complex
> "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];
> [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];
> [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" -map 1:v -map
> "[out]" -c:v copy -c:a aac -strict -2 -shortest output.mp4

虽然它确实引发了一些似乎并没有阻止它的错误

帧= 93 fps=0.0 q=-1.0 大小= 642kB 时间=00:00:03.78 bitra 帧= 224 fps=224 q=-1.0 大小= 1595kB 时间=00:00:09.28 bitra 解码流 #1:1 时出错:发生错误号 -12 最后一条消息重复 158 次 frame= 274 fps=182 q=-1.0 size= 2382kB time=00:00:11.35 bitra 解码流时出错 #1:1: Error 数量 -12 发生

【讨论】:

  • 我会警惕这些错误...我会为你举一个使用 amix 的例子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-15
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 2021-01-02
相关资源
最近更新 更多