Mehmed
Mehmed

Reputation: 9

ffmpeg overlay voice on a song with fade in and fade out

I have a fade in and fade out problem and used below code, but not completely resolve. I have a voice as voice.mp3 name with voice_length seconds length and a song that biggest from voice. I want mix with song from start_mix_time time. When voice start volume should be 0.2 and when voice end, volume return to 1.0.

For example, if i have a voice by 10 s length and a song, song start playing and at position 3 s, starting to fade out to vol 0.2 and then, at 5 s, voice start over song and after 10 seconds, song fade in to vol 1 and play to end.

Here is a sample :

ffmpeg -i song1.mp3 -i voice2.mp3  -filter_complex "[0]asplit[a][b]; \
        [a]atrim=duration=voice_length,volume='1-max(0.25*(t-start_mix_time-2),0)':eval=frame[pre]; \
        [b]atrim=start=start_mix_time,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

@Mulvya

Upvotes: 0

Views: 780

Answers (2)

Mehmed
Mehmed

Reputation: 9

Finally, solved parametric by this :

ffmpeg -i song.mp3 -i voice.mp3  -filter_complex \
    "[0]volume='1-((t-start_song_fade_out)*fade_power) + min_song_volume':eval=frame:enable='between(t,start_song_fade_out,end_song_fade_out)', \
    volume=min_song_volume:eval=frame:enable='between(t,end_song_fade_out,end_song_fade_out + voice_duration - 1)', \
    volume='(t-end_song_fade_out + voice_duration - 1)*fade_power + min_song_volume' \
    :eval=frame:enable='between(t,end_song_fade_out + voice_duration - 1,start_song_fade_in_back + end_song_fade_out-start_song_fade_out)' \
    [song]; [1]adelay='(end_song_fade_out*1000)'|'(end_song_fade_out*1000)'[vo]; \
    [song][vo]amix=inputs=2:duration=first:dropout_transition=0.01" -id3v2_version 3 output.mp3

Upvotes: 0

Gyan
Gyan

Reputation: 93261

For the example given - volume fades from 1 to 0.2 between t=3 & 5 and then fades back to 1 from t=15 to 17.

ffmpeg -i song.mp3 -i voice.mp3  -filter_complex 
        "[0]volume='1-max((t-start_fade_t)*0.8/2,0)':eval=frame:enable='between(t,3,5)',volume=0.4:eval=frame:enable='between(t,5,15)',volume='0.2+max((t-end_fade_t)*0.8/2,0)':eval=frame:enable='between(t,15,17)'[song]; \
         [1]adelay=5000|5000[vo]; \
         [song][vo]amix=inputs=2:duration=first:dropout_transition=0.01" \
       output.mp3

Three volume filters are applied to the song - one for fade-in, one for fade-out and one during the overlay. Since the amix filter reduces the volume of its inputs, the overlay volume filter value is set to double the desired volume.

Upvotes: 0

Related Questions