[FFmpeg-user] trimmed audio has wrong duration

Moritz Barsnick barsnick at gmx.net
Thu Oct 10 20:55:51 EEST 2019


On Thu, Oct 10, 2019 at 19:45:41 +0200, FFmpeg user discussions wrote:
> But it is strange anyway:
>
> _ffmpeg.exe -i _audio.flac -t 10 -codec copy _audio_2.flac
> —> it shows me 9.98
> _ffmpeg.exe -i audio_2.flac -f null -
> —> but encode is 10.08
>
> _ffmpeg.exe -i _audio.flac -t 20 -codec copy _audio_2.flac
> —> it shows me 19.96
> _ffmpeg.exe -i audio_2.flac -f null -
> —> but encode is 20.06
>
> And so on ...
>
> But:
> _ffmpeg.exe -i _audio.flac -t 10 -codec flac _audio_2.flac
> —> 10.00
> Always accurate.

With stream copy, ffmpeg will (I guess) cut at nearest audio packet
borders. When re-encoding, it can cut at the exact sample.

Considering that FLAV packets usually contain a lot of samples (I
believe I saw some ffmpeg default of 4096 samples per packet?), the
packet's size will obviously determine the possible precision.

This happens with ther codecs as well, I have experienced it quite
often.

(I don't know why encode and decode have a different opinion regarding
the length, though.)

Cheers,
Moritz


More information about the ffmpeg-user mailing list