Opened 3 years ago
Last modified 2 years ago
#10465 open 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 |
Description
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: https://developer.apple.com/library/archive/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html) 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 https://github.com/FFmpeg/FFmpeg/blob/75b1a555a70c178a9166629e43ec2f6250219eb2/libavformat/cafenc.c#L262
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)
Change History (11)
by , 3 years ago
| Attachment: | playable.caf added |
|---|
comment:1 by , 3 years ago
comment:2 by , 3 years ago
| Version: | 5.0.3 → git-master |
|---|
comment:3 by , 3 years 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...
by , 3 years ago
| Attachment: | 0001-avformat-cafenc-fixed-packet_size-calculation.patch added |
|---|
possible issue fix
comment:4 by , 3 years 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.
comment:5 by , 2 years ago
| Cc: | removed |
|---|
comment:6 by , 2 years ago
| Cc: | added |
|---|
comment:7 by , 2 years ago
@mkver do you know by chance who can review patches to this part of ffmpeg?
comment:8 by , 2 years ago
| Owner: | set to |
|---|---|
| Status: | new → open |
comment:9 by , 2 years ago
| Owner: | removed |
|---|



related issue: https://trac.ffmpeg.org/ticket/9930