Opened 5 years ago

Closed 5 years ago

#543 closed defect (fixed)

FLV MP3 durations incur round-off error

Reported by: gbooker Owned by:
Priority: normal Milestone:
Component: Perian-Main Version: 1.2
Severity: normal Keywords:


Originally reported on forums: with file from:

Video and audio durations do not match within Perian. Video is 10:20 and audio is 9:53. In closer examination, I noticed that the av_read_frame returns a packet with a duration of 25 in a timescale of 1/1000. For MP3, this is always 26, regardless of the timescale. It is computed as 25 since the frame size is 209, the bitrate is 65536, and the sample rate is 22050 making the duration in the timescale = 209 * 1000 * 8 / 65536 = 25.51, which when rounded produces the correct result. FFmpeg does not compute it this way, but instead computes the decoded sample size of 209 * 22050 * 8 / 65536 = 562.55 which is rounded down to 562. This is then converted to time by dividing by the sample rate (in the track's timescale) resulting in 562 * 1000 / 22050 = 25.48 which is rounded down to 25, and thus the error.

This is caused by round-offs in two locations causing the incorrect value and the fact that 209 bytes per sample is not strictly 65536 bit/sec as stated by the FLV header but rather 64307. Marking FLV MP3 timestamps as untrusted in Perian solves this:

Attachments (1)

flvmp3.diff (603 bytes) - added by gbooker 5 years ago.
Patch to not trust flv timestamps

Download all attachments as: .zip

Change History (2)

Changed 5 years ago by gbooker

Patch to not trust flv timestamps

comment:1 Changed 5 years ago by gbooker

  • Resolution set to fixed
  • Status changed from new to closed

(In [1383]) Don't trust audio durations in FLV.
Fixes #543

Note: See TracTickets for help on using tickets.