diff mbox

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

Message ID 20180228044826.32278-1-lq@chinaffmpeg.org
State Accepted
Commit aa294ad00a497d07931914027267cd4964425ca3
Headers show

Commit Message

Liu Steven Feb. 28, 2018, 4:48 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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Jeyapal, Karthick Feb. 28, 2018, 4:50 a.m. UTC | #1
On 2/28/18 10:18 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 | 8 +++++++-

>  1 file changed, 7 insertions(+), 1 deletion(-)

>

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

> index ff064732a1..08fe0aa7a0 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;

> @@ -2141,7 +2142,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)

>      if (vs->has_video) {

>          can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&

>                      ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME));

> -        is_ref_pkt = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;

> +        is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->stream_index == vs->reference_stream_index);

>      }

>      if (pkt->pts == AV_NOPTS_VALUE)

>          is_ref_pkt = can_split = 0;

> @@ -2497,6 +2498,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->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) {

> +                vs->reference_stream_index = j;

> +            }

>              vs->has_subtitle += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE;

>          }

>  

LGTM

Regards,
Karthick
Liu Steven March 2, 2018, 2:59 a.m. UTC | #2
> On 28 Feb 2018, at 12:50, Jeyapal, Karthick <kjeyapal@akamai.com> wrote:
> 
> 
> 
> On 2/28/18 10:18 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 | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index ff064732a1..08fe0aa7a0 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;
>> @@ -2141,7 +2142,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>>     if (vs->has_video) {
>>         can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
>>                     ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME));
>> -        is_ref_pkt = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
>> +        is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->stream_index == vs->reference_stream_index);
>>     }
>>     if (pkt->pts == AV_NOPTS_VALUE)
>>         is_ref_pkt = can_split = 0;
>> @@ -2497,6 +2498,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->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) {
>> +                vs->reference_stream_index = j;
>> +            }
>>             vs->has_subtitle += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE;
>>         }
>> 
> LGTM
Pushed
> 
> Regards,
> Karthick
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index ff064732a1..08fe0aa7a0 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;
@@ -2141,7 +2142,7 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (vs->has_video) {
         can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
                     ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME));
-        is_ref_pkt = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
+        is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->stream_index == vs->reference_stream_index);
     }
     if (pkt->pts == AV_NOPTS_VALUE)
         is_ref_pkt = can_split = 0;
@@ -2497,6 +2498,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->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) {
+                vs->reference_stream_index = j;
+            }
             vs->has_subtitle += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE;
         }