[FFmpeg-devel] [PATCH] cafenc: fill in avg. packet size later if unknown
Lynne
dev at lynne.ee
Mon Jul 12 10:58:25 EEST 2021
10 Jul 2021, 09:42 by dev at lynne.ee:
> 10 Jul 2021, 03:10 by roman.beranek at prusa3d.cz:
>
>> Frame size of Opus stream was previously presumed here to be 960 samples
>> (20ms), however sizes of 120, 240, 480, 1920, and 2880 are also allowed.
>> It can also alter on a per-packet basis and even multiple frames may be
>> present in a single packet according to the specification, for the sake
>> of simplicity however, let us assume that this doesn't occur.
>>
>
> Actually 120ms frames are the maximum, so 5760 samples, but that's
> irrelevant to the patch.
>
>
>> if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
>> int64_t file_size = avio_tell(pb);
>>
>> avio_seek(pb, caf->data, SEEK_SET);
>> avio_wb64(pb, file_size - caf->data - 8);
>> - avio_seek(pb, file_size, SEEK_SET);
>> if (!par->block_align) {
>> + int packet_size = samples_per_packet(par->codec_id, par->channels, par->block_align);
>> + if (!packet_size) {
>> + packet_size = st->duration / (caf->packets - 1);
>> + avio_seek(pb, FRAME_SIZE_OFFSET, SEEK_SET);
>> + avio_wb32(pb, packet_size);
>> + }
>> + avio_seek(pb, file_size, SEEK_SET);
>> ffio_wfourcc(pb, "pakt");
>> avio_wb64(pb, caf->size_entries_used + 24);
>> avio_wb64(pb, caf->packets); ///< mNumberPackets
>> - avio_wb64(pb, caf->packets * samples_per_packet(par->codec_id, par->channels, par->block_align)); ///< mNumberValidFrames
>> + avio_wb64(pb, caf->packets * packet_size); ///< mNumberValidFrames
>> avio_wb32(pb, 0); ///< mPrimingFrames
>> avio_wb32(pb, 0); ///< mRemainderFrames
>> avio_write(pb, caf->pkt_sizes, caf->size_entries_used);
>>
>
> This doesn't move the pointer back to the file end if par->block_align is set.
> I think that's fine though, since the function writes the trailer, which should
> mean that nothing more needs to be written.
> Patch LGTM. But please, someone yell at Apple to support Opus in MP4,
> WebM and OGG, as terrible as that is.
>
Patch pushed, thanks
More information about the ffmpeg-devel
mailing list