diff mbox

[FFmpeg-devel] avformat/hlsenc: add reference stream index for split segment

Message ID 20180227053933.14789-1-lq@chinaffmpeg.org
State Superseded
Headers show

Commit Message

Liu Steven Feb. 27, 2018, 5:39 a.m. UTC
fix ticket: #7044
Get the first video stream to reference for split segment
when there have more than one video stream

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Jeyapal, Karthick Feb. 28, 2018, 3:32 a.m. UTC | #1
On 2/27/18 11:09 AM, Steven Liu wrote:
> fix ticket: #7044

> Get the first video stream to reference for split segment

> when there have more than one video stream

>

> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>

> ---

>  libavformat/hlsenc.c | 12 ++++++++++--

>  1 file changed, 10 insertions(+), 2 deletions(-)

>

> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c

> index ff064732a1..8567227885 100644

> --- a/libavformat/hlsenc.c

> +++ b/libavformat/hlsenc.c

> @@ -129,6 +129,7 @@ typedef struct VariantStream {

>      int nb_entries;

>      int discontinuity_set;

>      int discontinuity;

> +    int reference_stream_index;

>  

>      HLSSegment *segments;

>      HLSSegment *last_segment;

> @@ -2155,8 +2156,10 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)

>                                         * st->time_base.num / st->time_base.den;

>              vs->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den;

>          } else {

> -            if (pkt->duration) {

> -                vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;

> +           if (pkt->duration) {

> +                if (pkt->stream_index == vs->reference_stream_index) {

> +                    vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;

> +                }

Still the duration variable in other places is being set for all video streams. 
Maybe it is better to restrict the “is_ref_pkt” to 1, only for vs->reference_stream_index.
>              } else {

>                  av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the hls segment duration will not precise\n");

>                  vs->duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den;

> @@ -2497,6 +2500,11 @@ static int hls_init(AVFormatContext *s)

>  

>          for (j = 0; j < vs->nb_streams; j++) {

>              vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;

> +            /* Get one video stream to reference for split segments

> +             * so use the first video stream index. */

> +            if (vs->has_video == 1) {

> +                vs->reference_stream_index = j;

> +            }

This doesn’t look correct. Potentially vs->reference_stream_index could get overwritten by audio and/or subtitle stream index.
>              vs->has_subtitle += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE;

>          }

>
Steven Liu Feb. 28, 2018, 4:49 a.m. UTC | #2
2018-02-28 11:32 GMT+08:00 Jeyapal, Karthick <kjeyapal@akamai.com>:
>
>
> On 2/27/18 11:09 AM, Steven Liu wrote:
>> fix ticket: #7044
>> Get the first video stream to reference for split segment
>> when there have more than one video stream
>>
>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>> ---
>>  libavformat/hlsenc.c | 12 ++++++++++--
>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index ff064732a1..8567227885 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -129,6 +129,7 @@ typedef struct VariantStream {
>>      int nb_entries;
>>      int discontinuity_set;
>>      int discontinuity;
>> +    int reference_stream_index;
>>
>>      HLSSegment *segments;
>>      HLSSegment *last_segment;
>> @@ -2155,8 +2156,10 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>>                                         * st->time_base.num / st->time_base.den;
>>              vs->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den;
>>          } else {
>> -            if (pkt->duration) {
>> -                vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
>> +           if (pkt->duration) {
>> +                if (pkt->stream_index == vs->reference_stream_index) {
>> +                    vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
>> +                }
> Still the duration variable in other places is being set for all video streams.
> Maybe it is better to restrict the “is_ref_pkt” to 1, only for vs->reference_stream_index.
>>              } else {
>>                  av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the hls segment duration will not precise\n");
>>                  vs->duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den;
>> @@ -2497,6 +2500,11 @@ static int hls_init(AVFormatContext *s)
>>
>>          for (j = 0; j < vs->nb_streams; j++) {
>>              vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
>> +            /* Get one video stream to reference for split segments
>> +             * so use the first video stream index. */
>> +            if (vs->has_video == 1) {
>> +                vs->reference_stream_index = j;
>> +            }
> This doesn’t look correct. Potentially vs->reference_stream_index could get overwritten by audio and/or subtitle stream index.



Patch updated :D



Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index ff064732a1..8567227885 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -129,6 +129,7 @@  typedef struct VariantStream {
     int nb_entries;
     int discontinuity_set;
     int discontinuity;
+    int reference_stream_index;
 
     HLSSegment *segments;
     HLSSegment *last_segment;
@@ -2155,8 +2156,10 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
                                        * st->time_base.num / st->time_base.den;
             vs->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den;
         } else {
-            if (pkt->duration) {
-                vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
+           if (pkt->duration) {
+                if (pkt->stream_index == vs->reference_stream_index) {
+                    vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
+                }
             } else {
                 av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the hls segment duration will not precise\n");
                 vs->duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den;
@@ -2497,6 +2500,11 @@  static int hls_init(AVFormatContext *s)
 
         for (j = 0; j < vs->nb_streams; j++) {
             vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
+            /* Get one video stream to reference for split segments
+             * so use the first video stream index. */
+            if (vs->has_video == 1) {
+                vs->reference_stream_index = j;
+            }
             vs->has_subtitle += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE;
         }