[FFmpeg-user] current ffmpeg creates shortened audio stream when filter amix

Moritz Barsnick barsnick at gmx.net
Mon Sep 30 16:30:55 EEST 2019


On Sun, Sep 29, 2019 at 10:38:33 +0200, Paul B Mahol wrote:
> On 9/29/19, S Andreason <sandreas41 at gmail.com> wrote:
> > I am getting a shortened audio stream when including the audio filters
> > aresample and amix, which later makes it impossible to concat the clips,
> > because the different stream lengths lose sync between audio and video,
> > with errors:
> > Invalid audio PTS
> There are numerous issues with your report. First how is this
> supposed to work at all if one use two filter-complex at once? Second
> amix gets only one input in your command, and with no options given
> it accepts actually two inputs.

While I wanted to agree with this, ffmpeg seems to disagree:

> > $ ffmpeg -i 20190922_1532_3Kf-pan-right_3969_c2t14.MOV -i Voice_20190922-1315_voiceOverForEMR-outroClip_c108t8.m4a -filter_complex "[0]crop=x=128:y=0:w=1024:h=720,pad=1024:768:0:24,drawtext='fontsize=32:fontcolor=0xa73450:bordercolor=white:shadowcolor=black:fontfile=/usr/share/fonts/TrueType/SF-Foxboro-Script-Bold.ttf:x=(w-text_w-20):y=(h-text_h-36):shadowx=2:shadowy=2:borderw=1:text=seahorseCorral.org'" -filter_complex "aresample=48000,amix" -s 1024x768 -c:v h264 -b:v 4700k -r 30 20190922_1532_ch5.1e-g.mov
[...]
> > Stream mapping:
> >    Stream #0:0 (h264) -> crop (graph 0)
> >    Stream #0:1 (pcm_s16le) -> aresample (graph 1)
> >    Stream #1:0 (aac) -> amix:input1 (graph 1)
> >    drawtext (graph 0) -> Stream #0:0 (libx264)
> >    amix (graph 1) -> Stream #0:1 (aac)

Obviously, both filter_complex expressions are taken into
consideration, and amix seems to be able to grab two inputs.

OTOH, this is probably not what Stewart desired. 0:1 is being
aresample'd, and then amix'd with 1:0 (which is still at 44100). That
is bound to be undefined behavior(?).

Suggestion:
  -filter_complex "[0:v]crop=x=128:y=0:w=1024:h=720,pad=1024:768:0:24,drawtext='fontsize=32:fontcolor=0xa73450:bordercolor=white:shadowcolor=black:fontfile=/usr/share/fonts/TrueType/SF-Foxboro-Script-Bold.ttf:x=(w-text_w-20):y=(h-text_h-36):shadowx=2:shadowy=2:borderw=1:text=seahorseCorral.org'[v]; [1:a]aresample=48000[a1]; [0:a][a1]amix[a]" -map "[v]" -map "[a]"

I'm not saying this will fix the observed issue (as Stewart mentioned
he tried resampling externally), but it will make the behavior more
well-defined.

Stewart, it helps if you leave away the parts of the video filter which
aren't relevant to the issue (assuming you tried leaving them away on
your side first), to make the command line easier to read.

Also, it helps to explictly mark inputs and outputs in the
filter_complex chains, to make sure they do what you intend them to do.
(Implicit is for heros. I'm not one of them. ;-))

Cheers,
Moritz


More information about the ffmpeg-user mailing list