Opened 5 months ago

Last modified 2 months ago

#10465 new defect

The latest versions of ffmpeg (>=5.x) produces not playable on Apple devices .caf files

Reported by: Sergey Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: opus caf ios macos
Cc: Sergey Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Source file contains opus audio stream inside, and it's playable on iOs and Mac OS.
But if do

% ffmpeg -y -i playable.caf -c:a copy converted.caf

(i.e. I just trying to duplicate content of audio stream to another file) I get not playable .caf file.

After some investigation I found result file has mFramesPerPacket (from struct CAFAudioFormat: different from 960 (comparing to playable.caf). If I change that piece of file to 960 - both iOs and Mac OS starts play this file without any issue.

After further investigation I found problem is on

packet_size = st->duration / (caf->packets - 1);

And if I replace that line to

packet_size = st->duration / caf->packets;

it fixes output file, but I'm not sure if it's right fix.

Attachments (2)

playable.caf (5.9 KB ) - added by Sergey 5 months ago.
0001-avformat-cafenc-fixed-packet_size-calculation.patch (1.8 KB ) - added by Sergey 2 months ago.
possible issue fix

Download all attachments as: .zip

Change History (6)

by Sergey, 5 months ago

Attachment: playable.caf added

comment:2 by Sergey, 5 months ago

Version: 5.0.3git-master

comment:3 by Sergey, 2 months ago

I think I've found the reason. And it's very simple, even if audio stream has constant packet_size for all containing packets, it's almost always the last one is incomplete (i.e. less than packet_size) since there is no enough audio data to fill it completely, and it leads to wrong calculations. And it's possible using of (caf->packets - 1) in packet_size calculations was try to fix it. But for complete fix it's required to subtract duration of the last (incomplete) packet from full audio stream duration.

Also, maybe, it worth put calculation of duration directly to cafenc.c (if be more specific into caf_write_packet function) - it will give more control over calculations.

Anyway, I'm going to prepare patch for this issue...

Last edited 2 months ago by Sergey (previous) (diff)

by Sergey, 2 months ago

possible issue fix

comment:4 by Sergey, 2 months ago

I've provided possible issue fix, but it's highly possible it's too naive (or just totally wrong), since I'm not very familiar with ffmpeg internals. So I will be very glad to any comment or critique.

Thanks in advance.

Note: See TracTickets for help on using tickets.