ffmpeg使用amix和adelay通过歌曲播放广告 [英] ffmpeg use amix and adelay to play ad over song

查看:56
本文介绍了ffmpeg使用amix和adelay通过歌曲播放广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个mp3文件,一个长而一个短(一首歌和一则广告).我需要从歌曲开始播放15秒钟开始播放广告的广告.在广告前后,我还需要歌曲的音量逐渐淡入/淡出.我尝试过将adelay与amix一起使用,但无法正确完成.

I have two mp3 files, one long and one short(a song and an ad). I need the ad to play over the song starting 15 seconds into the song. I also need the volume of the song to fade out/in slightly before and after the ad. I have tried using amix with adelay but just can't get it right.

有些东西很近但是很破损.

here is something close but broken.

ffmpeg -i song.mp3 -i ad.mp3 -filter_complex "amix=inputs=2:duration=first:dropout_transition=2;adelay=0|15000" output.mp3

如何使广告与歌曲正确混合?

How can I get the ad to mix with the song properly?

推荐答案

由于您希望歌曲在广告出现之前淡出一点,因此预先分割歌曲会更方便.

Since you wish the song to fade-out a bit before the ad appears, it's more convenient to split the song beforehand.

ffmpeg -i song.mp3 -i ad.mp3 \
       -filter_complex "[0]asplit[a][b]; \
                        [a]atrim=duration=15,volume='1-max(0.25*(t-13),0)':eval=frame[pre]; \
                        [b]atrim=start=15,asetpts=PTS-STARTPTS[song]; \
                        [song][1]amix=inputs=2:duration=first:dropout_transition=2[post]; \
                        [pre][post]concat=n=2:v=0:a=1[mixed]" \
       -map "[mixed]" output.mp3

音量表达式 1-max(0.25 *(t-13),0)从13秒开始以每秒25%的速度减小音量,因此当混合开始.由于您不知道混音过滤器会在与广告混合时降低多少歌曲的音量,因此如果结果不可接受,您将不得不尝试使用速率因子 0.25 .

The volume expression 1-max(0.25*(t-13),0) reduces volume at the rate of 25% per second starting at 13 seconds, so the volume is reduced to half when the mix starts. Since you don't know how much the amix filter will reduce the song's volume when mixed with the ad, you will have to experiment with the rate factor 0.25 if the result's not acceptable.

这篇关于ffmpeg使用amix和adelay通过歌曲播放广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆