* [FFmpeg-devel] [PATCH v2] avformat/segment: calculate segment durations correctly.
@ 2023-01-07 12:07 Gyan Doshi
2023-01-12 5:59 ` Gyan Doshi
0 siblings, 1 reply; 4+ messages in thread
From: Gyan Doshi @ 2023-01-07 12:07 UTC (permalink / raw)
To: ffmpeg-devel
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.
---
libavformat/segment.c | 15 +++++++++++++++
tests/ref/fate/segment-mp4-to-ts | 4 ++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 0e6421ea5d..80e4bf851c 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -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);
diff --git a/tests/ref/fate/segment-mp4-to-ts b/tests/ref/fate/segment-mp4-to-ts
index 54fcadb846..2994416270 100644
--- a/tests/ref/fate/segment-mp4-to-ts
+++ b/tests/ref/fate/segment-mp4-to-ts
@@ -23,7 +23,7 @@
0, 50400, 54000, 3600, 607, 0xc53c2339, F=0x0, S=1, 1
0, 54000, 72000, 3600, 4755, 0x2f642b58, F=0x0, S=1, 1
0, 57600, 64800, 3600, 1182, 0xbe1a4847, F=0x0, S=1, 1
-0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x2, S=1, 1
+0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x0, S=1, 1
0, 64800, 68400, 3600, 656, 0x4fa03c2b, F=0x0, S=1, 1
0, 68400, 86400, 3600, 26555, 0x5629b584, S=1, 1
0, 72000, 79200, 3600, 1141, 0x761b31e8, F=0x0, S=1, 1
@@ -71,7 +71,7 @@
0, 223200, 226800, 3600, 809, 0x84e37fee, F=0x0, S=1, 1
0, 226800, 244800, 3600, 4541, 0xd4e5c0de, F=0x0, S=1, 1
0, 230400, 237600, 3600, 1545, 0x0099fc98, F=0x0, S=1, 1
-0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x0, S=1, 1
+0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x2, S=1, 1
0, 237600, 241200, 3600, 829, 0xcfda9e96, F=0x0, S=1, 1
0, 241200, 259200, 3600, 24220, 0x5ca21d71, S=1, 1
0, 244800, 252000, 3600, 1422, 0xcde6cc34, F=0x0, S=1, 1
--
2.36.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/segment: calculate segment durations correctly.
2023-01-07 12:07 [FFmpeg-devel] [PATCH v2] avformat/segment: calculate segment durations correctly Gyan Doshi
@ 2023-01-12 5:59 ` Gyan Doshi
2023-01-15 4:19 ` Gyan Doshi
0 siblings, 1 reply; 4+ messages in thread
From: Gyan Doshi @ 2023-01-12 5:59 UTC (permalink / raw)
To: ffmpeg-devel
On 2023-01-07 05:37 pm, Gyan Doshi wrote:
> 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.
Comments?
> ---
> libavformat/segment.c | 15 +++++++++++++++
> tests/ref/fate/segment-mp4-to-ts | 4 ++--
> 2 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 0e6421ea5d..80e4bf851c 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -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);
>
> diff --git a/tests/ref/fate/segment-mp4-to-ts b/tests/ref/fate/segment-mp4-to-ts
> index 54fcadb846..2994416270 100644
> --- a/tests/ref/fate/segment-mp4-to-ts
> +++ b/tests/ref/fate/segment-mp4-to-ts
> @@ -23,7 +23,7 @@
> 0, 50400, 54000, 3600, 607, 0xc53c2339, F=0x0, S=1, 1
> 0, 54000, 72000, 3600, 4755, 0x2f642b58, F=0x0, S=1, 1
> 0, 57600, 64800, 3600, 1182, 0xbe1a4847, F=0x0, S=1, 1
> -0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x2, S=1, 1
> +0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x0, S=1, 1
> 0, 64800, 68400, 3600, 656, 0x4fa03c2b, F=0x0, S=1, 1
> 0, 68400, 86400, 3600, 26555, 0x5629b584, S=1, 1
> 0, 72000, 79200, 3600, 1141, 0x761b31e8, F=0x0, S=1, 1
> @@ -71,7 +71,7 @@
> 0, 223200, 226800, 3600, 809, 0x84e37fee, F=0x0, S=1, 1
> 0, 226800, 244800, 3600, 4541, 0xd4e5c0de, F=0x0, S=1, 1
> 0, 230400, 237600, 3600, 1545, 0x0099fc98, F=0x0, S=1, 1
> -0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x0, S=1, 1
> +0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x2, S=1, 1
> 0, 237600, 241200, 3600, 829, 0xcfda9e96, F=0x0, S=1, 1
> 0, 241200, 259200, 3600, 24220, 0x5ca21d71, S=1, 1
> 0, 244800, 252000, 3600, 1422, 0xcde6cc34, F=0x0, S=1, 1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/segment: calculate segment durations correctly.
2023-01-12 5:59 ` Gyan Doshi
@ 2023-01-15 4:19 ` Gyan Doshi
2023-01-16 10:09 ` Gyan Doshi
0 siblings, 1 reply; 4+ messages in thread
From: Gyan Doshi @ 2023-01-15 4:19 UTC (permalink / raw)
To: ffmpeg-devel
On 2023-01-12 11:29 am, Gyan Doshi wrote:
>
>
> On 2023-01-07 05:37 pm, Gyan Doshi wrote:
>> 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.
>
> Comments?
Plan to push tomorrow.
>
>> ---
>> libavformat/segment.c | 15 +++++++++++++++
>> tests/ref/fate/segment-mp4-to-ts | 4 ++--
>> 2 files changed, 17 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>> index 0e6421ea5d..80e4bf851c 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -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);
>> diff --git a/tests/ref/fate/segment-mp4-to-ts
>> b/tests/ref/fate/segment-mp4-to-ts
>> index 54fcadb846..2994416270 100644
>> --- a/tests/ref/fate/segment-mp4-to-ts
>> +++ b/tests/ref/fate/segment-mp4-to-ts
>> @@ -23,7 +23,7 @@
>> 0, 50400, 54000, 3600, 607, 0xc53c2339, F=0x0,
>> S=1, 1
>> 0, 54000, 72000, 3600, 4755, 0x2f642b58, F=0x0,
>> S=1, 1
>> 0, 57600, 64800, 3600, 1182, 0xbe1a4847, F=0x0,
>> S=1, 1
>> -0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x2,
>> S=1, 1
>> +0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x0,
>> S=1, 1
>> 0, 64800, 68400, 3600, 656, 0x4fa03c2b, F=0x0,
>> S=1, 1
>> 0, 68400, 86400, 3600, 26555, 0x5629b584,
>> S=1, 1
>> 0, 72000, 79200, 3600, 1141, 0x761b31e8, F=0x0,
>> S=1, 1
>> @@ -71,7 +71,7 @@
>> 0, 223200, 226800, 3600, 809, 0x84e37fee, F=0x0,
>> S=1, 1
>> 0, 226800, 244800, 3600, 4541, 0xd4e5c0de, F=0x0,
>> S=1, 1
>> 0, 230400, 237600, 3600, 1545, 0x0099fc98, F=0x0,
>> S=1, 1
>> -0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x0,
>> S=1, 1
>> +0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x2,
>> S=1, 1
>> 0, 237600, 241200, 3600, 829, 0xcfda9e96, F=0x0,
>> S=1, 1
>> 0, 241200, 259200, 3600, 24220, 0x5ca21d71,
>> S=1, 1
>> 0, 244800, 252000, 3600, 1422, 0xcde6cc34, F=0x0,
>> S=1, 1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/segment: calculate segment durations correctly.
2023-01-15 4:19 ` Gyan Doshi
@ 2023-01-16 10:09 ` Gyan Doshi
0 siblings, 0 replies; 4+ messages in thread
From: Gyan Doshi @ 2023-01-16 10:09 UTC (permalink / raw)
To: ffmpeg-devel
Pushed as 01f46f18dbcdf323ceb4fdff7358cf3ca71366e6
On 2023-01-15 09:49 am, Gyan Doshi wrote:
>
>
> On 2023-01-12 11:29 am, Gyan Doshi wrote:
>>
>>
>> On 2023-01-07 05:37 pm, Gyan Doshi wrote:
>>> 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.
>>
>> Comments?
>
> Plan to push tomorrow.
>
>>
>>> ---
>>> libavformat/segment.c | 15 +++++++++++++++
>>> tests/ref/fate/segment-mp4-to-ts | 4 ++--
>>> 2 files changed, 17 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>>> index 0e6421ea5d..80e4bf851c 100644
>>> --- a/libavformat/segment.c
>>> +++ b/libavformat/segment.c
>>> @@ -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);
>>> diff --git a/tests/ref/fate/segment-mp4-to-ts
>>> b/tests/ref/fate/segment-mp4-to-ts
>>> index 54fcadb846..2994416270 100644
>>> --- a/tests/ref/fate/segment-mp4-to-ts
>>> +++ b/tests/ref/fate/segment-mp4-to-ts
>>> @@ -23,7 +23,7 @@
>>> 0, 50400, 54000, 3600, 607, 0xc53c2339, F=0x0,
>>> S=1, 1
>>> 0, 54000, 72000, 3600, 4755, 0x2f642b58, F=0x0,
>>> S=1, 1
>>> 0, 57600, 64800, 3600, 1182, 0xbe1a4847, F=0x0,
>>> S=1, 1
>>> -0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x2,
>>> S=1, 1
>>> +0, 61200, 61200, 3600, 809, 0x8d948a4e, F=0x0,
>>> S=1, 1
>>> 0, 64800, 68400, 3600, 656, 0x4fa03c2b, F=0x0,
>>> S=1, 1
>>> 0, 68400, 86400, 3600, 26555, 0x5629b584,
>>> S=1, 1
>>> 0, 72000, 79200, 3600, 1141, 0x761b31e8, F=0x0,
>>> S=1, 1
>>> @@ -71,7 +71,7 @@
>>> 0, 223200, 226800, 3600, 809, 0x84e37fee, F=0x0,
>>> S=1, 1
>>> 0, 226800, 244800, 3600, 4541, 0xd4e5c0de, F=0x0,
>>> S=1, 1
>>> 0, 230400, 237600, 3600, 1545, 0x0099fc98, F=0x0,
>>> S=1, 1
>>> -0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x0,
>>> S=1, 1
>>> +0, 234000, 234000, 3600, 929, 0xfd72d049, F=0x2,
>>> S=1, 1
>>> 0, 237600, 241200, 3600, 829, 0xcfda9e96, F=0x0,
>>> S=1, 1
>>> 0, 241200, 259200, 3600, 24220, 0x5ca21d71,
>>> S=1, 1
>>> 0, 244800, 252000, 3600, 1422, 0xcde6cc34, F=0x0,
>>> S=1, 1
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-16 10:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-07 12:07 [FFmpeg-devel] [PATCH v2] avformat/segment: calculate segment durations correctly Gyan Doshi
2023-01-12 5:59 ` Gyan Doshi
2023-01-15 4:19 ` Gyan Doshi
2023-01-16 10:09 ` Gyan Doshi
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git