[FFmpeg-cvslog] avformat/hlsenc: Add CHANNELS to EXT-X-MEDIA for Audio
Dave Johansen
git at videolan.org
Sun Nov 12 10:45:09 EET 2023
ffmpeg | branch: master | Dave Johansen <davejohansen at gmail.com> | Thu Oct 26 19:43:59 2023 -0600| [39878fc50400f347075f75d1a0cbb77b16fb9c9d] | committer: Steven Liu
avformat/hlsenc: Add CHANNELS to EXT-X-MEDIA for Audio
Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=39878fc50400f347075f75d1a0cbb77b16fb9c9d
---
libavformat/dashenc.c | 3 ++-
libavformat/hlsenc.c | 8 +++++++-
libavformat/hlsplaylist.c | 5 ++++-
libavformat/hlsplaylist.h | 2 +-
4 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 96f4a5fbdf..15f700acbc 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1284,7 +1284,8 @@ 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,
+ s->streams[i]->codecpar->ch_layout.nb_channels);
max_audio_bitrate = FFMAX(st->codecpar->bit_rate +
os->muxer_overhead, max_audio_bitrate);
if (!av_strnstr(audio_codec_str, os->codec_str, sizeof(audio_codec_str))) {
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index fa2f3946e9..8c001a0d39 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1386,6 +1386,7 @@ static int create_master_playlist(AVFormatContext *s,
int is_file_proto = proto && !strcmp(proto, "file");
int use_temp_file = is_file_proto && ((hls->flags & HLS_TEMP_FILE) || hls->master_publish_rate);
char temp_filename[MAX_URL_SIZE];
+ int nb_channels;
input_vs->m3u8_created = 1;
if (!hls->master_m3u8_created) {
@@ -1434,8 +1435,13 @@ static int create_master_playlist(AVFormatContext *s,
av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n");
goto fail;
}
+ nb_channels = 0;
+ for (j = 0; j < vs->nb_streams; j++)
+ if (vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+ 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);
+ 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);
}
/* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/
diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c
index 2bf05f3c7c..4f35d0388f 100644
--- a/libavformat/hlsplaylist.c
+++ b/libavformat/hlsplaylist.c
@@ -39,7 +39,7 @@ 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 name_id, int is_default, int nb_channels)
{
if (!out || !agroup || !filename)
return;
@@ -49,6 +49,9 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup,
if (language) {
avio_printf(out, "LANGUAGE=\"%s\",", language);
}
+ if (nb_channels) {
+ avio_printf(out, "CHANNELS=\"%d\",", nb_channels);
+ }
avio_printf(out, "URI=\"%s\"\n", filename);
}
diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h
index 1928fe787d..c2744c227c 100644
--- a/libavformat/hlsplaylist.h
+++ b/libavformat/hlsplaylist.h
@@ -38,7 +38,7 @@ 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 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);
More information about the ffmpeg-cvslog
mailing list