diff mbox series

[FFmpeg-devel,v2] avformat/hlsenc: Fix initial setting for start_pts

Message ID 1583467102-29502-1-git-send-email-sj.hc_Zhong@sjtu.edu.cn
State Accepted
Headers show
Series [FFmpeg-devel,v2] avformat/hlsenc: Fix initial setting for start_pts | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Hongcheng Zhong March 6, 2020, 3:58 a.m. UTC
This patch fixes Bug #8469
If x264 baseline profile is used with other profiles,
start_pts will be initialized to audio stream's first pts,
while the duration is calculated based on video stream's pts.
In this patch the start_pts is initialized with the correct stream's first pts.

Signed-off-by: Hongcheng Zhong <sj.hc_Zhong@sjtu.edu.cn>
---
 libavformat/hlsenc.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Liu Steven March 7, 2020, 3:26 a.m. UTC | #1
> 2020年3月6日 上午11:58,Hongcheng Zhong <sj.hc_zhong@sjtu.edu.cn> 写道:
> 
> This patch fixes Bug #8469
> If x264 baseline profile is used with other profiles,
> start_pts will be initialized to audio stream's first pts,
> while the duration is calculated based on video stream's pts.
> In this patch the start_pts is initialized with the correct stream's first pts.
> 
> Signed-off-by: Hongcheng Zhong <sj.hc_Zhong@sjtu.edu.cn>
> ---
> libavformat/hlsenc.c | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f6dd894..19aa2b1 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -126,6 +126,7 @@ typedef struct VariantStream {
>     int has_video;
>     int has_subtitle;
>     int new_start;
> +    int start_pts_from_audio;
>     double dpp;           // duration per packet
>     int64_t start_pts;
>     int64_t end_pts;
> @@ -2274,6 +2275,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
> 
>     if (vs->start_pts == AV_NOPTS_VALUE) {
>         vs->start_pts = pkt->pts;
> +        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
> +            vs->start_pts_from_audio = 1;
> +    }
> +    if (vs->start_pts_from_audio && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
> +        vs->start_pts = pkt->pts;
> +        vs->start_pts_from_audio = 0;
>     }
> 
>    if (vs->has_video) {
> -- 
> 2.7.4
> 
> _______________________________________________
> 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”.
LGTM

Thanks
Steven
Liu Steven March 10, 2020, 11:06 p.m. UTC | #2
> 2020年3月7日 上午11:26,Steven Liu <lq@chinaffmpeg.org> 写道:
> 
> 
> 
>> 2020年3月6日 上午11:58,Hongcheng Zhong <sj.hc_zhong@sjtu.edu.cn> 写道:
>> 
>> This patch fixes Bug #8469
>> If x264 baseline profile is used with other profiles,
>> start_pts will be initialized to audio stream's first pts,
>> while the duration is calculated based on video stream's pts.
>> In this patch the start_pts is initialized with the correct stream's first pts.
>> 
>> Signed-off-by: Hongcheng Zhong <sj.hc_Zhong@sjtu.edu.cn>
>> ---
>> libavformat/hlsenc.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index f6dd894..19aa2b1 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -126,6 +126,7 @@ typedef struct VariantStream {
>>    int has_video;
>>    int has_subtitle;
>>    int new_start;
>> +    int start_pts_from_audio;
>>    double dpp;           // duration per packet
>>    int64_t start_pts;
>>    int64_t end_pts;
>> @@ -2274,6 +2275,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>> 
>>    if (vs->start_pts == AV_NOPTS_VALUE) {
>>        vs->start_pts = pkt->pts;
>> +        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>> +            vs->start_pts_from_audio = 1;
>> +    }
>> +    if (vs->start_pts_from_audio && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
>> +        vs->start_pts = pkt->pts;
>> +        vs->start_pts_from_audio = 0;
>>    }
>> 
>>   if (vs->has_video) {
>> -- 
>> 2.7.4
>> 
>> _______________________________________________
>> 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”.
> LGTM
> 

Will apply if there have no more comments.

Thanks

Steven
Liu Steven March 12, 2020, 5:16 a.m. UTC | #3
> 2020年3月11日 上午7:06,Steven Liu <lq@chinaffmpeg.org> 写道:
> 
>> 
>> 2020年3月7日 上午11:26,Steven Liu <lq@chinaffmpeg.org> 写道:
>> 
>> 
>> 
>>> 2020年3月6日 上午11:58,Hongcheng Zhong <sj.hc_zhong@sjtu.edu.cn> 写道:
>>> 
>>> This patch fixes Bug #8469
>>> If x264 baseline profile is used with other profiles,
>>> start_pts will be initialized to audio stream's first pts,
>>> while the duration is calculated based on video stream's pts.
>>> In this patch the start_pts is initialized with the correct stream's first pts.
>>> 
>>> Signed-off-by: Hongcheng Zhong <sj.hc_Zhong@sjtu.edu.cn>
>>> ---
>>> libavformat/hlsenc.c | 7 +++++++
>>> 1 file changed, 7 insertions(+)
>>> 
>>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>>> index f6dd894..19aa2b1 100644
>>> --- a/libavformat/hlsenc.c
>>> +++ b/libavformat/hlsenc.c
>>> @@ -126,6 +126,7 @@ typedef struct VariantStream {
>>>   int has_video;
>>>   int has_subtitle;
>>>   int new_start;
>>> +    int start_pts_from_audio;
>>>   double dpp;           // duration per packet
>>>   int64_t start_pts;
>>>   int64_t end_pts;
>>> @@ -2274,6 +2275,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>>> 
>>>   if (vs->start_pts == AV_NOPTS_VALUE) {
>>>       vs->start_pts = pkt->pts;
>>> +        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>>> +            vs->start_pts_from_audio = 1;
>>> +    }
>>> +    if (vs->start_pts_from_audio && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
>>> +        vs->start_pts = pkt->pts;
>>> +        vs->start_pts_from_audio = 0;
>>>   }
>>> 
>>>  if (vs->has_video) {
>>> -- 
>>> 2.7.4
>>> 
>>> _______________________________________________
>>> 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”.
>> LGTM
>> 
> 
> Will apply if there have no more comments.
Applied

> 
> Thanks
> 
> Steven
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f6dd894..19aa2b1 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -126,6 +126,7 @@  typedef struct VariantStream {
     int has_video;
     int has_subtitle;
     int new_start;
+    int start_pts_from_audio;
     double dpp;           // duration per packet
     int64_t start_pts;
     int64_t end_pts;
@@ -2274,6 +2275,12 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (vs->start_pts == AV_NOPTS_VALUE) {
         vs->start_pts = pkt->pts;
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+            vs->start_pts_from_audio = 1;
+    }
+    if (vs->start_pts_from_audio && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) {
+        vs->start_pts = pkt->pts;
+        vs->start_pts_from_audio = 0;
     }
 
    if (vs->has_video) {