From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id C0CBA4F781 for ; Mon, 23 Jun 2025 00:33:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 4B98168EDE0; Mon, 23 Jun 2025 03:32:59 +0300 (EEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 8ACD568A556 for ; Mon, 23 Jun 2025 03:32:52 +0300 (EEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-23636167afeso35503315ad.3 for ; Sun, 22 Jun 2025 17:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750638771; x=1751243571; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=RTByMUM1SLHIy1aRfJqoVufumebQf8LNEusBPk9cYPo=; b=FeOv3/oNS0RFVKEW9nhUJcrruz4QTXYFaaVcVIoUMJXcIT4pQLugk4YXhlBAFhUp/G 9LCmLzb0i6PJp4+crnAc20dB5QkRVq3N0VSOPPOGKtSq/r8GCtRbNR15nWyPioXpwoFH 3s6YadtIN71X0Y1vfCxefy+Oe80245Scd6rdVeJxul97yCT1KpTLnicX6AOsSxjWDzq8 XCBem1C0grMv1nWYqfeJtfQJLn5wO+SNyQdpYWw8URmm0Rc02ZIwLyWs5AF8FY48Hf8C W4uqBzFDps1XR4pOxKMG8LigTTgsyan32qB4JfFjsnt7cqMnKO7pJVaIsOzJzekEtv2u w73A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750638771; x=1751243571; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=RTByMUM1SLHIy1aRfJqoVufumebQf8LNEusBPk9cYPo=; b=WH7tw2WNDpmyMcQ7pjapFuqeJACRLmKTjoIVZ0s7n9Pj/elgt6V0uIx2OhcMCrfB7g JfLmkq+QmRinx3K7B0hA1Z6Y2DHcbGIrmwHQyEW+WZdyBt+7rEgF8X7YG/fmgv5NcXkK ckl59uiP2LOmWX/buvaVLJAEP/rTb5mOvM5kHki6IKEAKDvNFJ2qSyqDEU2B6znGLwoa DzSq7p5JAwZc2xlKkidXoUejh9tzsuWKr2/AcZ5aeRnOrJhxmmquGcaZG/gwmjjKxHJn NrgT34DMZrM4XQ7ctvBqWUCkCMv7Ezd/fMlvOHZbLZVmaYzzEfwmv/R1jktBO6rKqgtZ fnqA== X-Gm-Message-State: AOJu0YyglXvHJ5+t0F0DUx1s8XzxjajiXCSpgkfBbDjD5SWOFmPQfZHk OuJXhCrJEUV/y7rwBPvTWTbfTr/O/ubyaAPEB/FRIKNbIuG7mJ1UanTxusZXUA== X-Gm-Gg: ASbGnct3YvlMmCF10ZAKdXsvPRgDEQA37mCvXWQ489fBRs4ta2noOWIlbVDSliw59ng laSjIaHSwYMTUrXJ2RTATre3rtvqnexUFmPeVUZfpfhIWP0RZgVKGpUoziS0Nu4RolOZ8EcvHhq /6SghMxApxLCAfDITlnF5lfnj9d9l3hGSwED6/xpFT7XZBxzDWt4M8T/uBr2xEllRs5sUiHzgVn hWJF5Gzb4ey9BtMbqsIU9ZMn7nWZrZ668Kx3DT3V4crCb8Da4BWTO3Pn82/SpP5lI3hviZMt2Yb 2ISC4v4ELUMWdXzHgtRmFPhq5gNemKkqvuJ02R9pTPOnu738Iy+A2B89K/k2uMeXf1I4+uxT01B pgiYX X-Google-Smtp-Source: AGHT+IGkYlC1HbFcRjHfPYp2qQF2T9xI+fb4GYMK8HSnxLvLlTgutA8NRLmHkkY8Gjs8V4iESbHMcg== X-Received: by 2002:a17:903:1a83:b0:231:c9bb:60fd with SMTP id d9443c01a7336-237d9a74a5amr170359425ad.33.1750638770443; Sun, 22 Jun 2025 17:32:50 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d839348bsm69275975ad.44.2025.06.22.17.32.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jun 2025 17:32:49 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Mon, 23 Jun 2025 00:32:44 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3] avformat/hlsenc: Fix path handling for Windows 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: softworkz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: softworkz ..to allow playlist paths like: c:\hls\video1\master.m3u8 When base_output_dirname was determined, only '/' was searched for as path separator. get_relative_url() on the other hand searched for both forward and backward slash regardless of OS. Fix these issues by factorizing the separator finder function, only search for backslash for Windows/DOS and use that in both places. Reviewed-by: Marton Balint Signed-off-by: softworkz --- avformat/hlsenc: Some HLS improvements Includes only a single patch now: * Fix path handling on Windows Versions ======== V2 == * Fix path handling for Windows; * Keep using av_asprintf() with "%*s" to limit the length (as per review by Marton - thanks!) * Use int64:_t instead of int * Removed logging patches V3 == * Updated commit message * Don't compare null pointers * use ptrdiff_t (all as per review by Marton Balint - thanks!) . Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-97%2Fsoftworkz%2Fsubmit_hls_logging-v3 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-97/softworkz/submit_hls_logging-v3 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/97 Range-diff vs v2: 1: 93e1a502be ! 1: 485ffe85e9 avformat/hlsenc: Fix path handling for Windows @@ Metadata ## Commit message ## avformat/hlsenc: Fix path handling for Windows + ..to allow playlist paths like: + c:\hls\video1\master.m3u8 + + When base_output_dirname was determined, only '/' was searched for as + path separator. get_relative_url() on the other hand searched for both + forward and backward slash regardless of OS. + + Fix these issues by factorizing the separator finder function, only + search for backslash for Windows/DOS and use that in both places. + + Reviewed-by: Marton Balint Signed-off-by: softworkz ## libavformat/hlsenc.c ## @@ libavformat/hlsenc.c: static int hlsenc_io_close(AVFormatContext *s, AVIOContext return ret; } -+static int64_t get_last_separator_pos(const char *path) ++static ptrdiff_t get_last_separator_pos(const char *path) +{ + if (!path || *path == '\0') + return -1; @@ libavformat/hlsenc.c: static int hlsenc_io_close(AVFormatContext *s, AVIOContext + char *p = strrchr(path, '/'); +#if HAVE_DOS_PATHS + char *q = strrchr(path, '\\'); -+ p = FFMAX(p, q); ++ if (q) { ++ if (p) { ++ p = FFMAX(p, q); ++ } else { ++ p = q; ++ } ++ } +#endif + + if (!p) @@ libavformat/hlsenc.c: static int hlsenc_io_close(AVFormatContext *s, AVIOContext { int http_base_proto = ff_is_http_proto(s->url); @@ libavformat/hlsenc.c: static int hls_rename_temp_file(AVFormatContext *s, AVFormatContext *oc) + return ret; + } - static const char* get_relative_url(const char *master_url, const char *media_url) +-static const char* get_relative_url(const char *master_url, const char *media_url) ++static const char *get_relative_url(const char *master_url, const char *media_url) { - const char *p = strrchr(master_url, '/'); - size_t base_len = 0; - - if (!p) p = strrchr(master_url, '\\'); -+ int64_t pos = get_last_separator_pos(master_url); ++ ptrdiff_t pos = get_last_separator_pos(master_url); - if (p) { - base_len = p - master_url; @@ libavformat/hlsenc.c: static int hls_init(AVFormatContext *s) - char tmp = *(++p); - *p = '\0'; - vs->base_output_dirname = av_asprintf("%s%s", vs->m3u8_name, -+ int64_t pos = get_last_separator_pos(vs->m3u8_name); ++ ptrdiff_t pos = get_last_separator_pos(vs->m3u8_name); + if (pos >= 0) { + vs->base_output_dirname = av_asprintf("%.*s%s", pos + 1, vs->m3u8_name, vs->fmp4_init_filename); libavformat/hlsenc.c | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index a93d35ab75..7de6820ef7 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -329,6 +329,29 @@ static int hlsenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename) return ret; } +static ptrdiff_t get_last_separator_pos(const char *path) +{ + if (!path || *path == '\0') + return -1; + + char *p = strrchr(path, '/'); +#if HAVE_DOS_PATHS + char *q = strrchr(path, '\\'); + if (q) { + if (p) { + p = FFMAX(p, q); + } else { + p = q; + } + } +#endif + + if (!p) + return -1; + + return p - path; +} + static void set_http_options(AVFormatContext *s, AVDictionary **options, HLSContext *c) { int http_base_proto = ff_is_http_proto(s->url); @@ -1406,16 +1429,12 @@ static int hls_rename_temp_file(AVFormatContext *s, AVFormatContext *oc) return ret; } -static const char* get_relative_url(const char *master_url, const char *media_url) +static const char *get_relative_url(const char *master_url, const char *media_url) { - const char *p = strrchr(master_url, '/'); - size_t base_len = 0; - - if (!p) p = strrchr(master_url, '\\'); + ptrdiff_t pos = get_last_separator_pos(master_url); - if (p) { - base_len = p - master_url; - if (av_strncasecmp(master_url, media_url, base_len)) { + if (pos >= 0) { + if (av_strncasecmp(master_url, media_url, pos)) { av_log(NULL, AV_LOG_WARNING, "Unable to find relative url\n"); return NULL; } @@ -1423,7 +1442,7 @@ static const char* get_relative_url(const char *master_url, const char *media_ur return media_url; } - return media_url + base_len + 1; + return media_url + pos + 1; } static int64_t get_stream_bit_rate(AVStream *stream) @@ -3142,13 +3161,10 @@ static int hls_init(AVFormatContext *s) vs->fmp4_init_filename = expanded; } - p = strrchr(vs->m3u8_name, '/'); - if (p) { - char tmp = *(++p); - *p = '\0'; - vs->base_output_dirname = av_asprintf("%s%s", vs->m3u8_name, + ptrdiff_t pos = get_last_separator_pos(vs->m3u8_name); + if (pos >= 0) { + vs->base_output_dirname = av_asprintf("%.*s%s", pos + 1, vs->m3u8_name, vs->fmp4_init_filename); - *p = tmp; } else { vs->base_output_dirname = av_strdup(vs->fmp4_init_filename); } base-commit: f3bf5356966b4ad9334034e720fa224c2d9464a6 -- ffmpeg-codebot _______________________________________________ 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".