From: softworkz <ffmpegagent-at-gmail.com@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: softworkz <softworkz@hotmail.com> Subject: [FFmpeg-devel] [PATCH v2] avformat/hlsenc: Fix path handling for Windows Date: Sat, 14 Jun 2025 00:12:26 +0000 Message-ID: <pull.97.v2.ffstaging.FFmpeg.1749859946978.ffmpegagent@gmail.com> (raw) In-Reply-To: <pull.97.ffstaging.FFmpeg.1749835195.ffmpegagent@gmail.com> From: softworkz <softworkz@hotmail.com> Signed-off-by: softworkz <softworkz@hotmail.com> --- 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 . Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-97%2Fsoftworkz%2Fsubmit_hls_logging-v2 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-97/softworkz/submit_hls_logging-v2 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/97 Range-diff vs v1: 1: 58988164f2 < -: ---------- avformat/hlsenc: Log information about segments written 2: 1a4268d7e1 < -: ---------- avformat/hlsenc: Log InitFileComplete message 3: 99dfda2420 ! 1: 93e1a502be avformat/hlsenc: Fix path handling for Windows @@ libavformat/hlsenc.c: static int hlsenc_io_close(AVFormatContext *s, AVIOContext return ret; } -+static int get_last_separator_pos(const char *path) ++static int64_t get_last_separator_pos(const char *path) +{ + if (!path || *path == '\0') + return -1; @@ libavformat/hlsenc.c: static int hls_rename_temp_file(AVFormatContext *s, AVForm - size_t base_len = 0; - - if (!p) p = strrchr(master_url, '\\'); -+ int pos = get_last_separator_pos(master_url); ++ int64_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, -- vs->fmp4_init_filename); -- *p = tmp; -+ int pos = get_last_separator_pos(vs->m3u8_name); ++ int64_t pos = get_last_separator_pos(vs->m3u8_name); + if (pos >= 0) { -+ AVBPrint buf; -+ av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); -+ av_bprint_append_data(&buf, vs->m3u8_name, pos + 1); -+ av_bprintf(&buf, "%s", vs->fmp4_init_filename); -+ av_bprint_finalize(&buf, &vs->base_output_dirname); ++ 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); } libavformat/hlsenc.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index a93d35ab75..965ed9c1c0 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -329,6 +329,23 @@ static int hlsenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename) return ret; } +static int64_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, '\\'); + p = FFMAX(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); @@ -1408,14 +1425,10 @@ static int hls_rename_temp_file(AVFormatContext *s, AVFormatContext *oc) 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); - 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 +1436,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 +3155,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, + int64_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".
prev parent reply other threads:[~2025-06-14 0:12 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-06-13 17:19 [FFmpeg-devel] [PATCH 0/3] avformat/hlsenc: Some HLS improvements ffmpegagent 2025-06-13 17:19 ` [FFmpeg-devel] [PATCH 1/3] avformat/hlsenc: Log information about segments written softworkz 2025-06-13 21:02 ` Marton Balint 2025-06-13 23:31 ` softworkz . 2025-06-13 17:19 ` [FFmpeg-devel] [PATCH 2/3] avformat/hlsenc: Log InitFileComplete message softworkz 2025-06-13 17:19 ` [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Fix path handling for Windows softworkz 2025-06-13 21:36 ` Marton Balint 2025-06-13 23:34 ` softworkz . 2025-06-14 15:34 ` Marton Balint 2025-06-14 0:56 ` softworkz . 2025-06-14 0:12 ` softworkz [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=pull.97.v2.ffstaging.FFmpeg.1749859946978.ffmpegagent@gmail.com \ --to=ffmpegagent-at-gmail.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=softworkz@hotmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git