mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-21 21:30:24 +08:00
avformat/cafdec: take into account priming samples in timestamps
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -263,6 +263,7 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size)
|
||||
priming = avio_rb32(pb); /* priming frames */
|
||||
caf->remainder = avio_rb32(pb); /* remainder frames */
|
||||
|
||||
caf->frame_cnt = -(int64_t)priming;
|
||||
st->codecpar->initial_padding = priming;
|
||||
st->nb_frames += priming;
|
||||
st->nb_frames += caf->remainder;
|
||||
@@ -273,10 +274,10 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size)
|
||||
return AVERROR_INVALIDDATA;
|
||||
num_packets = caf->data_size / caf->bytes_per_packet;
|
||||
}
|
||||
st->duration = caf->frames_per_packet * num_packets;
|
||||
st->duration = caf->frames_per_packet * num_packets - priming;
|
||||
pos = caf-> bytes_per_packet * num_packets;
|
||||
} else {
|
||||
st->duration = 0;
|
||||
st->duration = caf->frame_cnt;
|
||||
for (i = 0; i < num_packets; i++) {
|
||||
if (avio_feof(pb))
|
||||
return AVERROR_INVALIDDATA;
|
||||
@@ -455,7 +456,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
FFStream *const sti = ffstream(st);
|
||||
CafContext *caf = s->priv_data;
|
||||
int res, pkt_size = 0, pkt_frames = 0;
|
||||
unsigned remainder = 0;
|
||||
unsigned priming = 0, remainder = 0;
|
||||
int64_t left = CAF_MAX_PKT_SIZE;
|
||||
|
||||
if (avio_feof(pb))
|
||||
@@ -500,13 +501,18 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
if (remainder > 0) {
|
||||
if (!caf->packet_cnt)
|
||||
priming = st->codecpar->initial_padding;
|
||||
|
||||
if (priming > 0 || remainder > 0) {
|
||||
uint8_t* side_data = av_packet_new_side_data(pkt,
|
||||
AV_PKT_DATA_SKIP_SAMPLES,
|
||||
10);
|
||||
if (!side_data)
|
||||
return AVERROR(ENOMEM);
|
||||
AV_WL32(side_data + 4, caf->remainder);
|
||||
|
||||
AV_WL32A(side_data, priming);
|
||||
AV_WL32A(side_data + 4, remainder);
|
||||
}
|
||||
|
||||
pkt->duration = pkt_frames;
|
||||
@@ -536,7 +542,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
|
||||
if (caf->data_size > 0)
|
||||
pos = FFMIN(pos, caf->data_size);
|
||||
packet_cnt = pos / caf->bytes_per_packet;
|
||||
frame_cnt = caf->frames_per_packet * packet_cnt;
|
||||
frame_cnt = caf->frames_per_packet * packet_cnt - st->codecpar->initial_padding;
|
||||
} else if (sti->nb_index_entries) {
|
||||
packet_cnt = av_index_search_timestamp(st, timestamp, flags);
|
||||
frame_cnt = sti->index_entries[packet_cnt].timestamp;
|
||||
|
||||
Reference in New Issue
Block a user