FFmpeg实现将音频声音变细或变粗

在做录音机磁带倒带或者磁带受潮的时候,音频的声音会变得特别细或者特别粗,主要因素还是播放的时候采样被改变所致,下面来看一下用ffmpeg如何实现对应的效果。

通常单设置采样率时是无法达到很好的效果的,但是可以通过控制播放速度进行处理,播放速度在历史文章中可以看到相关介绍,通过命令行实现如下。

步骤:

  1. 输入三个音频流,全部为44100Hz的采样
  2. 将其中一个音频流的采样设置为22050Hz,并将播放速度设置为2倍
  3. 将其中另一个音频流采样设置为98000Hz,并将播放速度设置为0.5倍
  4. 将三个音频按照采样从低到高拼接

命令行部分:

StevenLiu:dash StevenLiu$ ffmpeg -v quiet -i b.mp3 -filter_complex "amovie=b.mp3[a1];amovie=b.mp3[a2];[0:a]adelay=8000|8000|8000[am];[a1]asetrate=22050,atempo=2[a0];[a0][am]amix[ao];[a2]asetrate=98000,atempo=0.5,adelay=16000|16000|16000[a22];[ao][a22]amix[oa];[oa]asetnsamples=1024" -y c.mp3

代码部分:


StevenLiu:dash StevenLiu$ git diff ../doc/examples/transcoding.c
diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index e48837cbd2..47b8fa669a 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -393,7 +393,7 @@ static int init_filters(void)
         if (ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
             filter_spec = "null"; /* passthrough (dummy) filter for video */
         else
-            filter_spec = "anull"; /* passthrough (dummy) filter for audio */
+            filter_spec = "amovie=b.mp3[a1];amovie=b.mp3[a2];[in]adelay=8000|8000|8000[am];[a1]asetrate=22050,atempo=2[a0];[a0][am]amix[ao];[a2]asetrate=98000,atempo=0.5,adelay=16000|16000|16000[a22];[ao][a22]amix[o1];[o1]asetnsamples=1024"; /* passthrough (dummy) filter for audio */
         ret = init_filter(&filter_ctx[i], stream_ctx[i].dec_ctx,
                 stream_ctx[i].enc_ctx, filter_spec);
         if (ret)
StevenLiu:dash StevenLiu$

主要用到了如下几个滤镜:

  1. adelay 设置音频起始时间
  2. asetrate 设置音频采样率
  3. atempo 设置音频播放速度
  4. amix 合并音频
  5. asetnsamples 设置采样数

作者:悟空 ;公众号:流媒体技术

版权声明:本文内容转自互联网,本文观点仅代表作者本人。本站仅提供信息存储空间服务,所有权归原作者所有。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至1393616908@qq.com 举报,一经查实,本站将立刻删除。

(0)

相关推荐

发表回复

登录后才能评论