FFmpeg audio fade-out not applied when generating video with image sequence + mp3 (audio cuts abruptly) [closed]

1 day ago 1
ARTICLE AD BOX

I’m generating a video in Android using FFmpeg (via FFmpegKit). The video is created from an image sequence, a GIF overlay and an MP3 audio file.

The problem: the audio always ends abruptly.
I’m trying to apply a fade-out to the audio, but the fade does not seem to be applied — it still cuts suddenly when the audio ends.

The audio duration is always 30 seconds.
The video duration may vary, but in this case it’s also 30 seconds.

This is the exact FFmpeg command being generated by my app:

ffmpeg -y -r 7 -i \ /data/user/0/com.xxx.xxx/files/Pensamiento8163_%04d.jpg \ -ignore_loop 0 \ -i /data/user/0/com.xxx.xxx/files/anim00.gif \ -i /data/user/0/com.xxx.xxx/files/Pensamiento8163.mp3 \ -filter_complex "[0]scale=720:1280[ovrl0],[1]scale=681:973[ovrl1],[ovrl0][ovrl1]overlay=19:28[v]; \[2:a]afade=t=in:st=0:d=2,afade=t=out:st=25:d=5,apad[a]" \ -map [v] \ -map [a] \ -t 00:00:30 \ -c:v mpeg4 \ -c:a aac \ -pix_fmt yuv420p \ /data/user/0/com.xxx.xxx/files/Pensamiento8163.mp4

What this command does:

Uses an image sequence as background

Overlays a GIF animation

Adds MP3 audio

Applies fade-in and fade-out

Pads audio with apad

Exports MP4 with AAC audio

Expected behavior:
The audio should fade out smoothly during the last 5 seconds.

Actual behavior:
The audio still cuts abruptly at the end, as if the fade-out is not being applied.

Questions:

Why would afade=t=out not be applied in this scenario?

Is there something wrong with using apad together with afade?

Should the audio be processed in a separate FFmpeg step before muxing into the video?

Is there a better way to guarantee a smooth fade-out when the audio duration is fixed (30s) but video duration may vary?

Any help understanding why the fade-out is not applied would be greatly appreciated.

Read Entire Article