mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-06 15:49:50 +08:00
avformat/segment: calculate segment durations correctly.
segment_time and segment_times are defined as duration specifications, not timestamps, so calculation of segment duration must account for initial timestamp. Fixed. FATE ref for segment-mp4-to-ts changed on account of avoiding premature segment cut at the end of the first segment.
This commit is contained in:
@ -116,6 +116,7 @@ typedef struct SegmentContext {
|
||||
int64_t initial_offset; ///< initial timestamps offset, expressed in microseconds
|
||||
char *reference_stream_specifier; ///< reference stream specifier
|
||||
int reference_stream_index;
|
||||
int64_t reference_stream_first_pts; ///< initial timestamp, expressed in microseconds
|
||||
int break_non_keyframes;
|
||||
int write_empty;
|
||||
|
||||
@ -746,6 +747,8 @@ static int seg_init(AVFormatContext *s)
|
||||
seg->reference_stream_index,
|
||||
av_get_media_type_string(s->streams[seg->reference_stream_index]->codecpar->codec_type));
|
||||
|
||||
seg->reference_stream_first_pts = AV_NOPTS_VALUE;
|
||||
|
||||
seg->oformat = av_guess_format(seg->format, s->url, NULL);
|
||||
|
||||
if (!seg->oformat)
|
||||
@ -898,6 +901,18 @@ calc_times:
|
||||
pkt->flags & AV_PKT_FLAG_KEY,
|
||||
pkt->stream_index == seg->reference_stream_index ? seg->frame_count : -1);
|
||||
|
||||
if (seg->reference_stream_first_pts == AV_NOPTS_VALUE &&
|
||||
pkt->stream_index == seg->reference_stream_index &&
|
||||
pkt->pts != AV_NOPTS_VALUE) {
|
||||
seg->reference_stream_first_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
|
||||
}
|
||||
|
||||
if (seg->reference_stream_first_pts != AV_NOPTS_VALUE) {
|
||||
end_pts += (INT64_MAX - end_pts >= seg->reference_stream_first_pts) ?
|
||||
seg->reference_stream_first_pts :
|
||||
INT64_MAX - end_pts;
|
||||
}
|
||||
|
||||
if (pkt->pts != AV_NOPTS_VALUE)
|
||||
pkt_pts_avtb = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
|
||||
|
||||
|
Reference in New Issue
Block a user