假设我有大约 1 分钟持续时间的 MP3 并增加它的持续时间更长。持续时间可以是任何。
我想为该音频随机添加 N 秒的静音。
我可以产生如下的沉默
ffmpeg -f lavfi -i anullsrc=r=44100:cl=mono -t <seconds> -q:a 9 -acodec libmp3lame out.mp3
我可以像下面这样在音频中插入静音ffmpeg -i in.wav -filter_complex "anullsrc,atrim=0:4[s];[0]atrim=0:14[a];[0]atrim=14,asetpts=N/SR/TB[b];[a][s][b]concat=3:v=0:a=1" out.wav
无论如何要在多个区域插入静音。使用 php,我可以根据 60 秒音频生成随机时间插入,如下所示。$arr = [];
$arr[3] = 2; //here 3 is original audio insert time and 2 is the duration of silence
$arr[6] = 3; //here 6 is original audio insert time and 3 is the duration of silence
$arr[10] = 1;
$arr[12] = 3;
现在我想根据上面的数组在几秒钟之间插入静音,比如2 seconds silence at 3rd second
3 seconds silence at 6th second
1 second silence at 10th second
和儿子..
最佳答案
我假设您在执行 ffmpeg 之前就知道静音的位置和持续时间。
举个例子,
2 seconds silence at 3rd second
3 seconds silence at 6th second
1 second silence at 10th second
你会跑ffmpeg -i in.wav -af "asetpts='PTS+gte(T\,2)*2/TB+gte(T\,5)*3/TB+gte(T\,9)*1/TB',aresample=async=1" out.wav
asetpts 过滤器保留时间间隔 0 到 2 的时间戳。它将时间戳为 2s 或更高的所有帧的时间戳增加 2 秒。它进一步为时间戳 >= 5 的所有帧增加 3 秒,为所有时间戳为 9 或更高的帧增加一秒。 T
指源时间戳。aresample
过滤器然后用静默塞住所有时间戳间隙。
关于ffmpeg - 在ffmpeg中的音频之间多次插入随机静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69302506/