diff options
author | Jonathan Baecker <jonbae77@gmail.com> | 2024-09-28 23:30:12 +0200 |
---|---|---|
committer | Steven Liu <lq@chinaffmpeg.org> | 2024-10-13 23:01:59 +0800 |
commit | e6e9cb3ce74b48bd0f93f54df84440c4d6266c4d (patch) | |
tree | 6ad2101809170f16378786df6679340505978695 /libavformat | |
parent | c7cf0df4948cc0df8fed1c10252ab232898bb41c (diff) | |
download | ffmpeg-e6e9cb3ce74b48bd0f93f54df84440c4d6266c4d.tar.gz |
libavformat/hlsplaylist: add subtitle_varname for naming subtitle streams
If 'sname:*' is set in the var_stream_map variable, use it as
the NAME attribute for subtitles. This improves the naming of
subtitle streams in HTML players, providing clearer and more
descriptive labels for users.
Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/hlsenc.c | 7 | ||||
-rw-r--r-- | libavformat/hlsplaylist.c | 9 | ||||
-rw-r--r-- | libavformat/hlsplaylist.h | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index a0a2cc0bb3..8d81452264 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -189,6 +189,7 @@ typedef struct VariantStream { const char *sgroup; /* subtitle group name */ const char *ccgroup; /* closed caption group name */ const char *varname; /* variant name */ + const char *subtitle_varname; /* subtitle variant name */ } VariantStream; typedef struct ClosedCaptionsStream { @@ -1563,7 +1564,8 @@ 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, + vs->subtitle_varname, i, hls->has_default_key ? vs->is_default : 1); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2137,6 +2139,9 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; + } else if (av_strstart(keyval, "sname:", &val)) { + vs->subtitle_varname = val; + continue; } else if (av_strstart(keyval, "agroup:", &val)) { vs->agroup = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..3412dce423 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -57,13 +57,18 @@ 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) + const char *sname, int name_id, int is_default) { 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 (sname) { + avio_printf(out, ",NAME=\"%s\",", sname); + } else { + avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); + } + avio_printf(out, "DEFAULT=%s,", is_default ? "YES" : "NO"); if (language) { avio_printf(out, "LANGUAGE=\"%s\",", language); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..ec44e5a0ae 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -41,7 +41,7 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, int name_id, int is_default, 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); + const char *sname, int name_id, int is_default); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, |