* [FFmpeg-devel] [PATCH] avformat/hls: Fixed incorrect behaviour of default setting, , added autoselect and forced @ 2024-07-05 13:27 CoderVenkat 2024-07-07 10:18 ` Steven Liu 0 siblings, 1 reply; 9+ messages in thread From: CoderVenkat @ 2024-07-05 13:27 UTC (permalink / raw) To: ffmpeg-devel In absence of default in var_stream_map, it was setting default=yes on every stream, but according to RFC8216 4.3.4.1 only one stream in a default group may have that. Additionally added support for autoselect=yes/no, whose presence combined with default means that it MUST be YES. Similarly forced=yes/no for subtitle stream. Showed sample output of incorrectness in bug #11088 Signed-off-by: vckt <codervenkat@gmail.com> --- libavformat/dashenc.c | 3 ++- libavformat/hlsenc.c | 41 +++++++++++++++++++++++++++++++++++++-- libavformat/hlsplaylist.c | 25 ++++++++++++++++++++---- libavformat/hlsplaylist.h | 6 ++++-- 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index d4a6fe0304..c84b44f20d 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1273,6 +1273,7 @@ static int write_manifest(AVFormatContext *s, int final) const char *audio_group = "A1"; char audio_codec_str[128] = "\0"; int is_default = 1; + int autoselect = 0; int max_audio_bitrate = 0; for (i = 0; i < s->nb_streams; i++) { @@ -1285,7 +1286,7 @@ static int write_manifest(AVFormatContext *s, int final) continue; get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); ff_hls_write_audio_rendition(c->m3u8_out, audio_group, - playlist_file, NULL, i, is_default, + playlist_file, NULL, i, is_default, autoselect s->streams[i]->codecpar->ch_layout.nb_channels); max_audio_bitrate = FFMAX(st->codecpar->bit_rate + os->muxer_overhead, max_audio_bitrate); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 274de00f9a..af4501af54 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -184,6 +184,8 @@ typedef struct VariantStream { unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ int is_default; /* default status of audio group */ + int autoselect; /* autoselect by system language */ + int forced; /* forced status of subtitle stream */ const char *language; /* audio language name */ const char *agroup; /* audio group name */ const char *sgroup; /* subtitle group name */ @@ -1434,6 +1436,31 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(hls->m3u8_out, ",INSTREAM-ID=\"%s\"\n", ccs->instreamid); } + /* Check only one default is present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (vs->agroup && temp_vs->agroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); + goto fail; + } + } else if (vs->sgroup && temp_vs->sgroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->sgroup, temp_vs->sgroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an sgroup can not be default\n"); + goto fail; + } + } + } + } + } + /* 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]); @@ -1452,7 +1479,7 @@ static int create_master_playlist(AVFormatContext *s, if (vs->streams[j]->codecpar->ch_layout.nb_channels > nb_channels) nb_channels = vs->streams[j]->codecpar->ch_layout.nb_channels; - ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1, nb_channels); + ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, nb_channels); } /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ @@ -1533,7 +1560,7 @@ static int create_master_playlist(AVFormatContext *s, break; } - ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); + ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, vs->forced); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2104,6 +2131,16 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) (!av_strncasecmp(val, "1", strlen("1")))); hls->has_default_key = 1; continue; + } else if (av_strstart(keyval, "autoselect:", &val)) { + vs->autoselect = (!av_strncasecmp(val, "YES", strlen("YES")) || + (!av_strncasecmp(val, "1", strlen("1")))) || + (hls->has_default_key && vs->is_default); + /* autoselect must = 1 if default = 1 */ + continue; + } else if (av_strstart(keyval, "forced:", &val)) { + vs->forced = (!av_strncasecmp(val, "YES", strlen("YES")) || + (!av_strncasecmp(val, "1", strlen("1")))); + continue; } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..40a8a36849 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -39,13 +39,20 @@ void ff_hls_write_playlist_version(AVIOContext *out, int version) void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels) + int name_id, int is_default, + int autoselect, int nb_channels) { if (!out || !agroup || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", agroup); - avio_printf(out, ",NAME=\"audio_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); + avio_printf(out, ",NAME=\"audio_%d\",", name_id); + if (is_default) { + avio_printf(out, "DEFAULT=YES,"); + } + if (autoselect) { + avio_printf(out, "AUTOSELECT=YES,"); + } if (language) { avio_printf(out, "LANGUAGE=\"%s\",", language); } @@ -57,13 +64,23 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + int name_id, int is_default, + int autoselect, int forced) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); - avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); + avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); + if (is_default) { + avio_printf(out, "DEFAULT=YES,"); + } + if (autoselect) { + avio_printf(out, "AUTOSELECT=YES,"); + } + if (forced) { + avio_printf(out, "FORCED=YES,"); + } if (language) { avio_printf(out, "LANGUAGE=\"%s\",", language); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..41e640a09a 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -38,10 +38,12 @@ typedef enum { void ff_hls_write_playlist_version(AVIOContext *out, int version); void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels); + int name_id, int is_default, + int autoselect, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default); + int name_id, int is_default, + int autoselect, int forced); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, -- 2.30.1.windows.1 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hls: Fixed incorrect behaviour of default setting, , added autoselect and forced 2024-07-05 13:27 [FFmpeg-devel] [PATCH] avformat/hls: Fixed incorrect behaviour of default setting, , added autoselect and forced CoderVenkat @ 2024-07-07 10:18 ` Steven Liu 2024-07-08 13:43 ` [FFmpeg-devel] [PATCH v2] avformat/hls: Fixed incorrect behaviour of default CoderVenkat 0 siblings, 1 reply; 9+ messages in thread From: Steven Liu @ 2024-07-07 10:18 UTC (permalink / raw) To: FFmpeg development discussions and patches CoderVenkat <codervenkat@gmail.com> 于2024年7月5日周五 21:27写道: > > In absence of default in var_stream_map, it was setting default=yes on > every stream, > but according to RFC8216 4.3.4.1 only one stream in a default group may > have that. > Additionally added support for autoselect=yes/no, whose presence > combined with default > means that it MUST be YES. Similarly forced=yes/no for subtitle stream. > > Showed sample output of incorrectness in bug #11088 > > Signed-off-by: vckt <codervenkat@gmail.com> > --- > libavformat/dashenc.c | 3 ++- > libavformat/hlsenc.c | 41 +++++++++++++++++++++++++++++++++++++-- > libavformat/hlsplaylist.c | 25 ++++++++++++++++++++---- > libavformat/hlsplaylist.h | 6 ++++-- > 4 files changed, 66 insertions(+), 9 deletions(-) > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > index d4a6fe0304..c84b44f20d 100644 > --- a/libavformat/dashenc.c > +++ b/libavformat/dashenc.c > @@ -1273,6 +1273,7 @@ static int write_manifest(AVFormatContext *s, int > final) > const char *audio_group = "A1"; > char audio_codec_str[128] = "\0"; > int is_default = 1; > + int autoselect = 0; > int max_audio_bitrate = 0; > > for (i = 0; i < s->nb_streams; i++) { > @@ -1285,7 +1286,7 @@ static int write_manifest(AVFormatContext *s, int > final) > continue; > get_hls_playlist_name(playlist_file, > sizeof(playlist_file), NULL, i); > ff_hls_write_audio_rendition(c->m3u8_out, audio_group, > - playlist_file, NULL, i, > is_default, > + playlist_file, NULL, i, > is_default, autoselect > s->streams[i]->codecpar->ch_layout.nb_channels); > max_audio_bitrate = FFMAX(st->codecpar->bit_rate + > os->muxer_overhead, > max_audio_bitrate); > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c > index 274de00f9a..af4501af54 100644 > --- a/libavformat/hlsenc.c > +++ b/libavformat/hlsenc.c > @@ -184,6 +184,8 @@ typedef struct VariantStream { > unsigned int nb_streams; > int m3u8_created; /* status of media play-list creation */ > int is_default; /* default status of audio group */ > + int autoselect; /* autoselect by system language */ > + int forced; /* forced status of subtitle stream */ > const char *language; /* audio language name */ > const char *agroup; /* audio group name */ > const char *sgroup; /* subtitle group name */ > @@ -1434,6 +1436,31 @@ static int create_master_playlist(AVFormatContext *s, > avio_printf(hls->m3u8_out, ",INSTREAM-ID=\"%s\"\n", > ccs->instreamid); > } > > + /* Check only one default is present in a group */ > + for (i = 0; i < hls->nb_varstreams; i++) { > + vs = &(hls->var_streams[i]); > + for (j = 0; j < hls->nb_varstreams; j++) { > + if (i != j) { > + temp_vs = &(hls->var_streams[j]); > + if (vs->agroup && temp_vs->agroup && > + !vs->has_video && !temp_vs->has_video) { > + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && > + vs->is_default && temp_vs->is_default) { > + av_log(s, AV_LOG_ERROR, "Two streams in an > agroup can not be default\n"); > + goto fail; > + } > + } else if (vs->sgroup && temp_vs->sgroup && > + !vs->has_video && !temp_vs->has_video) { > + if (!av_strcasecmp(vs->sgroup, temp_vs->sgroup) && > + vs->is_default && temp_vs->is_default) { > + av_log(s, AV_LOG_ERROR, "Two streams in an > sgroup can not be default\n"); > + goto fail; > + } > + } > + } > + } > + } > + > /* 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]); > @@ -1452,7 +1479,7 @@ static int create_master_playlist(AVFormatContext *s, > if (vs->streams[j]->codecpar->ch_layout.nb_channels > > nb_channels) > nb_channels = > vs->streams[j]->codecpar->ch_layout.nb_channels; > > - ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, > m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : > 1, nb_channels); > + ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, > m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : > 0, vs->autoselect, nb_channels); > } > > /* For variant streams with video add #EXT-X-STREAM-INF tag with > attributes*/ > @@ -1533,7 +1560,7 @@ static int create_master_playlist(AVFormatContext *s, > break; > } > > - ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, > vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? > vs->is_default : 1); > + ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, > vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? > vs->is_default : 0, vs->autoselect, vs->forced); > } > > if (!hls->has_default_key || !hls->has_video_m3u8) { > @@ -2104,6 +2131,16 @@ static int > parse_variant_stream_mapstring(AVFormatContext *s) > (!av_strncasecmp(val, "1", > strlen("1")))); > hls->has_default_key = 1; > continue; > + } else if (av_strstart(keyval, "autoselect:", &val)) { > + vs->autoselect = (!av_strncasecmp(val, "YES", > strlen("YES")) || > + (!av_strncasecmp(val, "1", > strlen("1")))) || What about move the strlen const to start of this function, then it not need more strlen functions call. > + (hls->has_default_key && vs->is_default); > + /* autoselect must = 1 if default = 1 */ > + continue; > + } else if (av_strstart(keyval, "forced:", &val)) { > + vs->forced = (!av_strncasecmp(val, "YES", > strlen("YES")) || > + (!av_strncasecmp(val, "1", > strlen("1")))); > + continue; > } else if (av_strstart(keyval, "name:", &val)) { > vs->varname = val; > continue; > diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c > index f8a6977702..40a8a36849 100644 > --- a/libavformat/hlsplaylist.c > +++ b/libavformat/hlsplaylist.c > @@ -39,13 +39,20 @@ void ff_hls_write_playlist_version(AVIOContext *out, > int version) > > void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, > const char *filename, const char > *language, > - int name_id, int is_default, int > nb_channels) > + int name_id, int is_default, > + int autoselect, int nb_channels) > { > if (!out || !agroup || !filename) > return; > > avio_printf(out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", > agroup); > - avio_printf(out, ",NAME=\"audio_%d\",DEFAULT=%s,", name_id, > is_default ? "YES" : "NO"); > + avio_printf(out, ",NAME=\"audio_%d\",", name_id); > + if (is_default) { > + avio_printf(out, "DEFAULT=YES,"); > + } Unnecessary braces, > + if (autoselect) { > + avio_printf(out, "AUTOSELECT=YES,"); > + } Unnecessary braces, > if (language) { > avio_printf(out, "LANGUAGE=\"%s\",", language); > } Unnecessary braces, > @@ -57,13 +64,23 @@ void ff_hls_write_audio_rendition(AVIOContext *out, > const char *agroup, > > void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, > const char *filename, const char > *language, > - int name_id, int is_default) > + int name_id, int is_default, > + int autoselect, int forced) > { > if (!out || !filename) > return; > > avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", > sgroup); > - avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, > is_default ? "YES" : "NO"); > + avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); > + if (is_default) { > + avio_printf(out, "DEFAULT=YES,"); > + } Unnecessary braces, > + if (autoselect) { > + avio_printf(out, "AUTOSELECT=YES,"); > + } Unnecessary braces, > + if (forced) { > + avio_printf(out, "FORCED=YES,"); > + } Unnecessary braces, > if (language) { > avio_printf(out, "LANGUAGE=\"%s\",", language); > } > diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h > index d7aa44d8dc..41e640a09a 100644 > --- a/libavformat/hlsplaylist.h > +++ b/libavformat/hlsplaylist.h > @@ -38,10 +38,12 @@ typedef enum { > void ff_hls_write_playlist_version(AVIOContext *out, int version); > void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, > const char *filename, const char > *language, > - int name_id, int is_default, int > nb_channels); > + int name_id, int is_default, > + int autoselect, int nb_channels); > void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, > const char *filename, const char > *language, > - int name_id, int is_default); > + int name_id, int is_default, > + int autoselect, int forced); > void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int > bandwidth, > int avg_bandwidth, > const char *filename, const char *agroup, > -- Thans Steven _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH v2] avformat/hls: Fixed incorrect behaviour of default 2024-07-07 10:18 ` Steven Liu @ 2024-07-08 13:43 ` CoderVenkat 2024-07-14 8:21 ` CoderVenkat 0 siblings, 1 reply; 9+ messages in thread From: CoderVenkat @ 2024-07-08 13:43 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Steven Liu [-- Attachment #1: Type: text/plain, Size: 72 bytes --] Hello, I have attached a patch with the requested changes. Thanks, vckt [-- Attachment #2: v2-0001-avformat-hls-Fixed-incorrect-behaviour-of-default.patch --] [-- Type: text/plain, Size: 10686 bytes --] From 5ac9b69d1c570eff4bc72ee4469874a9b182537d Mon Sep 17 00:00:00 2001 From: vckt <codervenkat@gmail.com> Date: Fri, 5 Jul 2024 18:51:32 +0530 Subject: [PATCH v2] avformat/hls: Fixed incorrect behaviour of default setting, added autoselect and forced In absence of defualt in var_stream_map, it was setting default=yes on every stream, but according to RFC8216 4.3.4.1 only one stream in a default group may have that. Additionally added support for autoselect=yes/no, whose presence combined with default means that it MUST be YES. Similarly forced=yes/no for subtitle stream. Showed sample output of incorrectness in bug #11088 Signed-off-by: vckt <codervenkat@gmail.com> --- libavformat/dashenc.c | 3 ++- libavformat/hlsenc.c | 47 +++++++++++++++++++++++++++++++++++---- libavformat/hlsplaylist.c | 26 +++++++++++++++------- libavformat/hlsplaylist.h | 6 +++-- 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index d4a6fe0304..898a227cbe 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1273,6 +1273,7 @@ static int write_manifest(AVFormatContext *s, int final) const char *audio_group = "A1"; char audio_codec_str[128] = "\0"; int is_default = 1; + int autoselect = 0; int max_audio_bitrate = 0; for (i = 0; i < s->nb_streams; i++) { @@ -1285,7 +1286,7 @@ static int write_manifest(AVFormatContext *s, int final) continue; get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); ff_hls_write_audio_rendition(c->m3u8_out, audio_group, - playlist_file, NULL, i, is_default, + playlist_file, NULL, i, is_default, autoselect, s->streams[i]->codecpar->ch_layout.nb_channels); max_audio_bitrate = FFMAX(st->codecpar->bit_rate + os->muxer_overhead, max_audio_bitrate); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 274de00f9a..86c1c9a274 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -184,6 +184,8 @@ typedef struct VariantStream { unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ int is_default; /* default status of audio group */ + int autoselect; /* autoselect by system language */ + int forced; /* forced status of subtitle stream */ const char *language; /* audio language name */ const char *agroup; /* audio group name */ const char *sgroup; /* subtitle group name */ @@ -1434,6 +1436,31 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(hls->m3u8_out, ",INSTREAM-ID=\"%s\"\n", ccs->instreamid); } + /* Check only one default is present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (vs->agroup && temp_vs->agroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); + goto fail; + } + } else if (vs->sgroup && temp_vs->sgroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->sgroup, temp_vs->sgroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an sgroup can not be default\n"); + goto fail; + } + } + } + } + } + /* 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]); @@ -1452,7 +1479,7 @@ static int create_master_playlist(AVFormatContext *s, if (vs->streams[j]->codecpar->ch_layout.nb_channels > nb_channels) nb_channels = vs->streams[j]->codecpar->ch_layout.nb_channels; - ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1, nb_channels); + ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, nb_channels); } /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ @@ -1533,7 +1560,7 @@ static int create_master_playlist(AVFormatContext *s, break; } - ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); + ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, vs->forced); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2032,6 +2059,8 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) int nb_varstreams = 0, nb_streams; char *p, *q, *saveptr1, *saveptr2, *varstr, *keyval; const char *val; + const size_t strlen_yes = strlen("YES"); + const size_t strlen_1 = strlen("1"); /* used in multiple arguments */ /** * Expected format for var_stream_map string is as below: @@ -2100,10 +2129,20 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) vs->language = val; continue; } else if (av_strstart(keyval, "default:", &val)) { - vs->is_default = (!av_strncasecmp(val, "YES", strlen("YES")) || - (!av_strncasecmp(val, "1", strlen("1")))); + vs->is_default = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))); hls->has_default_key = 1; continue; + } else if (av_strstart(keyval, "autoselect:", &val)) { + vs->autoselect = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))) || + (hls->has_default_key && vs->is_default); + /* autoselect must = 1 if default = 1 */ + continue; + } else if (av_strstart(keyval, "forced:", &val)) { + vs->forced = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))); + continue; } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..094bb56689 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -39,16 +39,20 @@ void ff_hls_write_playlist_version(AVIOContext *out, int version) void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels) + int name_id, int is_default, + int autoselect, int nb_channels) { if (!out || !agroup || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", agroup); - avio_printf(out, ",NAME=\"audio_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); - if (language) { + avio_printf(out, ",NAME=\"audio_%d\",", name_id); + if (is_default) + avio_printf(out, "DEFAULT=YES,"); + if (autoselect) + avio_printf(out, "AUTOSELECT=YES,"); + if (language) avio_printf(out, "LANGUAGE=\"%s\",", language); - } if (nb_channels) { avio_printf(out, "CHANNELS=\"%d\",", nb_channels); } @@ -57,16 +61,22 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + int name_id, int is_default, + int autoselect, int forced) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); - avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); - if (language) { + avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); + if (is_default) + avio_printf(out, "DEFAULT=YES,"); + if (autoselect) + avio_printf(out, "AUTOSELECT=YES,"); + if (forced) + avio_printf(out, "FORCED=YES,"); + if (language) avio_printf(out, "LANGUAGE=\"%s\",", language); - } avio_printf(out, "URI=\"%s\"\n", filename); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..41e640a09a 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -38,10 +38,12 @@ typedef enum { void ff_hls_write_playlist_version(AVIOContext *out, int version); void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels); + int name_id, int is_default, + int autoselect, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default); + int name_id, int is_default, + int autoselect, int forced); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, -- 2.30.1.windows.1 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/hls: Fixed incorrect behaviour of default 2024-07-08 13:43 ` [FFmpeg-devel] [PATCH v2] avformat/hls: Fixed incorrect behaviour of default CoderVenkat @ 2024-07-14 8:21 ` CoderVenkat 2024-07-14 12:04 ` Steven Liu 0 siblings, 1 reply; 9+ messages in thread From: CoderVenkat @ 2024-07-14 8:21 UTC (permalink / raw) To: ffmpeg-devel Ping. Any chance you could take a look? I would like to submit another fix based on this. Thanks, vckt On 2024-07-08 19:13, CoderVenkat wrote: > Hello, > I have attached a patch with the requested changes. > Thanks, > vckt _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/hls: Fixed incorrect behaviour of default 2024-07-14 8:21 ` CoderVenkat @ 2024-07-14 12:04 ` Steven Liu 2024-07-14 15:16 ` [FFmpeg-devel] [PATCH v3] " CoderVenkat 0 siblings, 1 reply; 9+ messages in thread From: Steven Liu @ 2024-07-14 12:04 UTC (permalink / raw) To: FFmpeg development discussions and patches CoderVenkat <codervenkat@gmail.com> 于2024年7月14日周日 16:21写道: Hi Coder Venkat, > > Ping. > Any chance you could take a look? I would like to submit another fix based on this. @@ -1434,6 +1436,31 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(hls->m3u8_out, ",INSTREAM-ID=\"%s\"\n", ccs->instreamid); } + /* Check only one default is present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (vs->agroup && temp_vs->agroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); + goto fail; + } + } else if (vs->sgroup && temp_vs->sgroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->sgroup, temp_vs->sgroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an sgroup can not be default\n"); + goto fail; + } + } + } + } + } + /* 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]); @@ -1452,7 +1479,7 @@ static int create_master_playlist(AVFormatContext Can these logic be optimized? for example, audio in one for logic, subtitle in the other for logic. > Thanks, > vckt > Thanks Steven _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH v3] avformat/hls: Fixed incorrect behaviour of default 2024-07-14 12:04 ` Steven Liu @ 2024-07-14 15:16 ` CoderVenkat 2024-07-14 16:06 ` CoderVenkat 0 siblings, 1 reply; 9+ messages in thread From: CoderVenkat @ 2024-07-14 15:16 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Steven Liu [-- Attachment #1: Type: text/plain, Size: 160 bytes --] Hi, I separated both into different for loops, and changed the order of some checks so they aren't unnecessarily done. Attached patch to this mail. Thanks, vckt [-- Attachment #2: v3-0001-avformat-hls-Fixed-incorrect-behaviour-of-default.patch --] [-- Type: text/plain, Size: 10676 bytes --] From 1ccc029801699c21db2fad8e20ddfab226068c37 Mon Sep 17 00:00:00 2001 From: vckt <codervenkat@gmail.com> Date: Fri, 5 Jul 2024 18:51:32 +0530 Subject: [PATCH v3] avformat/hls: Fixed incorrect behaviour of default setting, added autoselect and forced In absence of defualt in var_stream_map, it was setting default=yes on every stream, but according to RFC8216 4.3.4.1 only one stream in a default group may have that. Additionally added support for autoselect=yes/no, whose presence combined with default means that it MUST be YES. Similarly forced=yes/no for subtitle stream. Showed sample output of incorrectness in bug #11088 Signed-off-by: vckt <codervenkat@gmail.com> --- libavformat/dashenc.c | 3 ++- libavformat/hlsenc.c | 47 +++++++++++++++++++++++++++++++++++---- libavformat/hlsplaylist.c | 26 +++++++++++++++------- libavformat/hlsplaylist.h | 6 +++-- 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index d4a6fe0304..898a227cbe 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1273,6 +1273,7 @@ static int write_manifest(AVFormatContext *s, int final) const char *audio_group = "A1"; char audio_codec_str[128] = "\0"; int is_default = 1; + int autoselect = 0; int max_audio_bitrate = 0; for (i = 0; i < s->nb_streams; i++) { @@ -1285,7 +1286,7 @@ static int write_manifest(AVFormatContext *s, int final) continue; get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); ff_hls_write_audio_rendition(c->m3u8_out, audio_group, - playlist_file, NULL, i, is_default, + playlist_file, NULL, i, is_default, autoselect, s->streams[i]->codecpar->ch_layout.nb_channels); max_audio_bitrate = FFMAX(st->codecpar->bit_rate + os->muxer_overhead, max_audio_bitrate); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 274de00f9a..86c1c9a274 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -184,6 +184,8 @@ typedef struct VariantStream { unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ int is_default; /* default status of audio group */ + int autoselect; /* autoselect by system language */ + int forced; /* forced status of subtitle stream */ const char *language; /* audio language name */ const char *agroup; /* audio group name */ const char *sgroup; /* subtitle group name */ @@ -1434,6 +1436,31 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(hls->m3u8_out, ",INSTREAM-ID=\"%s\"\n", ccs->instreamid); } + /* Check only one default is present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (vs->agroup && temp_vs->agroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); + goto fail; + } + } else if (vs->sgroup && temp_vs->sgroup && + !vs->has_video && !temp_vs->has_video) { + if (!av_strcasecmp(vs->sgroup, temp_vs->sgroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an sgroup can not be default\n"); + goto fail; + } + } + } + } + } + /* 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]); @@ -1452,7 +1479,7 @@ static int create_master_playlist(AVFormatContext *s, if (vs->streams[j]->codecpar->ch_layout.nb_channels > nb_channels) nb_channels = vs->streams[j]->codecpar->ch_layout.nb_channels; - ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1, nb_channels); + ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, nb_channels); } /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ @@ -1533,7 +1560,7 @@ static int create_master_playlist(AVFormatContext *s, break; } - ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); + ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, vs->forced); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2032,6 +2059,8 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) int nb_varstreams = 0, nb_streams; char *p, *q, *saveptr1, *saveptr2, *varstr, *keyval; const char *val; + const size_t strlen_yes = strlen("YES"); + const size_t strlen_1 = strlen("1"); /* used in multiple arguments */ /** * Expected format for var_stream_map string is as below: @@ -2100,10 +2129,20 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) vs->language = val; continue; } else if (av_strstart(keyval, "default:", &val)) { - vs->is_default = (!av_strncasecmp(val, "YES", strlen("YES")) || - (!av_strncasecmp(val, "1", strlen("1")))); + vs->is_default = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))); hls->has_default_key = 1; continue; + } else if (av_strstart(keyval, "autoselect:", &val)) { + vs->autoselect = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))) || + (hls->has_default_key && vs->is_default); + /* autoselect must = 1 if default = 1 */ + continue; + } else if (av_strstart(keyval, "forced:", &val)) { + vs->forced = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))); + continue; } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..094bb56689 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -39,16 +39,20 @@ void ff_hls_write_playlist_version(AVIOContext *out, int version) void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels) + int name_id, int is_default, + int autoselect, int nb_channels) { if (!out || !agroup || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", agroup); - avio_printf(out, ",NAME=\"audio_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); - if (language) { + avio_printf(out, ",NAME=\"audio_%d\",", name_id); + if (is_default) + avio_printf(out, "DEFAULT=YES,"); + if (autoselect) + avio_printf(out, "AUTOSELECT=YES,"); + if (language) avio_printf(out, "LANGUAGE=\"%s\",", language); - } if (nb_channels) { avio_printf(out, "CHANNELS=\"%d\",", nb_channels); } @@ -57,16 +61,22 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + int name_id, int is_default, + int autoselect, int forced) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); - avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); - if (language) { + avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); + if (is_default) + avio_printf(out, "DEFAULT=YES,"); + if (autoselect) + avio_printf(out, "AUTOSELECT=YES,"); + if (forced) + avio_printf(out, "FORCED=YES,"); + if (language) avio_printf(out, "LANGUAGE=\"%s\",", language); - } avio_printf(out, "URI=\"%s\"\n", filename); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..41e640a09a 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -38,10 +38,12 @@ typedef enum { void ff_hls_write_playlist_version(AVIOContext *out, int version); void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels); + int name_id, int is_default, + int autoselect, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default); + int name_id, int is_default, + int autoselect, int forced); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, -- 2.45.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Fixed incorrect behaviour of default 2024-07-14 15:16 ` [FFmpeg-devel] [PATCH v3] " CoderVenkat @ 2024-07-14 16:06 ` CoderVenkat 2024-07-15 13:47 ` Steven Liu 0 siblings, 1 reply; 9+ messages in thread From: CoderVenkat @ 2024-07-14 16:06 UTC (permalink / raw) To: ffmpeg-devel [-- Attachment #1: Type: text/plain, Size: 45 bytes --] Apologies Correct file attached in this mail. [-- Attachment #2: v3-0001-avformat-hls-Fixed-incorrect-behaviour-of-default.patch --] [-- Type: text/plain, Size: 11126 bytes --] From 631bdac055935be6f2dfb7c6e227098dae62eb6e Mon Sep 17 00:00:00 2001 From: vckt <codervenkat@gmail.com> Date: Fri, 5 Jul 2024 18:51:32 +0530 Subject: [PATCH v3] avformat/hls: Fixed incorrect behaviour of default setting, added autoselect and forced In absence of defualt in var_stream_map, it was setting default=yes on every stream, but according to RFC8216 4.3.4.1 only one stream in a default group may have that. Additionally added support for autoselect=yes/no, whose presence combined with default means that it MUST be YES. Similarly forced=yes/no for subtitle stream. Showed sample output of incorrectness in bug #11088 Signed-off-by: vckt <codervenkat@gmail.com> --- libavformat/dashenc.c | 3 +- libavformat/hlsenc.c | 60 ++++++++++++++++++++++++++++++++++++--- libavformat/hlsplaylist.c | 26 +++++++++++------ libavformat/hlsplaylist.h | 6 ++-- 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index d4a6fe0304..898a227cbe 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1273,6 +1273,7 @@ static int write_manifest(AVFormatContext *s, int final) const char *audio_group = "A1"; char audio_codec_str[128] = "\0"; int is_default = 1; + int autoselect = 0; int max_audio_bitrate = 0; for (i = 0; i < s->nb_streams; i++) { @@ -1285,7 +1286,7 @@ static int write_manifest(AVFormatContext *s, int final) continue; get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); ff_hls_write_audio_rendition(c->m3u8_out, audio_group, - playlist_file, NULL, i, is_default, + playlist_file, NULL, i, is_default, autoselect, s->streams[i]->codecpar->ch_layout.nb_channels); max_audio_bitrate = FFMAX(st->codecpar->bit_rate + os->muxer_overhead, max_audio_bitrate); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 274de00f9a..ac4f48d36c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -184,6 +184,8 @@ typedef struct VariantStream { unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ int is_default; /* default status of audio group */ + int autoselect; /* autoselect by system language */ + int forced; /* forced status of subtitle stream */ const char *language; /* audio language name */ const char *agroup; /* audio group name */ const char *sgroup; /* subtitle group name */ @@ -1434,6 +1436,44 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(hls->m3u8_out, ",INSTREAM-ID=\"%s\"\n", ccs->instreamid); } + /* Check only one default audio stream is present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + if (vs->agroup && !vs->has_video) { + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (temp_vs->agroup && !temp_vs->has_video) { + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); + goto fail; + } + } + } + } + } + } + + /* Check only one default subtitle stream present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + if (vs->sgroup && !vs->has_video) { + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (temp_vs->sgroup && !temp_vs->has_video) { + if (!av_strcasecmp(vs->sgroup, temp_vs->sgroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an sgroup can not be default\n"); + goto fail; + } + } + } + } + } + } + /* 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]); @@ -1452,7 +1492,7 @@ static int create_master_playlist(AVFormatContext *s, if (vs->streams[j]->codecpar->ch_layout.nb_channels > nb_channels) nb_channels = vs->streams[j]->codecpar->ch_layout.nb_channels; - ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1, nb_channels); + ff_hls_write_audio_rendition(hls->m3u8_out, vs->agroup, m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, nb_channels); } /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ @@ -1533,7 +1573,7 @@ static int create_master_playlist(AVFormatContext *s, break; } - ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); + ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 0, vs->autoselect, vs->forced); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2032,6 +2072,8 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) int nb_varstreams = 0, nb_streams; char *p, *q, *saveptr1, *saveptr2, *varstr, *keyval; const char *val; + const size_t strlen_yes = strlen("YES"); + const size_t strlen_1 = strlen("1"); /* used in multiple arguments */ /** * Expected format for var_stream_map string is as below: @@ -2100,10 +2142,20 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) vs->language = val; continue; } else if (av_strstart(keyval, "default:", &val)) { - vs->is_default = (!av_strncasecmp(val, "YES", strlen("YES")) || - (!av_strncasecmp(val, "1", strlen("1")))); + vs->is_default = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))); hls->has_default_key = 1; continue; + } else if (av_strstart(keyval, "autoselect:", &val)) { + vs->autoselect = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))) || + (hls->has_default_key && vs->is_default); + /* autoselect must = 1 if default = 1 */ + continue; + } else if (av_strstart(keyval, "forced:", &val)) { + vs->forced = (!av_strncasecmp(val, "YES", strlen_yes) || + (!av_strncasecmp(val, "1", strlen_1))); + continue; } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..094bb56689 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -39,16 +39,20 @@ void ff_hls_write_playlist_version(AVIOContext *out, int version) void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels) + int name_id, int is_default, + int autoselect, int nb_channels) { if (!out || !agroup || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", agroup); - avio_printf(out, ",NAME=\"audio_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); - if (language) { + avio_printf(out, ",NAME=\"audio_%d\",", name_id); + if (is_default) + avio_printf(out, "DEFAULT=YES,"); + if (autoselect) + avio_printf(out, "AUTOSELECT=YES,"); + if (language) avio_printf(out, "LANGUAGE=\"%s\",", language); - } if (nb_channels) { avio_printf(out, "CHANNELS=\"%d\",", nb_channels); } @@ -57,16 +61,22 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + int name_id, int is_default, + int autoselect, int forced) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); - avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); - if (language) { + avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); + if (is_default) + avio_printf(out, "DEFAULT=YES,"); + if (autoselect) + avio_printf(out, "AUTOSELECT=YES,"); + if (forced) + avio_printf(out, "FORCED=YES,"); + if (language) avio_printf(out, "LANGUAGE=\"%s\",", language); - } avio_printf(out, "URI=\"%s\"\n", filename); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..41e640a09a 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -38,10 +38,12 @@ typedef enum { void ff_hls_write_playlist_version(AVIOContext *out, int version); void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, - int name_id, int is_default, int nb_channels); + int name_id, int is_default, + int autoselect, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default); + int name_id, int is_default, + int autoselect, int forced); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, -- 2.30.1.windows.1 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Fixed incorrect behaviour of default 2024-07-14 16:06 ` CoderVenkat @ 2024-07-15 13:47 ` Steven Liu 2024-07-16 10:59 ` Steven Liu 0 siblings, 1 reply; 9+ messages in thread From: Steven Liu @ 2024-07-15 13:47 UTC (permalink / raw) To: FFmpeg development discussions and patches CoderVenkat <codervenkat@gmail.com> 于2024年7月15日周一 00:07写道: > > Apologies > Correct file attached in this mail._______________________________________________ I need more time look at the deep for and if logic. Thanks Steven _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Fixed incorrect behaviour of default 2024-07-15 13:47 ` Steven Liu @ 2024-07-16 10:59 ` Steven Liu 0 siblings, 0 replies; 9+ messages in thread From: Steven Liu @ 2024-07-16 10:59 UTC (permalink / raw) To: FFmpeg development discussions and patches Steven Liu <lingjiujianke@gmail.com> 于2024年7月15日周一 21:47写道: > > CoderVenkat <codervenkat@gmail.com> 于2024年7月15日周一 00:07写道: > > > > Apologies > > Correct file attached in this mail._______________________________________________ > I need more time look at the deep for and if logic. Hi CoderVenkat, + /* Check only one default audio stream is present in a group */ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + if (vs->agroup && !vs->has_video) { + for (j = 0; j < hls->nb_varstreams; j++) { + if (i != j) { + temp_vs = &(hls->var_streams[j]); + if (temp_vs->agroup && !temp_vs->has_video) { + if (!av_strcasecmp(vs->agroup, temp_vs->agroup) && + vs->is_default && temp_vs->is_default) { + av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); + goto fail; + } + } + } + } + } + } Can this logic modify as bellow? int has_default = 0; for (i = 0; i < hls->nb_varstreams; i++) { vs = &(hls->var_streams[i]); if (vs->is_default == 1) has_default++; if (vs->agroup && !vs->has_video && has_default > 1) { av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be default\n"); has_default = 0; goto fail; } } has_default = 0; Thanks Steven _______________________________________________ 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". ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-07-16 11:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-07-05 13:27 [FFmpeg-devel] [PATCH] avformat/hls: Fixed incorrect behaviour of default setting, , added autoselect and forced CoderVenkat 2024-07-07 10:18 ` Steven Liu 2024-07-08 13:43 ` [FFmpeg-devel] [PATCH v2] avformat/hls: Fixed incorrect behaviour of default CoderVenkat 2024-07-14 8:21 ` CoderVenkat 2024-07-14 12:04 ` Steven Liu 2024-07-14 15:16 ` [FFmpeg-devel] [PATCH v3] " CoderVenkat 2024-07-14 16:06 ` CoderVenkat 2024-07-15 13:47 ` Steven Liu 2024-07-16 10:59 ` Steven Liu
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git