diff options
author | James Almer <jamrial@gmail.com> | 2024-11-20 14:40:29 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-11-22 20:50:05 -0300 |
commit | b328bf8f7ed6f7794bc69b8a6304390527a6216a (patch) | |
tree | da9c921fdb294cf28b45f2333bb60c577ea3735e /libavformat | |
parent | 0dceced45c52acc773e690a7aa7ff2e3fb8c560b (diff) | |
download | ffmpeg-b328bf8f7ed6f7794bc69b8a6304390527a6216a.tar.gz |
avformat/mov: rename MOVCtts.duration to offset
The value is a timestamp offset, not a duration.
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/isom.h | 2 | ||||
-rw-r--r-- | libavformat/mov.c | 29 | ||||
-rw-r--r-- | libavformat/movenc.c | 8 |
3 files changed, 20 insertions, 19 deletions
diff --git a/libavformat/isom.h b/libavformat/isom.h index 5aab5bad9b..ff08f2a48d 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -61,7 +61,7 @@ typedef struct MOVStts { typedef struct MOVCtts { unsigned int count; - int duration; + int offset; } MOVCtts; typedef struct MOVStsc { diff --git a/libavformat/mov.c b/libavformat/mov.c index 954ff657a9..3e94a21418 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3977,7 +3977,7 @@ static int find_prev_closest_index(AVStream *st, // Find a "key frame" with PTS <= timestamp_pts (So that we can decode B-frames correctly). // No need to add dts_shift to the timestamp here becase timestamp_pts has already been // compensated by dts_shift above. - if ((e_old[*index].timestamp + ctts_data[*ctts_index].duration) <= timestamp_pts && + if ((e_old[*index].timestamp + ctts_data[*ctts_index].offset) <= timestamp_pts && (e_old[*index].flags & AVINDEX_KEYFRAME)) { break; } @@ -4068,7 +4068,7 @@ static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_ * Returns the new ctts_count if successful, else returns -1. */ static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size, - int count, int duration) + int count, int offset) { MOVCtts *ctts_buf_new; const size_t min_size_needed = (*ctts_count + 1) * sizeof(MOVCtts); @@ -4088,7 +4088,7 @@ static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, uns *ctts_data = ctts_buf_new; ctts_buf_new[*ctts_count].count = count; - ctts_buf_new[*ctts_count].duration = duration; + ctts_buf_new[*ctts_count].offset = offset; *ctts_count = (*ctts_count) + 1; return *ctts_count; @@ -4118,7 +4118,7 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) if (buf_start == MAX_REORDER_DELAY + 1) buf_start = 0; - pts_buf[j] = sti->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; + pts_buf[j] = sti->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].offset; // The timestamps that are already in the sorted buffer, and are greater than the // current pts, are exactly the timestamps that need to be buffered to output PTS @@ -4347,7 +4347,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) curr_ctts = 0; if (ctts_data_old && ctts_index_old < ctts_count_old) { - curr_ctts = ctts_data_old[ctts_index_old].duration; + curr_ctts = ctts_data_old[ctts_index_old].offset; av_log(mov->fc, AV_LOG_TRACE, "stts: %"PRId64" ctts: %"PRId64", ctts_index: %"PRId64", ctts_count: %"PRId64"\n", curr_cts, curr_ctts, ctts_index_old, ctts_count_old); curr_cts += curr_ctts; @@ -4356,11 +4356,11 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count, &msc->ctts_allocated_size, ctts_data_old[ctts_index_old].count - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration) == -1) { + ctts_data_old[ctts_index_old].offset) == -1) { av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n", ctts_index_old, ctts_data_old[ctts_index_old].count - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration); + ctts_data_old[ctts_index_old].offset); break; } ctts_index_old++; @@ -4463,10 +4463,10 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count, &msc->ctts_allocated_size, ctts_sample_old - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration) == -1) { + ctts_data_old[ctts_index_old].offset) == -1) { av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n", ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration); + ctts_data_old[ctts_index_old].offset); break; } } @@ -4540,7 +4540,7 @@ static int build_open_gop_key_points(AVStream *st) k = 0; for (uint32_t i = 0; i < sc->ctts_count; i++) for (int j = 0; j < sc->ctts_data[i].count; j++) - sc->sample_offsets[k++] = sc->ctts_data[i].duration; + sc->sample_offsets[k++] = sc->ctts_data[i].offset; /* The following HEVC NAL type reveal the use of open GOP sync points * (TODO: BLA types may also be concerned) */ @@ -4693,7 +4693,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) sc->ctts_count < sc->sample_count; j++) add_ctts_entry(&sc->ctts_data, &sc->ctts_count, &sc->ctts_allocated_size, 1, - ctts_data_old[i].duration); + ctts_data_old[i].offset); av_free(ctts_data_old); } @@ -4900,7 +4900,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->nb_index_entries > 0) { st->start_time = sti->index_entries[0].timestamp + sc->dts_shift; if (sc->ctts_data) { - st->start_time += sc->ctts_data[0].duration; + st->start_time += sc->ctts_data[0].offset; } } @@ -5910,7 +5910,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sti->index_entries[index_entry_pos].flags = index_entry_flags; sc->ctts_data[index_entry_pos].count = 1; - sc->ctts_data[index_entry_pos].duration = ctts_duration; + sc->ctts_data[index_entry_pos].offset = ctts_duration; index_entry_pos++; av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " @@ -10721,7 +10721,8 @@ static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s pkt->flags |= AV_PKT_FLAG_DISCARD; } if (sc->ctts_data && sc->ctts_index < sc->ctts_count) { - pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration)); + pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].offset)); + /* update ctts context */ sc->ctts_sample++; if (sc->ctts_index < sc->ctts_count && diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 0595c4ce82..1488c173a7 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -3007,13 +3007,13 @@ static int mov_write_ctts_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra if (!ctts_entries) return AVERROR(ENOMEM); ctts_entries[0].count = 1; - ctts_entries[0].duration = track->cluster[0].cts; + ctts_entries[0].offset = track->cluster[0].cts; for (i = 1; i < track->entry; i++) { - if (track->cluster[i].cts == ctts_entries[entries].duration) { + if (track->cluster[i].cts == ctts_entries[entries].offset) { ctts_entries[entries].count++; /* compress */ } else { entries++; - ctts_entries[entries].duration = track->cluster[i].cts; + ctts_entries[entries].offset = track->cluster[i].cts; ctts_entries[entries].count = 1; } } @@ -3029,7 +3029,7 @@ static int mov_write_ctts_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra avio_wb32(pb, entries); /* entry count */ for (i = 0; i < entries; i++) { avio_wb32(pb, ctts_entries[i].count); - avio_wb32(pb, ctts_entries[i].duration); + avio_wb32(pb, ctts_entries[i].offset); } av_free(ctts_entries); return atom_size; |