[FFmpeg-user] amix with atempo: Inconsistent behaviour creating m4a with aac

Jonathan Girven jonathan.girven at trickbook.com
Wed Sep 13 13:40:53 EEST 2017


> I would expect output.m4a to be 25 seconds long: 5 seconds normal playback,
> 10 seconds atempo=0.5, 10 seconds normal. Instead it is 15 seconds long and
> doesn't contain the last 10 seconds of normal playback.

I have experimented with some alternatives to achieve the same goal.
If I do the above process in two stages, first merge the audio tracks,
output to an intermediate file, then apply atempo to the intermediate,
e.g:

$ ffmpeg -y \
  -i BigBuckBunny_320x180_t10.mp4 \
  -i BigBuckBunny_320x180_t10.mp4 \
  -filter_complex "
aevalsrc=0:d=10[na1];
[na1][1:a]concat=n=2:v=0:a=1[a1];
[0:a][a1]amix=inputs=2[mix_audio]
" \
  -map [mix_audio] \
  -c:a aac \
  intermediate.m4a

$ ffmpeg -y \
  -i intermediate.m4a \
  -filter_complex "
[0:a]asplit=3[a0][a1][a2];
[a0]atrim=0:5,asetpts=expr=PTS-STARTPTS[a_trim0];
[a1]atrim=5:10,asetpts=expr=PTS-STARTPTS[a_trim1];
[a2]atrim=10:20,asetpts=expr=PTS-STARTPTS[a_trim2];
[a_trim1]atempo=0.5[a_slomo1];
[a_trim0][a_slomo1][a_trim2]concat=n=3:v=0:a=1[com_a_slomo]
" \
  -map [com_a_slomo] \
  -c:a aac \
  output.m4a

This works as expected.

Also, if I instead do the merge in one stage, but first ensure that
both audio tracks are the same length as the final output by appending
silent audio to the end of [0:a]:

ffmpeg -y \
  -i BigBuckBunny_320x180_t10.mp4 \
  -i BigBuckBunny_320x180_t10.mp4 \
  -filter_complex "
aevalsrc=0:d=10[na0];[0:a][na0]concat=n=2:v=0:a=1[a0];
aevalsrc=0:d=10[na1];[na1][1:a]concat=n=2:v=0:a=1[a1];
[a0][a1]amix=inputs=2[mix_audio];
[mix_audio]asplit=3[mix_audio0][mix_audio1][mix_audio2];
[mix_audio0]atrim=0:5,asetpts=expr=PTS-STARTPTS[a_trim0];
[mix_audio1]atrim=5:10,asetpts=expr=PTS-STARTPTS[a_trim1];
[mix_audio2]atrim=10:20,asetpts=expr=PTS-STARTPTS[a_trim2];
[a_trim1]atempo=0.5[a_slomo1];
[a_trim0][a_slomo1][a_trim2]concat=n=3:v=0:a=1[com_a_slomo]
" \
  -map [com_a_slomo] \
  -c:a aac \
  output.m4a

This works as expected too. Therefore, I wonder if label [mix_audio]
in the original command does not have the correct length assigned or
something? Saving to an intermediate file enforces that 25 second
length, and so does appending silent audio to make both tracks the
full length.


More information about the ffmpeg-user mailing list