简体   繁体   English

如何在 ffmpeg 的混音中插入某些其他声音时停止声音?

[英]How to stop a sound when certain other sound is inserted in the mix in ffmpeg?

I'm using a ffmpeg command that takes a set of sounds, mixes them into a single file, separating them by certain time intervals.我正在使用 ffmpeg 命令获取一组声音,将它们混合到一个文件中,按特定时间间隔将它们分开。

Below is how my command is today.以下是我今天的命令。

ffmpeg -i 
close_hh.wav    -i \
crash_l.wav     -i \
crash_r.wav     -i \
floor.wav       -i \
kick_l.wav      -i \
kick_r.wav      -i \
open_hh.wav     -i \
ride.wav        -i \
snare.wav       -i \
splash.wav      -i \
tom_1.wav       -i \
tom_2.wav       -i \
  tom_3.wav  -filter_complex  " [6]adelay=0|0[note_0];  [0]adelay=360|360[note_1];  [6]adelay=1260|1260[note_2];  [0]adelay=1537|1537[note_3];  [6]adelay=2494|2494[note_4];  [5]adelay=2767|2767[note_5];  [0]adelay=2969|2969[note_6];  [6]adelay=3673|3673[note_7];  [5]adelay=3924|3924[note_8];  [0]adelay=4132|4132[note_9];  [0][note_0][note_1][note_2][note_3][note_4][note_5][note_6][note_7][note_8][note_9]amix=inputs=11:normalize=0" record.wav

This is the resulting audio that this command generates:这是此命令生成的结果音频:

ffmpg record.wav: https://drive.google.com/file/d/1LFV4ImLKLnRCqZRhZ7OqZy4Ecq5fwT3j/view?usp=sharing ffmpg 记录.wav: https://drive.google.com/file/d/1LFV4ImLKLnRCqZRhZ7OqZy4Ecq5fwT3j/view?usp=sharing

The purpose is to generate a drum recording, so I would like to simulate the dynamics of the hi-hat sounds: When the closed hi-hat is played, the open hi-hat will stop playing immediately if it is still sounding.目的是生成鼓录音,所以我想模拟踩镲声音的动态:当关闭的踩镲演奏时,打开的踩镲如果还在响,会立即停止播放。 The same behavior does not happen for any of the other sounds.任何其他声音都不会发生相同的行为。

One point that makes this a little more challenging is that other sounds can also be played between open hi-hat and closed hi-hat strikes, and theoretically the sound interruption behavior should work normally.使这更具挑战性的一点是,在打开踩镲和关闭踩镲之间也可以播放其他声音,理论上声音中断行为应该正常工作。

Below is a recording demonstrating the expected result.以下是演示预期结果的录音。 (My app already reproduces the sound result I need internally, so I just made a simple recording with the microphone to illustrate) (我的应用程序已经在内部再现了我需要的声音结果,所以我只是用麦克风做了一个简单的录音来说明)

mic record.wav https://drive.google.com/file/d/19x19Fd_URQVo-MMCmGEHIC1SjaQbpWrh/view?usp=sharing mic record.wav https://drive.google.com/file/d/19x19Fd_URQVo-MMCmGEHIC1SjaQbpWrh/view?usp=sharing

Notice that in the first audio (ffmpeg record.wav) the first sound (open hi-hat) continues playing after the second is played.请注意,在第一个音频 (ffmpeg record.wav) 中,第一个声音(打开踩镲)在第二个播放后继续播放。 In the second audio (mic record.wav) the first sound stops immediately after the second sound is played.在第二个音频 (mic record.wav) 中,第一个声音在第二个声音播放后立即停止。

How should the ffmpeg command be to get the expected result? ffmpeg命令应该如何得到预期的结果?

While I'm not sure FFmpeg is the correct tool to synthesize music, here is a couple ways to approach your goal.虽然我不确定 FFmpeg 是合成音乐的正确工具,但这里有几种方法可以帮助您实现目标。 First, I suggest to "compose" one instrument (in the case of a drumset, one drum/cymbal) at a time as illustrated below and then mix full tracks of instruments together.首先,我建议如下图所示一次“创作”一种乐器(在鼓组的情况下,一种鼓/铙钹),然后将乐器的完整音轨混合在一起。

Now, let's take the first 3 hi-hat segments to show how you can construct a filtergraph to form a hi-hat track.现在,让我们以前 3 个踩镲片段来展示如何构建滤波器图以形成踩镲音轨。

(1) Trim each file to the length and concatenate all streams: (1) 将每个文件修剪到一定长度并连接所有流:

[0]atrim=duration=0.36[note_0]; \
[6]atrim=duration=0.9[note_1]; \
[0]atrim=duration=0.277[note_2]; \
[note_0][note_1][note_2]concat=3:0:1[aout]

While this works, if there is any audible sound at the trimmed moment, you'll likely hear the abrupt cut-off of the sound.虽然这有效,但如果在修剪的时刻有任何可听见的声音,您可能会听到声音突然中断。 This brings the alternate...这带来了替代...

(2) Trim each file to the length + extra and cross-fade: (2) 将每个文件修剪到长度 + 额外和交叉淡入淡出:

Let's say 10 ms overlap suffices, then you want to elongate each segment by 10 ms (0.01 s).假设 10 毫秒的重叠就足够了,那么您希望将每个片段延长 10 毫秒(0.01 秒)。

[0]atrim=duration=0.37[note_0]; \
[6]atrim=duration=0.91[note_1]; \
[0]atrim=duration=0.277[note_2]; \ # last file remain same length
[note_0][note_1]acrossfade=d=0.01:c1=exp:c2=exp[notes_01] \
[note_01][note_2]acrossfade=d=0.01:c1=exp:c2=exp[notes_012]

This will get ridiculously long, so you can shorten a bit by这会变得很长,所以你可以缩短一点

[0]atrim=duration=0.37[note_0]; \
[6]atrim=duration=0.91,[note_0]acrossfade=d=0.01:c1=exp:c2=exp[notes_01]; \
[0]atrim=duration=0.277,[note_01]acrossfade=d=0.01:c1=exp:c2=exp[notes_012];

The c1 and c2 are the fading curve profiles. c1c2是衰落曲线配置文件。 See this Wiki page for the available fade curves .有关可用的淡入淡出曲线,请参阅此 Wiki 页面

Finally, I arbitrarily chose 10 ms, and it is likely too short, so experiment and pick the best overlap duration.最后,我随意选择了 10 毫秒,它可能太短了,因此请试验并选择最佳重叠持续时间。

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

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