ffmpeg - 在ffmpeg中的音频之间多次插入随机静音

标签 ffmpeg ffmpeg-php

假设我有大约 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.wavasetpts 过滤器保留时间间隔 0 到 2 的时间戳。它将时间戳为 2s 或更高的所有帧的时间戳增加 2 秒。它进一步为时间戳 >= 5 的所有帧增加 3 秒,为所有时间戳为 9 或更高的帧增加一秒。 T指源时间戳。aresample过滤器然后用静默塞住所有时间戳间隙。

关于ffmpeg - 在ffmpeg中的音频之间多次插入随机静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69302506/

相关文章:

python - 提取帧失败,出现 : Invalid data found when processing input

php - 使用 PHP shell_exec 和 ffmpeg 合并 2 个音频文件

html - 如何在使用 ffmpeg php 启动流后停止流?

FFMPEG 将多个音频输入文件映射到 1 个单个图像文件,以便创建多个视频输出文件

video - 如何使用 ffmpeg 将视频放置在较大的静态背景图像之上的特定位置?

video - 对编码流进行 ffmpeg 解码(作为缓冲区出现)

ffmpeg - 如何导出 Adob​​e Connect 视频?

php - 建议 fatal error : Uncaught exception 'Alchemy\BinaryDriver\Exception\ExecutableNotFoundException' with message 'Executable not found,

php - 我怎么知道 ffmpeg-php 已安装?

php - 压缩/减小视频的文件大小