Re: [FFmpeg-devel] [PATCH v8 1/3] avformat/hlsenc:addition of #EXT-X-MEDIA tag and AUDIO attribute
2017-12-22 19:30 GMT+08:00 刘歧 : > > >> On 22 Dec 2017, at 19:05, Dixit, Vishwanath wrote: >> >> On 12/19/17 11:53 AM, 刘歧 wrote: >>> On 19 Dec 2017, at 14:09, vdi...@akamai.com wrote: From: Vishwanath Dixit --- doc/muxers.texi | 12 + libavformat/dashenc.c | 3 ++- libavformat/hlsenc.c | 64 --- libavformat/hlsplaylist.c | 4 ++- libavformat/hlsplaylist.h | 2 +- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 3d0c7bf..93db549 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -834,6 +834,18 @@ be a video only stream with video bitrate 1000k, the second variant stream will be an audio only stream with bitrate 64k and the third variant stream will be a video only stream with bitrate 256k. Here, three media playlist with file names out_1.m3u8, out_2.m3u8 and out_3.m3u8 will be created. +@example +ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \ + -map 0:a -map 0:a -map 0:v -map 0:v -f hls \ + -var_stream_map "a:0,agroup:aud_low a:1,agroup:aud_high v:0,agroup:aud_low v:1,agroup:aud_high" \ + -master_pl_name master.m3u8 \ + http://example.com/live/out.m3u8 +@end example +This example creates two audio only and two video only variant streams. In +addition to the #EXT-X-STREAM-INF tag for each variant stream in the master +playlist, #EXT-X-MEDIA tag is also added for the two audio only variant streams +and they are mapped to the two video only variant streams with audio group names +'aud_low' and 'aud_high'. By default, a single hls variant containing all the encoded streams is created. diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 5687530..f363418 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -759,7 +759,8 @@ static int write_manifest(AVFormatContext *s, int final) char playlist_file[64]; AVStream *st = s->streams[i]; get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); -ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, playlist_file); +ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, +playlist_file, NULL); } avio_close(out); if (use_rename) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index e3442c3..53dc835 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -144,6 +144,7 @@ typedef struct VariantStream { AVStream **streams; unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ +char *agroup; /* audio group name */ char *baseurl; } VariantStream; @@ -1085,7 +1086,7 @@ static int create_master_playlist(AVFormatContext *s, VariantStream * const input_vs) { HLSContext *hls = s->priv_data; -VariantStream *vs; +VariantStream *vs, *temp_vs; AVStream *vid_st, *aud_st; AVDictionary *options = NULL; unsigned int i, j; @@ -1117,6 +1118,34 @@ static int create_master_playlist(AVFormatContext *s, ff_hls_write_playlist_version(hls->m3u8_out, hls->version); +/* For audio only variant streams add #EXT-X-MEDIA tag with attributes*/ +for (i = 0; i < hls->nb_varstreams; i++) { +vs = &(hls->var_streams[i]); + +if (vs->has_video || vs->has_subtitle || !vs->agroup) +continue; + +m3u8_name_size = strlen(vs->m3u8_name) + 1; +m3u8_rel_name = av_malloc(m3u8_name_size); +if (!m3u8_rel_name) { +ret = AVERROR(ENOMEM); +goto fail; +} +av_strlcpy(m3u8_rel_name, vs->m3u8_name, m3u8_name_size); +ret = get_relative_url(hls->master_m3u8_url, vs->m3u8_name, + m3u8_rel_name, m3u8_name_size); +if (ret < 0) { +av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n"); +goto fail; +} + +avio_printf(hls->m3u8_out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", +vs->agroup); +avio_printf(hls->m3u8_out, ",NAME=\"audio_0\",DEFAULT=YES,URI=\"%s\"\n", +m3u8_rel_name); +av_freep(&m3u8_rel_name); +} + /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ for (i = 0; i < hls->nb_varstreams; i++) { vs = &(hls->var_streams[i]); @@ -1149
Re: [FFmpeg-devel] [PATCH v8 1/3] avformat/hlsenc:addition of #EXT-X-MEDIA tag and AUDIO attribute
> On 22 Dec 2017, at 19:05, Dixit, Vishwanath wrote: > > On 12/19/17 11:53 AM, 刘歧 wrote: >> On 19 Dec 2017, at 14:09, vdi...@akamai.com wrote: >>> From: Vishwanath Dixit >>> >>> --- >>> doc/muxers.texi | 12 + >>> libavformat/dashenc.c | 3 ++- >>> libavformat/hlsenc.c | 64 >>> --- >>> libavformat/hlsplaylist.c | 4 ++- >>> libavformat/hlsplaylist.h | 2 +- >>> 5 files changed, 79 insertions(+), 6 deletions(-) >>> >>> diff --git a/doc/muxers.texi b/doc/muxers.texi >>> index 3d0c7bf..93db549 100644 >>> --- a/doc/muxers.texi >>> +++ b/doc/muxers.texi >>> @@ -834,6 +834,18 @@ be a video only stream with video bitrate 1000k, the >>> second variant stream will >>> be an audio only stream with bitrate 64k and the third variant stream will >>> be a >>> video only stream with bitrate 256k. Here, three media playlist with file >>> names >>> out_1.m3u8, out_2.m3u8 and out_3.m3u8 will be created. >>> +@example >>> +ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \ >>> + -map 0:a -map 0:a -map 0:v -map 0:v -f hls \ >>> + -var_stream_map "a:0,agroup:aud_low a:1,agroup:aud_high >>> v:0,agroup:aud_low v:1,agroup:aud_high" \ >>> + -master_pl_name master.m3u8 \ >>> + http://example.com/live/out.m3u8 >>> +@end example >>> +This example creates two audio only and two video only variant streams. In >>> +addition to the #EXT-X-STREAM-INF tag for each variant stream in the master >>> +playlist, #EXT-X-MEDIA tag is also added for the two audio only variant >>> streams >>> +and they are mapped to the two video only variant streams with audio group >>> names >>> +'aud_low' and 'aud_high'. >>> >>> By default, a single hls variant containing all the encoded streams is >>> created. >>> >>> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c >>> index 5687530..f363418 100644 >>> --- a/libavformat/dashenc.c >>> +++ b/libavformat/dashenc.c >>> @@ -759,7 +759,8 @@ static int write_manifest(AVFormatContext *s, int final) >>>char playlist_file[64]; >>>AVStream *st = s->streams[i]; >>>get_hls_playlist_name(playlist_file, sizeof(playlist_file), >>> NULL, i); >>> -ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, >>> playlist_file); >>> +ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, >>> +playlist_file, NULL); >>>} >>>avio_close(out); >>>if (use_rename) >>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c >>> index e3442c3..53dc835 100644 >>> --- a/libavformat/hlsenc.c >>> +++ b/libavformat/hlsenc.c >>> @@ -144,6 +144,7 @@ typedef struct VariantStream { >>>AVStream **streams; >>>unsigned int nb_streams; >>>int m3u8_created; /* status of media play-list creation */ >>> +char *agroup; /* audio group name */ >>>char *baseurl; >>> } VariantStream; >>> >>> @@ -1085,7 +1086,7 @@ static int create_master_playlist(AVFormatContext *s, >>> VariantStream * const input_vs) >>> { >>>HLSContext *hls = s->priv_data; >>> -VariantStream *vs; >>> +VariantStream *vs, *temp_vs; >>>AVStream *vid_st, *aud_st; >>>AVDictionary *options = NULL; >>>unsigned int i, j; >>> @@ -1117,6 +1118,34 @@ static int create_master_playlist(AVFormatContext *s, >>> >>>ff_hls_write_playlist_version(hls->m3u8_out, hls->version); >>> >>> +/* For audio only variant streams add #EXT-X-MEDIA tag with >>> attributes*/ >>> +for (i = 0; i < hls->nb_varstreams; i++) { >>> +vs = &(hls->var_streams[i]); >>> + >>> +if (vs->has_video || vs->has_subtitle || !vs->agroup) >>> +continue; >>> + >>> +m3u8_name_size = strlen(vs->m3u8_name) + 1; >>> +m3u8_rel_name = av_malloc(m3u8_name_size); >>> +if (!m3u8_rel_name) { >>> +ret = AVERROR(ENOMEM); >>> +goto fail; >>> +} >>> +av_strlcpy(m3u8_rel_name, vs->m3u8_name, m3u8_name_size); >>> +ret = get_relative_url(hls->master_m3u8_url, vs->m3u8_name, >>> + m3u8_rel_name, m3u8_name_size); >>> +if (ret < 0) { >>> +av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n"); >>> +goto fail; >>> +} >>> + >>> +avio_printf(hls->m3u8_out, >>> "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", >>> +vs->agroup); >>> +avio_printf(hls->m3u8_out, >>> ",NAME=\"audio_0\",DEFAULT=YES,URI=\"%s\"\n", >>> +m3u8_rel_name); >>> +av_freep(&m3u8_rel_name); >>> +} >>> + >>>/* For variant streams with video add #EXT-X-STREAM-INF tag with >>> attributes*/ >>>for (i = 0; i < hls->nb_varstreams; i++) { >>>vs = &(hls->var_streams[i]); >>> @@ -1149,6 +1178,25 @@ static int create_master_playlist(AVFormatContext *s, >>>continue; >>>} >>> >>> +/** >>> + * Traverse through the
Re: [FFmpeg-devel] [PATCH v8 1/3] avformat/hlsenc:addition of #EXT-X-MEDIA tag and AUDIO attribute
On 12/19/17 11:53 AM, 刘歧 wrote: > On 19 Dec 2017, at 14:09, vdi...@akamai.com wrote: >> From: Vishwanath Dixit >> >> --- >> doc/muxers.texi | 12 + >> libavformat/dashenc.c | 3 ++- >> libavformat/hlsenc.c | 64 >> --- >> libavformat/hlsplaylist.c | 4 ++- >> libavformat/hlsplaylist.h | 2 +- >> 5 files changed, 79 insertions(+), 6 deletions(-) >> >> diff --git a/doc/muxers.texi b/doc/muxers.texi >> index 3d0c7bf..93db549 100644 >> --- a/doc/muxers.texi >> +++ b/doc/muxers.texi >> @@ -834,6 +834,18 @@ be a video only stream with video bitrate 1000k, the >> second variant stream will >> be an audio only stream with bitrate 64k and the third variant stream will >> be a >> video only stream with bitrate 256k. Here, three media playlist with file >> names >> out_1.m3u8, out_2.m3u8 and out_3.m3u8 will be created. >> +@example >> +ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \ >> + -map 0:a -map 0:a -map 0:v -map 0:v -f hls \ >> + -var_stream_map "a:0,agroup:aud_low a:1,agroup:aud_high >> v:0,agroup:aud_low v:1,agroup:aud_high" \ >> + -master_pl_name master.m3u8 \ >> + http://example.com/live/out.m3u8 >> +@end example >> +This example creates two audio only and two video only variant streams. In >> +addition to the #EXT-X-STREAM-INF tag for each variant stream in the master >> +playlist, #EXT-X-MEDIA tag is also added for the two audio only variant >> streams >> +and they are mapped to the two video only variant streams with audio group >> names >> +'aud_low' and 'aud_high'. >> >> By default, a single hls variant containing all the encoded streams is >> created. >> >> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c >> index 5687530..f363418 100644 >> --- a/libavformat/dashenc.c >> +++ b/libavformat/dashenc.c >> @@ -759,7 +759,8 @@ static int write_manifest(AVFormatContext *s, int final) >> char playlist_file[64]; >> AVStream *st = s->streams[i]; >> get_hls_playlist_name(playlist_file, sizeof(playlist_file), >> NULL, i); >> -ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, >> playlist_file); >> +ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, >> +playlist_file, NULL); >> } >> avio_close(out); >> if (use_rename) >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c >> index e3442c3..53dc835 100644 >> --- a/libavformat/hlsenc.c >> +++ b/libavformat/hlsenc.c >> @@ -144,6 +144,7 @@ typedef struct VariantStream { >> AVStream **streams; >> unsigned int nb_streams; >> int m3u8_created; /* status of media play-list creation */ >> +char *agroup; /* audio group name */ >> char *baseurl; >> } VariantStream; >> >> @@ -1085,7 +1086,7 @@ static int create_master_playlist(AVFormatContext *s, >> VariantStream * const input_vs) >> { >> HLSContext *hls = s->priv_data; >> -VariantStream *vs; >> +VariantStream *vs, *temp_vs; >> AVStream *vid_st, *aud_st; >> AVDictionary *options = NULL; >> unsigned int i, j; >> @@ -1117,6 +1118,34 @@ static int create_master_playlist(AVFormatContext *s, >> >> ff_hls_write_playlist_version(hls->m3u8_out, hls->version); >> >> +/* For audio only variant streams add #EXT-X-MEDIA tag with attributes*/ >> +for (i = 0; i < hls->nb_varstreams; i++) { >> +vs = &(hls->var_streams[i]); >> + >> +if (vs->has_video || vs->has_subtitle || !vs->agroup) >> +continue; >> + >> +m3u8_name_size = strlen(vs->m3u8_name) + 1; >> +m3u8_rel_name = av_malloc(m3u8_name_size); >> +if (!m3u8_rel_name) { >> +ret = AVERROR(ENOMEM); >> +goto fail; >> +} >> +av_strlcpy(m3u8_rel_name, vs->m3u8_name, m3u8_name_size); >> +ret = get_relative_url(hls->master_m3u8_url, vs->m3u8_name, >> + m3u8_rel_name, m3u8_name_size); >> +if (ret < 0) { >> +av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n"); >> +goto fail; >> +} >> + >> +avio_printf(hls->m3u8_out, >> "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", >> +vs->agroup); >> +avio_printf(hls->m3u8_out, >> ",NAME=\"audio_0\",DEFAULT=YES,URI=\"%s\"\n", >> +m3u8_rel_name); >> +av_freep(&m3u8_rel_name); >> +} >> + >> /* For variant streams with video add #EXT-X-STREAM-INF tag with >> attributes*/ >> for (i = 0; i < hls->nb_varstreams; i++) { >> vs = &(hls->var_streams[i]); >> @@ -1149,6 +1178,25 @@ static int create_master_playlist(AVFormatContext *s, >> continue; >> } >> >> +/** >> + * Traverse through the list of audio only rendition streams and >> find >> + * the rendition which has highest bitrate in the same audio group >> + */ >> +if (vs->agroup) { >
Re: [FFmpeg-devel] [PATCH v8 1/3] avformat/hlsenc:addition of #EXT-X-MEDIA tag and AUDIO attribute
On 19 Dec 2017, at 14:09, vdi...@akamai.com wrote: > > From: Vishwanath Dixit > > --- > doc/muxers.texi | 12 + > libavformat/dashenc.c | 3 ++- > libavformat/hlsenc.c | 64 --- > libavformat/hlsplaylist.c | 4 ++- > libavformat/hlsplaylist.h | 2 +- > 5 files changed, 79 insertions(+), 6 deletions(-) > > diff --git a/doc/muxers.texi b/doc/muxers.texi > index 3d0c7bf..93db549 100644 > --- a/doc/muxers.texi > +++ b/doc/muxers.texi > @@ -834,6 +834,18 @@ be a video only stream with video bitrate 1000k, the > second variant stream will > be an audio only stream with bitrate 64k and the third variant stream will be > a > video only stream with bitrate 256k. Here, three media playlist with file > names > out_1.m3u8, out_2.m3u8 and out_3.m3u8 will be created. > +@example > +ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \ > + -map 0:a -map 0:a -map 0:v -map 0:v -f hls \ > + -var_stream_map "a:0,agroup:aud_low a:1,agroup:aud_high v:0,agroup:aud_low > v:1,agroup:aud_high" \ > + -master_pl_name master.m3u8 \ > + http://example.com/live/out.m3u8 > +@end example > +This example creates two audio only and two video only variant streams. In > +addition to the #EXT-X-STREAM-INF tag for each variant stream in the master > +playlist, #EXT-X-MEDIA tag is also added for the two audio only variant > streams > +and they are mapped to the two video only variant streams with audio group > names > +'aud_low' and 'aud_high'. > > By default, a single hls variant containing all the encoded streams is > created. > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > index 5687530..f363418 100644 > --- a/libavformat/dashenc.c > +++ b/libavformat/dashenc.c > @@ -759,7 +759,8 @@ static int write_manifest(AVFormatContext *s, int final) >char playlist_file[64]; >AVStream *st = s->streams[i]; >get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, > i); > -ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, > playlist_file); > +ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, > +playlist_file, NULL); >} >avio_close(out); >if (use_rename) > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c > index e3442c3..53dc835 100644 > --- a/libavformat/hlsenc.c > +++ b/libavformat/hlsenc.c > @@ -144,6 +144,7 @@ typedef struct VariantStream { >AVStream **streams; >unsigned int nb_streams; >int m3u8_created; /* status of media play-list creation */ > +char *agroup; /* audio group name */ >char *baseurl; > } VariantStream; > > @@ -1085,7 +1086,7 @@ static int create_master_playlist(AVFormatContext *s, > VariantStream * const input_vs) > { >HLSContext *hls = s->priv_data; > -VariantStream *vs; > +VariantStream *vs, *temp_vs; >AVStream *vid_st, *aud_st; >AVDictionary *options = NULL; >unsigned int i, j; > @@ -1117,6 +1118,34 @@ static int create_master_playlist(AVFormatContext *s, > >ff_hls_write_playlist_version(hls->m3u8_out, hls->version); > > +/* For audio only variant streams add #EXT-X-MEDIA tag with attributes*/ > +for (i = 0; i < hls->nb_varstreams; i++) { > +vs = &(hls->var_streams[i]); > + > +if (vs->has_video || vs->has_subtitle || !vs->agroup) > +continue; > + > +m3u8_name_size = strlen(vs->m3u8_name) + 1; > +m3u8_rel_name = av_malloc(m3u8_name_size); > +if (!m3u8_rel_name) { > +ret = AVERROR(ENOMEM); > +goto fail; > +} > +av_strlcpy(m3u8_rel_name, vs->m3u8_name, m3u8_name_size); > +ret = get_relative_url(hls->master_m3u8_url, vs->m3u8_name, > + m3u8_rel_name, m3u8_name_size); > +if (ret < 0) { > +av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n"); > +goto fail; > +} > + > +avio_printf(hls->m3u8_out, > "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", > +vs->agroup); > +avio_printf(hls->m3u8_out, > ",NAME=\"audio_0\",DEFAULT=YES,URI=\"%s\"\n", > +m3u8_rel_name); > +av_freep(&m3u8_rel_name); > +} > + >/* For variant streams with video add #EXT-X-STREAM-INF tag with > attributes*/ >for (i = 0; i < hls->nb_varstreams; i++) { >vs = &(hls->var_streams[i]); > @@ -1149,6 +1178,25 @@ static int create_master_playlist(AVFormatContext *s, >continue; >} > > +/** > + * Traverse through the list of audio only rendition streams and find > + * the rendition which has highest bitrate in the same audio group > + */ > +if (vs->agroup) { > +for (j = 0; j < hls->nb_varstreams; j++) { > +temp_vs = &(hls->var_streams[j]); > +if (!temp_vs->has_video && !temp_vs->has_subtit
[FFmpeg-devel] [PATCH v8 1/3] avformat/hlsenc:addition of #EXT-X-MEDIA tag and AUDIO attribute
From: Vishwanath Dixit --- doc/muxers.texi | 12 + libavformat/dashenc.c | 3 ++- libavformat/hlsenc.c | 64 --- libavformat/hlsplaylist.c | 4 ++- libavformat/hlsplaylist.h | 2 +- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 3d0c7bf..93db549 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -834,6 +834,18 @@ be a video only stream with video bitrate 1000k, the second variant stream will be an audio only stream with bitrate 64k and the third variant stream will be a video only stream with bitrate 256k. Here, three media playlist with file names out_1.m3u8, out_2.m3u8 and out_3.m3u8 will be created. +@example +ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \ + -map 0:a -map 0:a -map 0:v -map 0:v -f hls \ + -var_stream_map "a:0,agroup:aud_low a:1,agroup:aud_high v:0,agroup:aud_low v:1,agroup:aud_high" \ + -master_pl_name master.m3u8 \ + http://example.com/live/out.m3u8 +@end example +This example creates two audio only and two video only variant streams. In +addition to the #EXT-X-STREAM-INF tag for each variant stream in the master +playlist, #EXT-X-MEDIA tag is also added for the two audio only variant streams +and they are mapped to the two video only variant streams with audio group names +'aud_low' and 'aud_high'. By default, a single hls variant containing all the encoded streams is created. diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 5687530..f363418 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -759,7 +759,8 @@ static int write_manifest(AVFormatContext *s, int final) char playlist_file[64]; AVStream *st = s->streams[i]; get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); -ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, playlist_file); +ff_hls_write_stream_info(st, out, st->codecpar->bit_rate, +playlist_file, NULL); } avio_close(out); if (use_rename) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index e3442c3..53dc835 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -144,6 +144,7 @@ typedef struct VariantStream { AVStream **streams; unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ +char *agroup; /* audio group name */ char *baseurl; } VariantStream; @@ -1085,7 +1086,7 @@ static int create_master_playlist(AVFormatContext *s, VariantStream * const input_vs) { HLSContext *hls = s->priv_data; -VariantStream *vs; +VariantStream *vs, *temp_vs; AVStream *vid_st, *aud_st; AVDictionary *options = NULL; unsigned int i, j; @@ -1117,6 +1118,34 @@ static int create_master_playlist(AVFormatContext *s, ff_hls_write_playlist_version(hls->m3u8_out, hls->version); +/* For audio only variant streams add #EXT-X-MEDIA tag with attributes*/ +for (i = 0; i < hls->nb_varstreams; i++) { +vs = &(hls->var_streams[i]); + +if (vs->has_video || vs->has_subtitle || !vs->agroup) +continue; + +m3u8_name_size = strlen(vs->m3u8_name) + 1; +m3u8_rel_name = av_malloc(m3u8_name_size); +if (!m3u8_rel_name) { +ret = AVERROR(ENOMEM); +goto fail; +} +av_strlcpy(m3u8_rel_name, vs->m3u8_name, m3u8_name_size); +ret = get_relative_url(hls->master_m3u8_url, vs->m3u8_name, + m3u8_rel_name, m3u8_name_size); +if (ret < 0) { +av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n"); +goto fail; +} + +avio_printf(hls->m3u8_out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", +vs->agroup); +avio_printf(hls->m3u8_out, ",NAME=\"audio_0\",DEFAULT=YES,URI=\"%s\"\n", +m3u8_rel_name); +av_freep(&m3u8_rel_name); +} + /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ for (i = 0; i < hls->nb_varstreams; i++) { vs = &(hls->var_streams[i]); @@ -1149,6 +1178,25 @@ static int create_master_playlist(AVFormatContext *s, continue; } +/** + * Traverse through the list of audio only rendition streams and find + * the rendition which has highest bitrate in the same audio group + */ +if (vs->agroup) { +for (j = 0; j < hls->nb_varstreams; j++) { +temp_vs = &(hls->var_streams[j]); +if (!temp_vs->has_video && !temp_vs->has_subtitle && +temp_vs->agroup && +!av_strcasecmp(temp_vs->agroup, vs->agroup)) { +if (!aud_st) +aud_st = temp_vs->streams[0]; +if (temp_vs->streams[0]->cod