History

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.

Gyan Doshi committed 3 years ago

Commit 01f46f11 parent 2524d0b2 files · +17 −2Browse files

Showing the changes to libavformat (1 of 2 files). Show all

Unified · Split

libavformat/segment.c+15−0
@@ -116,6 +116,7 @@ typedef struct SegmentContext { · 115 unmodified lines
116 int64_t initial_offset; ///< initial timestamps offset, expressed in microseconds116 int64_t initial_offset; ///< initial timestamps offset, expressed in microseconds
117 char *reference_stream_specifier; ///< reference stream specifier117 char *reference_stream_specifier; ///< reference stream specifier
118 int reference_stream_index;118 int reference_stream_index;
119 int64_t reference_stream_first_pts; ///< initial timestamp, expressed in microseconds
119 int break_non_keyframes;120 int break_non_keyframes;
120 int write_empty;121 int write_empty;
121 122
@@ -746,6 +747,8 @@ static int seg_init(AVFormatContext *s) · 624 unmodified lines
746 seg->reference_stream_index,747 seg->reference_stream_index,
747 av_get_media_type_string(s->streams[seg->reference_stream_index]->codecpar->codec_type));748 av_get_media_type_string(s->streams[seg->reference_stream_index]->codecpar->codec_type));
748 749
750 seg->reference_stream_first_pts = AV_NOPTS_VALUE;
751
749 seg->oformat = av_guess_format(seg->format, s->url, NULL);752 seg->oformat = av_guess_format(seg->format, s->url, NULL);
750 753
751 if (!seg->oformat)754 if (!seg->oformat)
@@ -898,6 +901,18 @@ calc_times: · 146 unmodified lines
898 pkt->flags & AV_PKT_FLAG_KEY,901 pkt->flags & AV_PKT_FLAG_KEY,
899 pkt->stream_index == seg->reference_stream_index ? seg->frame_count : -1);902 pkt->stream_index == seg->reference_stream_index ? seg->frame_count : -1);
900 903
904 if (seg->reference_stream_first_pts == AV_NOPTS_VALUE &&
905 pkt->stream_index == seg->reference_stream_index &&
906 pkt->pts != AV_NOPTS_VALUE) {
907 seg->reference_stream_first_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
908 }
909
910 if (seg->reference_stream_first_pts != AV_NOPTS_VALUE) {
911 end_pts += (INT64_MAX - end_pts >= seg->reference_stream_first_pts) ?
912 seg->reference_stream_first_pts :
913 INT64_MAX - end_pts;
914 }
915
901 if (pkt->pts != AV_NOPTS_VALUE)916 if (pkt->pts != AV_NOPTS_VALUE)
902 pkt_pts_avtb = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);917 pkt_pts_avtb = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
903 918

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t