From c68f092dfa82d5ee2a5e22e9ccf3e25ae5e8f771 Mon Sep 17 00:00:00 2001
From: sergey radionov <rsatom@gmail.com>
Date: Tue, 10 Oct 2023 15:48:18 +0700
Subject: [PATCH] avformat/cafenc: fixed packet_size calculation
the problem is the very last packet
can be shorter than default packet_size
so it's required to exclude it from
packet_size calculations
---
libavformat/cafenc.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
index 67be59806c..fcc4838392 100644
|
a
|
b
|
typedef struct {
|
| 34 | 34 | int size_buffer_size; |
| 35 | 35 | int size_entries_used; |
| 36 | 36 | int packets; |
| | 37 | int64_t duration; |
| | 38 | int64_t last_packet_duration; |
| 37 | 39 | } CAFContext; |
| 38 | 40 | |
| 39 | 41 | static uint32_t codec_flags(enum AVCodecID codec_id) { |
| … |
… |
static int caf_write_packet(AVFormatContext *s, AVPacket *pkt)
|
| 238 | 240 | pkt_sizes[caf->size_entries_used++] = 128 | top; |
| 239 | 241 | } |
| 240 | 242 | pkt_sizes[caf->size_entries_used++] = pkt->size & 127; |
| | 243 | caf->duration += pkt->duration; |
| | 244 | caf->last_packet_duration = pkt->duration; |
| 241 | 245 | caf->packets++; |
| 242 | 246 | } |
| 243 | 247 | avio_write(s->pb, pkt->data, pkt->size); |
| … |
… |
static int caf_write_trailer(AVFormatContext *s)
|
| 259 | 263 | if (!par->block_align) { |
| 260 | 264 | int packet_size = samples_per_packet(par); |
| 261 | 265 | if (!packet_size) { |
| 262 | | packet_size = st->duration / (caf->packets - 1); |
| | 266 | if (caf->duration) { |
| | 267 | packet_size = (caf->duration - caf->last_packet_duration) / (caf->packets - 1); |
| | 268 | } else { |
| | 269 | packet_size = st->duration / (caf->packets - 1); |
| | 270 | } |
| 263 | 271 | avio_seek(pb, FRAME_SIZE_OFFSET, SEEK_SET); |
| 264 | 272 | avio_wb32(pb, packet_size); |
| 265 | 273 | } |