From patchwork Wed Jun 26 10:57:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 50151 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ccd2:0:b0:482:c625:d099 with SMTP id q18csp346795vqv; Wed, 26 Jun 2024 03:57:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVl95xA+COHGFLl+EQR7h6r+70oX/bu+4a0cJJ71ssCCtVs9yfGAIoAfNobXW+zcqX5NRDFojEvrreOaTRDpr2IK2FyeFVb03iegg== X-Google-Smtp-Source: AGHT+IGxvGcxSOD/h954DkRRkXcwiVEJsw7YxKftbl+6Tp36mFH4nFG/V1gH/96qEbOzbKC2GPsE X-Received: by 2002:a17:906:b20b:b0:a72:8d40:52b8 with SMTP id a640c23a62f3a-a728d405f59mr79319566b.3.1719399470541; Wed, 26 Jun 2024 03:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719399470; cv=none; d=google.com; s=arc-20160816; b=QGX2to9qdD2tjIOxLe9kSZKZyjsV/KI7XHf8gbIwUDN8DV+ctpUZqoAWxEsf6qAW/R rZwGeAoX25H7FqxITlsYTA8qI49LNH11C4aew+aVMbG8PnaICKyPb+NKXpKpjOpKdded MsET1xMEGPxfMUlfNCxFgQGgdWftFo/wXxIHxHXeyNqeVOuvMx6SLi5wvjv31XKYcc34 7E5V317SBj4SB47je6QEC/ctCCHXm3Uag7A3ZllhELTovffRiXApG4Hw1CIRvMSQojZr f8TqGjKSMG9sTffcgzlrjPWRrR+6EDgPQMGJRiQB+MILtmx+WmXEoAOxkabjIK0HI9+R sCDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=SjKt+6AJIKmIqyfNVcCqz7FSm7Wn2/HYCxqVgVy/eao=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=JT7CBToAETxj0MoDM/QX1yJIkcD8IkFIhDx5fz0zn/kf3/+wW6HUUx6K7Gh90NQs2K 6Wixk2WZx9TAU0XUdoeRMxhihNXkTeIPuMKZM/df0HgEV7DfxXzS23DPC5z0IBLa8u9O d//+hZgoNT7sDiK1EYj+UwGP8SB/GF4Gi5EVIflooV+1qn6LbUNFo08nXvDJNgOtkm4v B/PIaKrwdTdk6TJy/B748oC65q/snJxGt/Jw5igQ/fVdwrD06Pw5K8JUxGRdJI53tKMP C6N18m6ezeoyjdpMkLkQVolp2jvL3jMH/+mpkcraIj0YyrnU32o21ygT67GWiZFdHTbQ Gw0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=awKV7y2c; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a711ec4caaesi448095966b.930.2024.06.26.03.57.49; Wed, 26 Jun 2024 03:57:50 -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=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=awKV7y2c; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD2FF68D57C; Wed, 26 Jun 2024 13:57:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C89568D26B for ; Wed, 26 Jun 2024 13:57:40 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52cdf579dd2so4064379e87.3 for ; Wed, 26 Jun 2024 03:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20230601.gappssmtp.com; s=20230601; t=1719399459; x=1720004259; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=w/JmEiku+UenKdtOzTbEM9LeDwd2twhQbA4B89VTa/Q=; b=awKV7y2cctBIbBDXTPhLVCTpJsMCgB335Btr5pcW8pdxVIuY9cTlpdkq1mYT2iX61m uJ6xc/dL0V8T6DKmkIkbPd7RMBQeZd+JkfSW2+mto6aM4IabJnSvz9tJBewl/W29IP8c r6bTSBZ5oQDU7apXapva4AHRVwqfEs+4egP6LLXIBMXRDiWB8OnVoRtAKGzn3u9H6ksT xqaypAxhFATdeVGeswfHGJT70D7VOB0x8LB1CBdmA1QMWokyAc3BrTjXhYzteJki5tg6 mhcIhHye4U2Ld7/RLM7TTH104qqVlAxuGLWU95nPjAtdK2GRz1laLOwyf4t/ydlPzjQM ykfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399459; x=1720004259; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w/JmEiku+UenKdtOzTbEM9LeDwd2twhQbA4B89VTa/Q=; b=H0Naw4S99QGR10rXXS7OvXXLjEtbOy0YiFCtmymBhgWB+AXPnMjJPXD47GrpthLEbR TgJIa2EDnWnc1o7MQhqB1q4AUbi6KjTgyfJAjxu0dIrfXuYQWCQ7zaWGSBh+UMZlSnzM GdMOMZoBrF5/XeerAnc8PrC8d5mYFw4mywKqpDkiSkLXQxeL6dcfuV5tHD1E3LrK6eib T6wFlxpbRfU0jPDlxW43nnndNpLDZg9dGOKvZw2pICx+m06WALjdGED4uLpTXNrtWajH E7yYQfjwmK5Ou6JAv1Kej67H+ByI1qriV/IXLx0pK/RPjTSwGMYagtQiwbgpLiwYW7hP 8Egw== X-Gm-Message-State: AOJu0YzK5ZW0soBpg+cD8kTnZacaOwuDTfhKQkv8gb23sfPnvA3B1Hks guc40ed20vlU5aPH5utQEVWF03iXCvJ+QcVAKWLYK1qoDWAGGtOxWAAXUxVUVuw7+8HrobXT4JU ttA== X-Received: by 2002:a05:6512:2245:b0:52d:9ad6:f57 with SMTP id 2adb3069b0e04-52d9ad610b2mr2171057e87.53.1719399459102; Wed, 26 Jun 2024 03:57:39 -0700 (PDT) Received: from localhost (host-114-191.parnet.fi. [77.234.114.191]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd94d7597sm1442590e87.284.2024.06.26.03.57.38 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Jun 2024 03:57:38 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jun 2024 13:57:34 +0300 Message-Id: <20240626105738.58427-1-martin@martin.st> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/5] hlsenc: Fix the return value accumulation in append_single_file 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uEYZHKIA8dQS Both the read_byte variable (which is accumulated into append_single_file) and the return value are int64_t; give the ret variable the right corresponding type too. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index f5c0243cf1..3d5eb47e84 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2380,7 +2380,7 @@ static int hls_init_file_resend(AVFormatContext *s, VariantStream *vs) static int64_t append_single_file(AVFormatContext *s, VariantStream *vs) { - int ret = 0; + int64_t ret = 0; int64_t read_byte = 0; int64_t total_size = 0; char *filename = NULL; From patchwork Wed Jun 26 10:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 50152 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ccd2:0:b0:482:c625:d099 with SMTP id q18csp346870vqv; Wed, 26 Jun 2024 03:58:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVIrah7fi1gtXPd0w8PRglVr5nePcfRrKM+QI8Hs90SA1OMMBtN8Nv/g8JYHLG4kjdxJCdIwnKAEvaWn75bQrVgSTIhC7DoUJAspw== X-Google-Smtp-Source: AGHT+IFkKpRi2lcPPpVSoawcviGO2GvK97n9H+kuLQm9bT6RjW08I+jGQ5fcYDUjFeWg/BO9IgKs X-Received: by 2002:aa7:c413:0:b0:57d:5286:b513 with SMTP id 4fb4d7f45d1cf-57d5286b544mr6103715a12.9.1719399480218; Wed, 26 Jun 2024 03:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719399480; cv=none; d=google.com; s=arc-20160816; b=Mr5Gvy1hymf8zdUXKVHA5MHW/nO/t4x6H7r3BxiYTLcNF+hQL8D3AGN1TsX7d2tTPh F3SQU2JxyT9k1/NUpgc0tv9ipDMQmhRTNqsdpCIH5hKPULfhKaAEVGqqceTougeryf8v 6E5xk9hxJxyEVaJf24KIZtXjez7XeS8TqI8HQFauDUKXH8MmzQJSjm8/i49io4Q8VjK8 dL3uIJtEkkBmeMJGiOV3ORlcR2LIsWCfu8Guku7oaOeMADF39LVKww8CJJmHmUhqmlZS eWy5EruRwTJv8TfWchMPtxYlzOQ+xQQkM8s8BoM+apj/zqCfEL90td1RT7Tbi2bPCB5N BErw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=ikK/Pgn4TpTfhmZF9gWUE/PVCrSOo9/JVaLyOmFMBd0=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=XzrOqDRUFaPaZupDCYPWYkrBRG1RqIICKP1aQbp+OUG8nBk9bXYdKUWVcT8GcQnIid NGrgQcA7YJK5umKrU/Lqk4dwyu446Wn8hbMvx6w7fDfN0rcU1UrLcFpEUY3KoQfWZgff ttMDjPZucEVQosL3F9lnaKqftjO7x0PK47OMiMaJ6N3KYavD/a3QSe0cW7aUEYrW3TFp 0dOpnjdxi3EANmxcTnWX6oi3xc/GY0a4yk0AmyW0DyJ+AkJT0RoZfjTc9esf+GM8svki 2TkmoXZROEFpivA2qTGVoPHtCXt717/RhH+JG9o2dhKTtSrmc8MOqaYPqP3eC5Kt5Kwr c8nw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=TDHOmNIh; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-57ddee90d2asi1878181a12.394.2024.06.26.03.57.59; Wed, 26 Jun 2024 03:58:00 -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=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=TDHOmNIh; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2FB436801F2; Wed, 26 Jun 2024 13:57:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D510668D3FA for ; Wed, 26 Jun 2024 13:57:40 +0300 (EEST) Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2ec52fbb50cso43208051fa.2 for ; Wed, 26 Jun 2024 03:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20230601.gappssmtp.com; s=20230601; t=1719399460; x=1720004260; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vY/mloxkuJevoJgPsdQohyCFyuLtyKYhXRL2Brwy7WA=; b=TDHOmNIhjIPZ2gkoAT2kSOVR8q544NnBulq+vKsdZ99UGKWSIBdVmBb4NilPB1NWAb YSfJbVFDwliFfZQSV8+PLFaMf3iXvVeIBXtPwZlenpr+9sureTAbvlgjUX0STDjJVSps tTCs24rbM0+eXW7hoOpmu/SeJS4sFoHxAtu4fU7OdJ8zLynSlRsACuA61apBCauujpmQ yoPMpDFUvaGUMEt1SPtEkB2RakLp+Tv3kwURRpiZ/t5cFm6DMsr1obFKJh/2EGlIk5+P 45mO3dzCJW2pcRz6GEtlzBmtjXItCMAIn1DgEvhDt5ApPV9H3vuJR1ZwPY2pnrWoKEkg RluQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399460; x=1720004260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vY/mloxkuJevoJgPsdQohyCFyuLtyKYhXRL2Brwy7WA=; b=FQ0YZx13VyN2KDO3LDX9idY+mY5PRlhZg8eiqhR2jKL/JubN3wy8ZF17jegUgDI7Nq qLiqsXtqMLQzRxguGtbuDRT4QcFZ+4cxP7+Zsg6MQs9H1K4pFOIK0tQGcc9MAeLWPSae yb3NjKzsRizvFc/TwB+6+oAzo799sqfijaznQqiPQkzdfRVSKdTViCQGzQ3CU+SJr4z2 1QXO/unSMzL4C1iRphGT1PDqhCoIsfwaQipZxx5gedsmARNIi5V3Hek6kY0aRflvTfZQ kO30EiD4X3D1uqHSGfFE+Z9ghtGH5GiQueGvc62odp4n+rrqReYaXxCWDHhehWpnb1V9 Oz0A== X-Gm-Message-State: AOJu0Yyf8PHIBN8hpLBwoo5RhwfTUTBYLK5jm+0pFVtDXsGqSVUCbC1u MgvjwHlGXHxe6bF/ZLXcXpL8kxVx3SQfbdn30fxNsQwIUYRy293oq7aJ9CA8GtfeW2tEZDUXKg8 YDw== X-Received: by 2002:a2e:8792:0:b0:2ec:4eca:748b with SMTP id 38308e7fff4ca-2ec5b2a011dmr55304001fa.14.1719399459820; Wed, 26 Jun 2024 03:57:39 -0700 (PDT) Received: from localhost (host-114-191.parnet.fi. [77.234.114.191]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ec520fc3b9sm12390621fa.114.2024.06.26.03.57.39 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Jun 2024 03:57:39 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jun 2024 13:57:35 +0300 Message-Id: <20240626105738.58427-2-martin@martin.st> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240626105738.58427-1-martin@martin.st> References: <20240626105738.58427-1-martin@martin.st> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/5] hlsenc: Fix setting vs->start_pos when not using HLS_SINGLE_FILE or hls_segment_size 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7J/z9w/UvPCH When not using HLS_SINGLE_FILE or hls_segment_size, we're writing each segment into a separate file. In that case, the file start pos for each segment will be zero. This matches the case in (hls->max_seg_size > 0) above, where we decide to switch to a new file. This fixes the calculation of "vs->size = new_start_pos - vs->start_pos" at the start of hls_write_packet; previously, start_pos would refer to the byte size of the previous segment file, giving vs->size entirely bogus values here. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 3d5eb47e84..0c72774e29 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2659,7 +2659,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) vs->start_pos = new_start_pos; } } else { - vs->start_pos = new_start_pos; + vs->start_pos = 0; sls_flag_file_rename(hls, vs, old_filename); ret = hls_start(s, vs); } From patchwork Wed Jun 26 10:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 50153 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ccd2:0:b0:482:c625:d099 with SMTP id q18csp346940vqv; Wed, 26 Jun 2024 03:58:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXWvMVAhbyrOdn7vRc5yCAko0UdWf1N8Yh3gSTK0FVD6vt3GRTCck6gmOoDxsv1/4+mnd/Y7P/lWgJWuyojebaeqOYZB21jag/dzw== X-Google-Smtp-Source: AGHT+IEZIdU9iZ/6IP4vaW2CcjvVqpcIxND4nnEY4kVKQUhl822FdOSEEF7MEXjRJcAgA9iKvX/Z X-Received: by 2002:a17:906:c009:b0:a6f:af31:6e7 with SMTP id a640c23a62f3a-a715f94b0f4mr742770166b.32.1719399489104; Wed, 26 Jun 2024 03:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719399489; cv=none; d=google.com; s=arc-20160816; b=B2pXQONFl+dQj4JwHrpAjx8XTkWQ0xqBI+HhleUXpq8uBtLxNqbaFDLbfVoVTxmeoS X0qzsXgpyFTDiH0702dKdIjPC4SzZNo38+uOjkywY5m6N8upOOsJuoEkflBMCyN7WHom DctvSGFkoICTVII8yVN5vnqT5mbeoX5GiNj3d4pr4VHpGXLhn/fTOWFzoXqqIai2nqna uGq7nx6P8y17981qd7LKuojG8zzw1OIDSxjR5QP1JrDavwJ+LwlVpUja9xgH5hTXfvgr tlGvP2itwwvrD8XvFOSBQKXlL2R80VezZvHG0F7Pfj609k/Mu435TGD8rfwjM/HIooHJ uzQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=xYivu8ZK21R5FvQcwvlkwCyEqXtqTPtf0GQD4hrfyXk=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=nREYMq1JWGuWy02G3+SL1IE4ciUlfdnxTu9l+s1BUbej66s0dcYOuzanezkFKxf3iN 2aUYK+PFycWkHNm8Yl4M9r7aDkMveFJp0U62ZPox6KVhfwdSycdgvDVxA9Vl4dOe0pga CGydGs8Z+oAj1X4NF+2BONUcYQB7u/1zXLHppDQVla/wqavRq2YWrJ4UXOXXbyrBNCVH K0Nk4H41xM5aVo0PlKjW7Zvx1LCRBFsvaZ+Kxh8CxtUoQKO8HINFq6MUIiXpi3ey3JuJ 639wN9JOaDEZccOGNuZhCW0tdnyciVzduHgT6MwfijHSBpSPmHm+ENt+Dmm1CQlrGRgG mZbA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=j19kgrTl; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a724675aa28si137432066b.526.2024.06.26.03.58.08; Wed, 26 Jun 2024 03:58:09 -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=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=j19kgrTl; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3BBFD68D40C; Wed, 26 Jun 2024 13:57:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 49A9068D3FA for ; Wed, 26 Jun 2024 13:57:41 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-52cdf579dd2so4064397e87.3 for ; Wed, 26 Jun 2024 03:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20230601.gappssmtp.com; s=20230601; t=1719399460; x=1720004260; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OMs0vEqf329+Qt+4lRf4WpQ8bQgq0RZ+e/WiI3X0oU4=; b=j19kgrTl4Gz2olvRRHeQHBjaKu87m4tE1rqeT6a4tz9Y+8d5ARsjF9GMoGJa3fhknd Xm3/VZ7pacojc/drW+yC2a7K43h2cJBuGTlt4kzQG3vIVTMk3mPK/L4i1vEyqpWvwdzv crWCKekD5u+EPLBAXpypyzq+4JZlM0dZ3eX3isEVXnAEBjoENwFWvOH9/GV6ErzqKOce Yc3GwQBWx5W+eyWUDwOxrgSdgkZgwkOJgrhpSnb12Fi8qap0WoGvhsk6WZFsqHaN0Pdv d4UIwCsGsGhqrPJ7e8in965WWipIH8MRcO2RvTvSqX1Rgs7LrO1Fsy3CiYjePUK6In9S Q3Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399460; x=1720004260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OMs0vEqf329+Qt+4lRf4WpQ8bQgq0RZ+e/WiI3X0oU4=; b=TeF61JQfm/CPDOYsMBXjxZ4GqgoJrs8Lqn9/jtyg8FVeA4Q/Lw0METgSKQA8G6vkFV aqIvPyeXAfgb70fLHsIAjym6ovHDLRpH8zRB7X0pNhz4gKldhq0wG3hEHawz8DYJvbwc kQUH1jkPryZX6bY5kpA5SNWeCp9zoa+MMYDgVkHV01nTwxnPfCGE05hZHWEShq2vjVj0 KxY4W9dE54mbQ0cwOYceZB6IIbdHeNPa0HDH/Kxsok1bOSs8XbqJHnaGETmBB3pczXmV DImhvTsBRjgtyXphudA2Z3x7TuVP+mBpHP6qD9/H+Id2j8kVLNfG7eNMRLeKXHn2Ro19 0AoQ== X-Gm-Message-State: AOJu0YyZ82kR1VUmLFMdDaEcsOf03wDiqI0Q9hyNPa5QeIUo3Y608aFC 1w8Gty/iNwXs2zXhdGSz7kGxy8jt21z/D8UOga/8RRSsEj4mD534b6QVb6h1/1e62Es5lmflJLw HdQ== X-Received: by 2002:a19:5f5a:0:b0:52c:c9b6:df0f with SMTP id 2adb3069b0e04-52cdf8260f2mr6971805e87.61.1719399460420; Wed, 26 Jun 2024 03:57:40 -0700 (PDT) Received: from localhost (host-114-191.parnet.fi. [77.234.114.191]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cebf46325sm574922e87.25.2024.06.26.03.57.40 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Jun 2024 03:57:40 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jun 2024 13:57:36 +0300 Message-Id: <20240626105738.58427-3-martin@martin.st> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240626105738.58427-1-martin@martin.st> References: <20240626105738.58427-1-martin@martin.st> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/5] hlsenc: Remove bogus check for if (vs->start_pos) for appending segments 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +7ShYVuGirjw Previously, vs->start_pos was never 0 here, unless using the -hls_segment_size option, which wasn't allowed for SEGMENT_TYPE_FMP4. Therefore, this if statement was practically always taken anyway. Remove this bogus if statement, to allow changing vs->start_pos to reflect the right value when not using the -hls_segment_size option. --- libavformat/hlsenc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 0c72774e29..e9aff1d0f7 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2504,6 +2504,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) end_pts, AV_TIME_BASE_Q) >= 0) { int64_t new_start_pos; int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size > 0); + double cur_duration; av_write_frame(oc, NULL); /* Flush any buffered data */ new_start_pos = avio_tell(oc->pb); @@ -2609,15 +2610,13 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(ENOMEM); } - if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) { - double cur_duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den; - ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size); - vs->end_pts = pkt->pts; - vs->duration = 0; - if (ret < 0) { - av_freep(&old_filename); - return ret; - } + cur_duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den; + ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size); + vs->end_pts = pkt->pts; + vs->duration = 0; + if (ret < 0) { + av_freep(&old_filename); + return ret; } // if we're building a VOD playlist, skip writing the manifest multiple times, and just wait until the end From patchwork Wed Jun 26 10:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 50155 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ccd2:0:b0:482:c625:d099 with SMTP id q18csp353109vqv; Wed, 26 Jun 2024 04:07:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWjWH1qzlF19g5aU2pU1oKFbuLz7pPmFeJvrOxqeFy8SEXHpQHbNuvgxqemz7orZiRGZiokE4sP70M24m599oWKDgD6xwBZVf13zQ== X-Google-Smtp-Source: AGHT+IG+y6ixDwXZDdkEF+l2olvx3ouaW33k4c9AUBCGB5dLbHEGjTqVpxJLB+Kl+NhjX9AG6hOO X-Received: by 2002:a2e:80da:0:b0:2ec:42a2:7e25 with SMTP id 38308e7fff4ca-2ec5619c255mr68475261fa.3.1719400078119; Wed, 26 Jun 2024 04:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719400078; cv=none; d=google.com; s=arc-20160816; b=ndFbkhXEEwEA61XBncHlf/p8dhrxX80I3e8uS4OK/jMhy6oZfv91x29ni2BZeT9I2U RyT25OVu2Pn3Y9xfPd3twSxrIo45dNJH4J9a9UxQUJqqdtnnp8hKvqBQMOUD3ATeKf+e VSofaqOqPjLsM5Sih5mTprfk3Fn3qpASUKBL+Qq1TrZFejxjBsDaKKf7t6gAqHCDwlb8 2udhbzvBtsVvRbuXOvEtqp4zFLubavlw2AEkm7f+qKyWlHrDLB4I5M9xwydKnL07Vme+ PzO/In5GCB8mwWl8JTzi+OV7o3a3mTmyPwX6+0qEhLULZHddjz5bppFZy1e5a4G803iD hG3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=xwSibuqXKwx6KayhxGWxh+gHQdSUg8q1K6UiTlTNtVc=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=ZKma8qDVdfg81abjieCs53a8UxvWfxc1c3W38p7KU+tliIa3lig7a6Jx2cINtRPbrH 7a2KcZorwznl0vvgM/alCMVB2rpOjBQW6CNDePN5u/LSlPaC08Vc2ZIPQNNRhg3bXtKk XSul4OuZZxOW74TvG7/tkEWSjTiiyn4eg8U0vdODbgMSZoxMqUkyPWMHA8hhI5Qe1tHl zuqMpja57sRkqoeqq+GKt3v1x4UCjOZQLXWyEr8H5MOuIsZLsFTtS7E9UPI/ezMz+K4R DV8mKiBtZdg1rnIGvKuRlz1YFkPiRmHv7Fbst9mMvIMAZf2l7AVWqk/ePDIcjWIPuZh+ 6Lrw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=UmGg6MAR; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2ec57816df8si24273031fa.509.2024.06.26.04.07.57; Wed, 26 Jun 2024 04:07:57 -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=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=UmGg6MAR; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4580C68D5B1; Wed, 26 Jun 2024 13:57:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD34D68D58B for ; Wed, 26 Jun 2024 13:57:41 +0300 (EEST) Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-52ce674da85so3415255e87.2 for ; Wed, 26 Jun 2024 03:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20230601.gappssmtp.com; s=20230601; t=1719399461; x=1720004261; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FgQ5qqOS1EsRuYY7hnMNz9SosuPY7CtN4YvUDaFPt28=; b=UmGg6MAR8QTg2DUpu/V3vTh9J+f/9Wngixs2D2KlwovuPgCAxTnfOjg1j6DhblWWJq a60tPcU3AUCHIJQRUo1bSw2n6trcyBKAZUv/fcZ+C9qs4PgU46LgWov2IHRssWeZnY/a hV2LubWNorCWyY8vj2FuGqOJEzAssreicxEGINSKXx5epUcNWSk/dcwHi0nwkBXWQtlA rR1sydM2gpDtEH2+5w5x8Ldd69PkSHxo7Yz2efeqgvkziwxUXSCmzl8Q245znxc91NrL JStSmquLgm4T+bz+zVBJPqB+JYDWas3os4RO62EvOwZhNb+Dre7QmL1T/Zi/AYLbb9Nv FLEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399461; x=1720004261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FgQ5qqOS1EsRuYY7hnMNz9SosuPY7CtN4YvUDaFPt28=; b=fjHTRD7Ng+p9MaadtXvrjgh8LgIOJuu1I9GdzqebfiT0NiW3YDHAzqWfLBgTwrk1FS TXJ9KqDlWHW6SUI30FltY0OgWP7RBpq6hWQLYXEzkVH7dn7mdo/ypE5RyEBQqg678umJ dM8Aw3g/zMQXUfYIQcBZD5Kp6HSeYzLqByPhlD+UtAJNLobO1ADnQ8cQOMU+xYG4oMdE z6l6dQ1DJB+bUiomgS307TnQ9oXui2t87xlIum8IC2oOaCSboq9scwrgbqVM3QH3cTZI gzHaKT11SFgW34Sx+BEbJfUQdHGO7olP01kurOkzzHpwyDRxQY9nPqdiDKt4Fw/ZpvSx OZ9g== X-Gm-Message-State: AOJu0YxOzBwEks0PwNDtirDG413jjMS0y7yshBrKrydyCF5+raDRG8T7 HHHT/9XJDpOSMbEV4VJmoCM4YFOPemb4NLqzG9SBynuY3tCrzzR7RL5tRV2/AaaB12WLpAZgacf XUQ== X-Received: by 2002:ac2:5588:0:b0:52c:e133:7b2e with SMTP id 2adb3069b0e04-52ce183b175mr6478641e87.35.1719399461075; Wed, 26 Jun 2024 03:57:41 -0700 (PDT) Received: from localhost (host-114-191.parnet.fi. [77.234.114.191]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ce8890c68sm742120e87.103.2024.06.26.03.57.40 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Jun 2024 03:57:40 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jun 2024 13:57:37 +0300 Message-Id: <20240626105738.58427-4-martin@martin.st> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240626105738.58427-1-martin@martin.st> References: <20240626105738.58427-1-martin@martin.st> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/5] hlsenc: When not using HLS_SINGLE_FILE, set vs->size to range_length 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jrwWdVkqusOZ This matches what is done in the corresponding case for HLS_SINGLE_FILE. Normally, vs->size is already initialized correctly - but when writing the initial segment, with mp4 files, vs->size has been set to the size of the init segment, while range_length contains the real size of the first segment. --- libavformat/hlsenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index e9aff1d0f7..7c8c886fc3 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2587,6 +2587,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) av_dict_free(&options); return ret; } + vs->size = range_length; ret = hlsenc_io_close(s, &vs->out, filename); if (ret < 0) { av_log(s, AV_LOG_WARNING, "upload segment failed," From patchwork Wed Jun 26 10:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 50154 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ccd2:0:b0:482:c625:d099 with SMTP id q18csp347123vqv; Wed, 26 Jun 2024 03:58:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVMbL5nFZkSWcCiis62ww6VOtJyC++4jaCJRW7atkYoWx6U2Vf5rKU8P3PriFFNbqekTWd9gV7+nMBnIsDxymqt5qFn5W8XrCjv1w== X-Google-Smtp-Source: AGHT+IE2PywM+V9JUL5vZZABCzE1h9WWEIJXYx+GdpeGZSGQExEDz5D0EGQVD7CvLbt/l1tsgQp5 X-Received: by 2002:a17:906:694b:b0:a6f:5815:f5e6 with SMTP id a640c23a62f3a-a7245b4cbabmr599908266b.8.1719399508258; Wed, 26 Jun 2024 03:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719399508; cv=none; d=google.com; s=arc-20160816; b=I6PmASX8/wKe1E0lSF58XXxBObq28nwRYp9aa9cXjEBwgBb5dlVR5vbfQjrjxbW3IA wmRMbapX07XRVdkeKLhvYGT/lN8ZGPG41ATDZCURX8ZBPgDSj9CE4UbqGNdHH2WNeQPG OnulsBWhe0nk5NZ4Z+3AGtzxfif0tw0RrxFbxIpgvF7o49+eQ1yjmhOe4UAbLtDfnpeV mX2TWrNpVy4PY2Ufx0A8bUW4PZV76s/pqWEhh8GwghjVTPnFFdyhD9UcJXH9woOEXPNG s11U7qYAC9pYODo0du3HQT2Vqj9MOooKQj+sZIYxQ6Kggpg3QlHkFgvG5DgOmdtN2fmY fR2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=n26gmJEyOoTwAu9akQs98ZfhLnCbLzsv8DlpqOeZ/Vs=; fh=w8JR1T/5WquwCqgnlKgniZcITMXOtCHDzF0NyyyGKZI=; b=O+qykhK+s26acnHutRtjtDmAnfnyvAItVi4gZ5OUZJ3kbV5zN8qsiQ7XxGTfY076Sg t1NcopILNXekypGu/DVjOsQY3/wIsQ35bKtYk6Y8PcZZeddrsAkPjHbHKScGwAt+i9PX 79AvqueHrRPwNNsTbneRe31d5FK4HPfmKUIFIyz0OMj55wKsCEIsL0r9lfn32JRbm4QL bacM/uz+O1X8jrlvxUTi31oAsFvG8Agrm9LLquC3/a9eAG7Nd97dhzH8p4hWdv+/6ylt 5h/LikFIpjx6pCKtMu8JGpvkx9mlpi7HzFeed+FXzqKzT+kQQaIHSdTCPDhCTv/r6H+/ vhlg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=X3gHE3tm; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a726759983dsi192728566b.380.2024.06.26.03.58.27; Wed, 26 Jun 2024 03:58:28 -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=@martin-st.20230601.gappssmtp.com header.s=20230601 header.b=X3gHE3tm; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5CDDB68D605; Wed, 26 Jun 2024 13:57:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BBB6668C0EB for ; Wed, 26 Jun 2024 13:57:43 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-52cecba8d11so2253092e87.1 for ; Wed, 26 Jun 2024 03:57:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20230601.gappssmtp.com; s=20230601; t=1719399463; x=1720004263; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jh2xkXJYfSr5TvV7RyKVBkBIu2R06kQHRKg9WaIJCKU=; b=X3gHE3tmP16qNW+FNmQ4I+NtFletAxIuDdBq50XfAaE8xdRVha5x8ld5CxOyDdtYod cGwHZmVpKWaSQ2B+6A4lkZnLJBeC47Y5vqUoyVF5S38hBOyQ1UT8IzKdtX2SajhwHLnX WXkjbtUlg8bEzd6HGeZCWKf9ZmxPeHhiyfhXajusSgpPHc3pwSM42XKtDzcRmTrsMXCk qIk8Ou+jz3gZBf7AGcqOJKeTks8rD19sxrPl9Ux2dLawsqcajvfi/SLfH2uftVVIzZVE p7XDnGa8Erq+dKnvZxvwsjXReF5BSGdImL++IjUpLNMjvrptWDI4fzE1jTeo8yXdlEX3 FGOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399463; x=1720004263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jh2xkXJYfSr5TvV7RyKVBkBIu2R06kQHRKg9WaIJCKU=; b=nKlNpG239vzeZ815hP/dFZLAAGBIvdqG88Jz6flGbettZdaOB9tEoQduGdG3CbjXtm 536tEo7gtMnzkmYGSq/T6TlYyrC4raAHm6eUpnH92y4WiiTekp7hqZ6QoCVO1sa3OHUB IuxrMtuw8+WPS7azYM89ynnbyZZtnDehHhnfO9g4/uydfCEaJeNF7b0D5Ovwa6QB+YiP sNuzbuOZYicZm7AW3AgpVPgtpGYmPuiQpLJrZkGfEj6G3V+o2LG4I8cVHGs/S49UsK2C WKZbhS0JZNwV9v0WGpfTIJsFTCRwZzw6JSR7kME0YzNkKcvlfXIsrG8y32UtpDoY7qe7 rDBg== X-Gm-Message-State: AOJu0YxHWDH8Sy4td2ZHIGMpQ8nrm6jnlKXHZcFno7zK3u0wJl8g8HKI 77M0XtYTbbk1UeAP04FUj3UdSw5JbbKKDkiPe2tsU+UD/3utxS0BAE4DnncdP6sbuIm7w3RoNpI ZjQ== X-Received: by 2002:a19:6b15:0:b0:52c:d085:9978 with SMTP id 2adb3069b0e04-52ce1864589mr6236545e87.62.1719399461700; Wed, 26 Jun 2024 03:57:41 -0700 (PDT) Received: from localhost (host-114-191.parnet.fi. [77.234.114.191]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd644c537sm1524670e87.281.2024.06.26.03.57.41 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Jun 2024 03:57:41 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jun 2024 13:57:38 +0300 Message-Id: <20240626105738.58427-5-martin@martin.st> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240626105738.58427-1-martin@martin.st> References: <20240626105738.58427-1-martin@martin.st> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/5] hlsenc: Calculate the average and actual maximum bitrate of segments 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: pw5dqJOtAK9y Previously, the bitrate advertised in the master playlist would only be based on the nominal values in either AVCodecParameters bit_rate, or via AVCPBProperties max_bitrate. On top of this, a fudge factor of 10% is added, to account for container overhead. Neither of these bitrates may be known, and if the encoder is running in VBR mode, there is no such value to be known. And the container overhead may be more or less than the given constant factor of 10%. Instead, calculate the maximum bitrate per segment based on what actually gets output from the muxer, and average bitrate across all segments. When muxing of the file finishes, update the master playlist with these values, exposing both the maximum (which previously was a guesstimate based on the nominal values) via EXT-X-STREAM-INF BANDWIDTH, and the average via EXT-X-STREAM-INF AVERAGE-BANDWIDTH. This makes it possible to use the hlsenc muxer with VBR encodes, for VOD style muxing. --- libavformat/dashenc.c | 4 ++-- libavformat/hlsenc.c | 47 ++++++++++++++++++++++++++++----------- libavformat/hlsplaylist.c | 3 +++ libavformat/hlsplaylist.h | 1 + 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 8c14aa746e..d4a6fe0304 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -1322,7 +1322,7 @@ static int write_manifest(AVFormatContext *s, int final) av_strlcat(codec_str, audio_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, + ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate, 0, playlist_file, agroup, codec_str, NULL, NULL); } @@ -1348,7 +1348,7 @@ static int write_manifest(AVFormatContext *s, int final) 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, + ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate, 0, playlist_file, NULL, codec_str, NULL, NULL); } diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 7c8c886fc3..511ae40f8f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -150,6 +150,11 @@ typedef struct VariantStream { int discontinuity; int reference_stream_index; + int64_t total_size; + double total_duration; + int64_t avg_bitrate; + int64_t max_bitrate; + HLSSegment *segments; HLSSegment *last_segment; HLSSegment *old_segments; @@ -1108,6 +1113,16 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, if (!en) return AVERROR(ENOMEM); + vs->total_size += size; + vs->total_duration += duration; + if (duration > 0) { + int cur_bitrate = (int)(8 * size / duration); + if (cur_bitrate > vs->max_bitrate) + vs->max_bitrate = cur_bitrate; + } + if (vs->total_duration > 0) + vs->avg_bitrate = (int)(8 * vs->total_size / vs->total_duration); + en->var_stream_idx = vs->var_stream_idx; ret = sls_flags_filename_process(s, hls, vs, en, duration, pos, size); if (ret < 0) { @@ -1362,14 +1377,15 @@ static int64_t get_stream_bit_rate(AVStream *stream) } static int create_master_playlist(AVFormatContext *s, - VariantStream * const input_vs) + VariantStream * const input_vs, + int final) { HLSContext *hls = s->priv_data; VariantStream *vs, *temp_vs; AVStream *vid_st, *aud_st; AVDictionary *options = NULL; unsigned int i, j; - int ret, bandwidth; + int ret, bandwidth, avg_bandwidth; const char *m3u8_rel_name = NULL; const char *vtt_m3u8_rel_name = NULL; const char *ccgroup; @@ -1389,8 +1405,8 @@ static int create_master_playlist(AVFormatContext *s, return 0; } else { /* Keep publishing the master playlist at the configured rate */ - if (&hls->var_streams[0] != input_vs || !hls->master_publish_rate || - input_vs->number % hls->master_publish_rate) + if ((&hls->var_streams[0] != input_vs || !hls->master_publish_rate || + input_vs->number % hls->master_publish_rate) && !final) return 0; } @@ -1480,12 +1496,17 @@ static int create_master_playlist(AVFormatContext *s, } } - bandwidth = 0; - if (vid_st) - bandwidth += get_stream_bit_rate(vid_st); - if (aud_st) - bandwidth += get_stream_bit_rate(aud_st); - bandwidth += bandwidth / 10; + if (final) { + bandwidth = vs->max_bitrate; + avg_bandwidth = vs->avg_bitrate; + } else { + bandwidth = 0; + if (vid_st) + bandwidth += get_stream_bit_rate(vid_st); + if (aud_st) + bandwidth += get_stream_bit_rate(aud_st); + bandwidth += bandwidth / 10; + } ccgroup = NULL; if (vid_st && vs->ccgroup) { @@ -1514,11 +1535,11 @@ static int create_master_playlist(AVFormatContext *s, } if (!hls->has_default_key || !hls->has_video_m3u8) { - ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, m3u8_rel_name, + ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, avg_bandwidth, m3u8_rel_name, aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup, sgroup); } else { if (vid_st) { - ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, m3u8_rel_name, + ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, avg_bandwidth, m3u8_rel_name, aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup, sgroup); } } @@ -1671,7 +1692,7 @@ fail: ff_rename(temp_vtt_filename, vs->vtt_m3u8_name, s); } if (ret >= 0 && hls->master_pl_name) - if (create_master_playlist(s, vs) < 0) + if (create_master_playlist(s, vs, last) < 0) av_log(s, AV_LOG_WARNING, "Master playlist creation failed\n"); return ret; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index 4f35d0388f..f8a6977702 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -71,6 +71,7 @@ void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, } void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, + int avg_bandwidth, const char *filename, const char *agroup, const char *codecs, const char *ccgroup, const char *sgroup) @@ -85,6 +86,8 @@ void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, } avio_printf(out, "#EXT-X-STREAM-INF:BANDWIDTH=%d", bandwidth); + if (avg_bandwidth) + avio_printf(out, ",AVERAGE-BANDWIDTH=%d", avg_bandwidth); if (st && st->codecpar->width > 0 && st->codecpar->height > 0) avio_printf(out, ",RESOLUTION=%dx%d", st->codecpar->width, st->codecpar->height); diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index c2744c227c..d7aa44d8dc 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -43,6 +43,7 @@ void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, 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, const char *codecs, const char *ccgroup, const char *sgroup);