From patchwork Thu May 20 10:01:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Przemys=C5=82aw_Sobala?= X-Patchwork-Id: 27843 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2302559iof; Thu, 20 May 2021 03:28:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnDmuvcsGgJvcqDTFY1SynhF1r0MicyeCNaKdzQolufwtTSOVtWgHKt4z0A3CGKCc+CtNy X-Received: by 2002:a05:6402:50b:: with SMTP id m11mr4327376edv.367.1621506501181; Thu, 20 May 2021 03:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621506501; cv=none; d=google.com; s=arc-20160816; b=hRofXYyEbloNFOk7jeyDNZIVdEHWAlR13H+No2xZhxm9GI6hYcuDwjxxSPvYEnLG7g 7pAyJCFv6ivJw4P3tSOlg3lWudiy5KB5zBuaOMNbZhAUNygcRJTXPWDZQcWg2TmdlrnB N5h0CT4GdoWejq/JDIwjIPme+j5LfPib5a+APQSbCwoPejwTjFYH63iyBzgEMTszcAKY YyciZFLFRQldJPAPntsxBaZM/LVqJSzZgzmoe34uBw/5M6CZJsgEDt9JS6Mojb0yTBOC TPmP9SZhhSIdecmXh+KboZXbt6sAASBLMs473grooswluOSsIGnQqfCTjMaRMuVdCw+8 r9WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:mime-version:user-agent:date :message-id:from:to:dkim-signature:delivered-to; bh=ThdOdUC45poryy+DfGlUG2enSyMEUUjkt2bOjcX+eIY=; b=tfJmAmdIM3cGBbgLrX2w3T4ccV2l77YLIo8o4lJaBzONPQatdVWsWKOSmlz4DiC+O1 ojNDloNZ/qR6F04NdFuXKjNyvyCvcdvFeRLVYUI6B4Cnc4abgwezRzIPcq04HDM4knmN Qhoxu7vum0hZ+ovT/SsFo0DAdKTQLxgTFhgkUzeEcp1d8rhZ19IJn70Q5NhOM+yHl2CQ pXg/5FiYm5VcBG3NFG8x0aLtu3FwRVtaN2/z7iedt4COdJ0I0qpM+BgBaOzl5nn1eik0 cvM6v+JSPKl1c/9ESmEi3lkJbcUmFz/o4VimjPW0+8JnKT/c3uqunCW5U5VQc/NJ+/YK Ihdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=vXxpKsHO; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s3si1079383edd.497.2021.05.20.03.28.20; Thu, 20 May 2021 03:28:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=vXxpKsHO; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A8FE3689902; Thu, 20 May 2021 13:28:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5831E680B74 for ; Thu, 20 May 2021 13:28:08 +0300 (EEST) Received: by mail-ed1-f49.google.com with SMTP id t15so18767870edr.11 for ; Thu, 20 May 2021 03:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=JlHYBUa7HeDIuL0Nr4R+3N3l0EL7LLcVrGs2nKetvCg=; b=vXxpKsHO7xaNrdzgIwZ1MxYXdnY/SuNXhA5riLRCC5bHLrV3PgiA+njH99x3mflsvF woCyGTIUXaiWJVvAFQPWoMopGdTN938g4RXjW3qdzCg7DYhjfv/Tn+KPPtNzyyNdRDGw IJ2HaY/uqan4QtVzryh0ZzvRLFnwAMF2cQ1Pwy1U5E9FjyepCGuyexKcQn9HRwBTrOob FlDgkV2Qg8LL82rdK4TiEdZBU+B9BJKyq58JKvVcCgOV4FJntI+avIMm748ZSJ8FmnNI mfLLMA8L6le0/5ChE8137NTBkgIHKXgWyGr4m+t4cG+iQ/SzDBTb6nVa/b4HawiSLQWV euBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=JlHYBUa7HeDIuL0Nr4R+3N3l0EL7LLcVrGs2nKetvCg=; b=VUPbLSi5FvgOsPiQTDZtSt6qfDRH/5x5hUMW+XN0+tNZUR8x5Li2XvDxT7OMqZSYzB P+yCwWUzrncuG0RGFSvYAVRNB/U1bQfMROaZ84tl18E6uBKiOtPYDsvt0b8SoZrhENVC e/DlD3M2vGmJGa/c0rFqFfdO6xMF5EGj5OcBHikI2zOz9FJ3A/r57LXerzB8QU7LtAB6 8J055rW9NYJPH8yNwzJB3/3AIOWGjrq9MansGqRX4XBqW4Q7FIGx37qOcSP2kiQ5TW1g DViMDOe99yK9tOl6yQG1EYj4Odmo2dDii5sMsM4+dUuEa3MtCZb+ONmrjjM77+PC+UQn WbYg== X-Gm-Message-State: AOAM533aTE/UQ7OpfOvwPbjYHDKq7Qfp5sgwR0d4aY95hzRiZcwPjwt3 AAppanJN7xDv+gvfSC0HKVzKovqrjTDbhA== X-Received: by 2002:a17:906:fc1e:: with SMTP id ov30mr3818821ejb.526.1621504915526; Thu, 20 May 2021 03:01:55 -0700 (PDT) Received: from [192.168.1.19] (83.8.212.159.ipv4.supernova.orange.pl. [83.8.212.159]) by smtp.gmail.com with ESMTPSA id me15sm1114682ejb.71.2021.05.20.03.01.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 May 2021 03:01:55 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org From: =?utf-8?q?Przemys=C5=82aw_Sobala?= Message-ID: Date: Thu, 20 May 2021 12:01:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] lavf/dashenc.c: Fix creating audio-only HLS playlists X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: T/eY0slvSlXw With audio/video HLS playlists, audio chunklists are treated as alternative renditions for video chunklists. This is wrong for audio-only HLS playlists. fixes: 9252 --- libavformat/dashenc.c | 137 ++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 53 deletions(-) if (c->master_playlist_created && (!c->master_publish_rate || @@ -1282,60 +1278,95 @@ static int write_manifest(AVFormatContext *s, int final) ff_hls_write_playlist_version(c->m3u8_out, 7); - for (i = 0; i < s->nb_streams; i++) { - char playlist_file[64]; - AVStream *st = s->streams[i]; - OutputStream *os = &c->streams[i]; - if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) - continue; - if (os->segment_type != SEGMENT_TYPE_MP4) - continue; - get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); - ff_hls_write_audio_rendition(c->m3u8_out, (char *)audio_group, - playlist_file, NULL, i, is_default); - 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))) { - if (strlen(audio_codec_str)) - av_strlcat(audio_codec_str, ",", sizeof(audio_codec_str)); - av_strlcat(audio_codec_str, os->codec_str, sizeof(audio_codec_str)); + if (c->has_video) { + // treat audio streams as alternative renditions for video streams + const char *audio_group = "A1"; + char audio_codec_str[128] = "\0"; + int is_default = 1; + int max_audio_bitrate = 0; + + for (i = 0; i < s->nb_streams; i++) { + char playlist_file[64]; + AVStream *st = s->streams[i]; + OutputStream *os = &c->streams[i]; + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) + continue; + if (os->segment_type != SEGMENT_TYPE_MP4) + continue; + get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); + ff_hls_write_audio_rendition(c->m3u8_out, (char *)audio_group, + playlist_file, NULL, i, is_default); + 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))) { + if (strlen(audio_codec_str)) + av_strlcat(audio_codec_str, ",", sizeof(audio_codec_str)); + av_strlcat(audio_codec_str, os->codec_str, sizeof(audio_codec_str)); + } + is_default = 0; } - is_default = 0; - } - for (i = 0; i < s->nb_streams; i++) { - char playlist_file[64]; - char codec_str[128]; - AVStream *st = s->streams[i]; - OutputStream *os = &c->streams[i]; - char *agroup = NULL; - char *codec_str_ptr = NULL; - int stream_bitrate = os->muxer_overhead; - if (os->bit_rate > 0) - stream_bitrate += os->bit_rate; - else if (final) - stream_bitrate += os->pos * 8 * AV_TIME_BASE / c->total_duration; - else if (os->first_segment_bit_rate > 0) - stream_bitrate += os->first_segment_bit_rate; - if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) - continue; - if (os->segment_type != SEGMENT_TYPE_MP4) - continue; - av_strlcpy(codec_str, os->codec_str, sizeof(codec_str)); - if (max_audio_bitrate) { - agroup = (char *)audio_group; - stream_bitrate += max_audio_bitrate; - av_strlcat(codec_str, ",", sizeof(codec_str)); - av_strlcat(codec_str, audio_codec_str, sizeof(codec_str)); + for (i = 0; i < s->nb_streams; i++) { + char playlist_file[64]; + char codec_str[128]; + AVStream *st = s->streams[i]; + OutputStream *os = &c->streams[i]; + char *agroup = NULL; + char *codec_str_ptr = NULL; + int stream_bitrate = os->muxer_overhead; + if (os->bit_rate > 0) + stream_bitrate += os->bit_rate; + else if (final) + stream_bitrate += os->pos * 8 * AV_TIME_BASE / c->total_duration; + else if (os->first_segment_bit_rate > 0) + stream_bitrate += os->first_segment_bit_rate; + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) + continue; + if (os->segment_type != SEGMENT_TYPE_MP4) + continue; + av_strlcpy(codec_str, os->codec_str, sizeof(codec_str)); + if (max_audio_bitrate) { + agroup = (char *)audio_group; + stream_bitrate += max_audio_bitrate; + av_strlcat(codec_str, ",", sizeof(codec_str)); + av_strlcat(codec_str, audio_codec_str, sizeof(codec_str)); + } + if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) { + codec_str_ptr = codec_str; + } + get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); + ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate, + playlist_file, agroup, + codec_str_ptr, NULL, NULL); } - if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) { - codec_str_ptr = codec_str; + + } else { + // treat audio streams as separate renditions + + for (i = 0; i < s->nb_streams; i++) { + char playlist_file[64]; + char codec_str[128]; + AVStream *st = s->streams[i]; + OutputStream *os = &c->streams[i]; + int stream_bitrate = os->muxer_overhead; + if (os->bit_rate > 0) + stream_bitrate += os->bit_rate; + else if (final) + stream_bitrate += os->pos * 8 * AV_TIME_BASE / c->total_duration; + else if (os->first_segment_bit_rate > 0) + stream_bitrate += os->first_segment_bit_rate; + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) + continue; + if (os->segment_type != SEGMENT_TYPE_MP4) + continue; + av_strlcpy(codec_str, os->codec_str, sizeof(codec_str)); + get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); + ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate, + playlist_file, NULL, + codec_str, NULL, NULL); } - get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); - ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate, - playlist_file, agroup, - codec_str_ptr, NULL, NULL); } + dashenc_io_close(s, &c->m3u8_out, temp_filename); if (use_rename) if ((ret = ff_rename(temp_filename, filename_hls, s)) < 0) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 07f191e2a2..c5da02840b 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1256,10 +1256,6 @@ static int write_manifest(AVFormatContext *s, int final) if (c->hls_playlist) { char filename_hls[1024]; - const char *audio_group = "A1"; - char audio_codec_str[128] = "\0"; - int is_default = 1; - int max_audio_bitrate = 0; // Publish master playlist only the configured rate