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

Steven Liu lingjiujianke at gmail.com
Wed Feb 28 06:49:13 EET 2018


2018-02-28 11:32 GMT+08:00 Jeyapal, Karthick <kjeyapal at 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 at 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


More information about the ffmpeg-devel mailing list