mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-10-24 02:09:03 +03:00
avformat/cafenc: support writing Packet Table Chunk Header if there are priming or remainder frames
If a codec has fixed block_align and frame_size but a given sample has either priming or remainder frames, a pakt chunk can be written declaring zero packets and no table, reporting only the samples to be discarded. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -263,10 +263,10 @@ static int caf_write_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
caf_st->frame_size_buffer = pkt_sizes;
|
||||
caf_st->frame_size_buffer[caf->packets] = pkt->duration;
|
||||
}
|
||||
|
||||
}
|
||||
caf->packets++;
|
||||
caf->total_duration += pkt->duration;
|
||||
}
|
||||
|
||||
avio_write(s->pb, pkt->data, pkt->size);
|
||||
return 0;
|
||||
}
|
||||
@@ -281,13 +281,15 @@ static int caf_write_trailer(AVFormatContext *s)
|
||||
|
||||
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);
|
||||
if (!par->block_align || !caf->frame_size) {
|
||||
int64_t packets = (!par->block_align || !caf->frame_size) ? caf->packets : 0;
|
||||
int64_t valid_frames = caf->frame_size ? caf->packets * caf->frame_size : caf->total_duration;
|
||||
unsigned remainder_frames = valid_frames > caf->total_duration
|
||||
? valid_frames - caf->total_duration : 0;
|
||||
|
||||
avio_seek(pb, caf->data, SEEK_SET);
|
||||
avio_wb64(pb, file_size - caf->data - 8);
|
||||
|
||||
if (!par->block_align || !caf->frame_size || par->initial_padding || remainder_frames) {
|
||||
int64_t size = 24;
|
||||
|
||||
valid_frames -= par->initial_padding;
|
||||
@@ -296,11 +298,11 @@ static int caf_write_trailer(AVFormatContext *s)
|
||||
avio_seek(pb, file_size, SEEK_SET);
|
||||
ffio_wfourcc(pb, "pakt");
|
||||
avio_wb64(pb, 0); // size, to be replaced
|
||||
avio_wb64(pb, caf->packets); ///< mNumberPackets
|
||||
avio_wb64(pb, packets); ///< mNumberPackets
|
||||
avio_wb64(pb, valid_frames); ///< mNumberValidFrames
|
||||
avio_wb32(pb, par->initial_padding); ///< mPrimingFrames
|
||||
avio_wb32(pb, remainder_frames); ///< mRemainderFrames
|
||||
for (int i = 0; i < caf->packets; i++) {
|
||||
for (int i = 0; i < packets; i++) {
|
||||
if (!par->block_align) {
|
||||
for (int j = 4; j > 0; j--) {
|
||||
unsigned top = caf_st->byte_size_buffer[i] >> j * 7;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
2b71d78aa6c9d13a3c0dbbbebe885227 *tests/data/fate/caf-qdm2-remux.caf
|
||||
51228 tests/data/fate/caf-qdm2-remux.caf
|
||||
fa896705e19dccfef00734f1e8f614c8 *tests/data/fate/caf-qdm2-remux.caf
|
||||
51264 tests/data/fate/caf-qdm2-remux.caf
|
||||
#extradata 0: 64, 0x10d20603
|
||||
#tb 0: 1/44100
|
||||
#media_type 0: audio
|
||||
|
||||
Reference in New Issue
Block a user