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.
Unified · Split
| @@ -116,6 +116,7 @@ typedef struct SegmentContext { · 115 unmodified lines | ||
| 116 | 116 | int64_t initial_offset; ///< initial timestamps offset, expressed in microseconds |
| 117 | 117 | char *reference_stream_specifier; ///< reference stream specifier |
| 118 | 118 | int reference_stream_index; |
| 119 | + int64_t reference_stream_first_pts; ///< initial timestamp, expressed in microseconds | |
| 119 | 120 | int break_non_keyframes; |
| 120 | 121 | int write_empty; |
| 121 | 122 | |
| @@ -746,6 +747,8 @@ static int seg_init(AVFormatContext *s) · 624 unmodified lines | ||
| 746 | 747 | seg->reference_stream_index, |
| 747 | 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 | 752 | seg->oformat = av_guess_format(seg->format, s->url, NULL); |
| 750 | 753 | |
| 751 | 754 | if (!seg->oformat) |
| @@ -898,6 +901,18 @@ calc_times: · 146 unmodified lines | ||
| 898 | 901 | pkt->flags & AV_PKT_FLAG_KEY, |
| 899 | 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 | 916 | if (pkt->pts != AV_NOPTS_VALUE) |
| 902 | 917 | pkt_pts_avtb = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q); |
| 903 | 918 | |
| @@ -23,7 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | 0, 50400, 54000, 3600, 607, 0xc53c2339, F=0x0, S=1, 1 |
| 24 | 24 | 0, 54000, 72000, 3600, 4755, 0x2f642b58, F=0x0, S=1, 1 |
| 25 | 25 | 0, 57600, 64800, 3600, 1182, 0xbe1a4847, F=0x0, S=1, 1 |
| 26 | −0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x2, S=1, 1 | |
| 26 | +0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x0, S=1, 1 | |
| 27 | 27 | 0, 64800, 68400, 3600, 656, 0x4fa03c2b, F=0x0, S=1, 1 |
| 28 | 28 | 0, 68400, 86400, 3600, 26555, 0x5629b584, S=1, 1 |
| 29 | 29 | 0, 72000, 79200, 3600, 1141, 0x761b31e8, F=0x0, S=1, 1 |
| @@ -71,7 +71,7 @@ · 41 unmodified lines | ||
| 71 | 71 | 0, 223200, 226800, 3600, 809, 0x84e37fee, F=0x0, S=1, 1 |
| 72 | 72 | 0, 226800, 244800, 3600, 4541, 0xd4e5c0de, F=0x0, S=1, 1 |
| 73 | 73 | 0, 230400, 237600, 3600, 1545, 0x0099fc98, F=0x0, S=1, 1 |
| 74 | −0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x0, S=1, 1 | |
| 74 | +0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x2, S=1, 1 | |
| 75 | 75 | 0, 237600, 241200, 3600, 829, 0xcfda9e96, F=0x0, S=1, 1 |
| 76 | 76 | 0, 241200, 259200, 3600, 24220, 0x5ca21d71, S=1, 1 |
| 77 | 77 | 0, 244800, 252000, 3600, 1422, 0xcde6cc34, F=0x0, S=1, 1 |