Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Marton Balint <cus@passwd.hu>
To: ffmpeg-devel@ffmpeg.org
Cc: Marton Balint <cus@passwd.hu>
Subject: [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files
Date: Sat, 17 May 2025 01:08:58 +0200
Message-ID: <20250516231041.4640-1-cus@passwd.hu> (raw)

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 fftools/cmdutils.c   | 17 ++++++++++-------
 fftools/cmdutils.h   |  4 ++--
 fftools/ffmpeg_opt.c | 14 +++++++++-----
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index be21ed2c6c..e516ee6ebd 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -920,7 +920,7 @@ int read_yesno(void)
     return yesno;
 }
 
-FILE *get_preset_file(char *filename, size_t filename_size,
+FILE *get_preset_file(AVBPrint *filename,
                       const char *preset_name, int is_path,
                       const char *codec_name)
 {
@@ -936,8 +936,9 @@ FILE *get_preset_file(char *filename, size_t filename_size,
                             FFMPEG_DATADIR, };
 
     if (is_path) {
-        av_strlcpy(filename, preset_name, filename_size);
-        f = fopen_utf8(filename, "r");
+        av_bprintf(filename, "%s", preset_name);
+        if (av_bprint_is_complete(filename))
+            f = fopen_utf8(filename->str, "r");
     } else {
 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
         wchar_t *datadir_w = get_module_filename(NULL);
@@ -971,15 +972,17 @@ FILE *get_preset_file(char *filename, size_t filename_size,
         for (i = 0; i < 3 && !f; i++) {
             if (!base[i])
                 continue;
-            snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
+            av_bprint_clear(filename);
+            av_bprintf(filename, "%s%s/%s.ffpreset", base[i],
                      i != 1 ? "" : "/.ffmpeg", preset_name);
-            f = fopen_utf8(filename, "r");
+            f = fopen_utf8(filename->str, "r");
             if (!f && codec_name) {
-                snprintf(filename, filename_size,
+                av_bprint_clear(filename);
+                av_bprintf(filename,
                          "%s%s/%s-%s.ffpreset",
                          base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
                          preset_name);
-                f = fopen_utf8(filename, "r");
+                f = fopen_utf8(filename->str, "r");
             }
         }
     }
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index ad020f893a..216a2bcfe7 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -28,6 +28,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavfilter/avfilter.h"
 #include "libavformat/avformat.h"
+#include "libavutil/bprint.h"
 #include "libswscale/swscale.h"
 
 #ifdef _WIN32
@@ -495,13 +496,12 @@ int read_yesno(void);
  * codec_name-preset_name.avpreset in the above-mentioned directories.
  *
  * @param filename buffer where the name of the found filename is written
- * @param filename_size size in bytes of the filename buffer
  * @param preset_name name of the preset to search
  * @param is_path tell if preset_name is a filename path
  * @param codec_name name of the codec for which to look for the
  * preset, may be NULL
  */
-FILE *get_preset_file(char *filename, size_t filename_size,
+FILE *get_preset_file(AVBPrint *filename,
                       const char *preset_name, int is_path, const char *codec_name);
 
 /**
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 3d1efe32f9..aafacb8f1c 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -42,6 +42,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/avutil.h"
+#include "libavutil/bprint.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -1017,13 +1018,15 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
 {
     OptionsContext *o = optctx;
     FILE *f=NULL;
-    char filename[1000], line[1000], tmp_line[1000];
+    char line[1000], tmp_line[1000];
+    AVBPrint filename;
     const char *codec_name = NULL;
     int ret = 0;
 
     codec_name = opt_match_per_type_str(&o->codec_names, *opt);
+    av_bprint_init(&filename, 0, AV_BPRINT_SIZE_UNLIMITED);
 
-    if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
+    if (!(f = get_preset_file(&filename, arg, *opt == 'f', codec_name))) {
         if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
             av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
         }else
@@ -1039,11 +1042,11 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
         av_strlcpy(tmp_line, line, sizeof(tmp_line));
         if (!av_strtok(key,   "=",    &value) ||
             !av_strtok(value, "\r\n", &endptr)) {
-            av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
+            av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename.str, line);
             ret = AVERROR(EINVAL);
             goto fail;
         }
-        av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
+        av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename.str, key, value);
 
         if      (!strcmp(key, "acodec")) opt_audio_codec   (o, key, value);
         else if (!strcmp(key, "vcodec")) opt_video_codec   (o, key, value);
@@ -1051,7 +1054,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
         else if (!strcmp(key, "dcodec")) opt_data_codec    (o, key, value);
         else if (opt_default_new(o, key, value) < 0) {
             av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
-                   filename, line, key, value);
+                   filename.str, line, key, value);
             ret = AVERROR(EINVAL);
             goto fail;
         }
@@ -1059,6 +1062,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
 
 fail:
     fclose(f);
+    av_bprint_finalize(&filename, NULL);
 
     return ret;
 }
-- 
2.43.0

_______________________________________________
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".

             reply	other threads:[~2025-05-16 23:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-16 23:08 Marton Balint [this message]
2025-05-16 23:08 ` [FFmpeg-devel] [PATCH 2/4] fftools/cmdutils: factorize loading a file from the datadir Marton Balint
2025-05-16 23:09 ` [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories Marton Balint
2025-05-17  2:21   ` softworkz .
2025-05-17  9:13     ` Marton Balint
2025-05-17 17:22       ` softworkz .
2025-05-17 20:33         ` softworkz .
2025-05-16 23:09 ` [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression" Marton Balint
2025-06-14 14:43   ` Kacper Michajlow
2025-06-14 16:11     ` Marton Balint

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=20250516231041.4640-1-cus@passwd.hu \
    --to=cus@passwd.hu \
    --cc=ffmpeg-devel@ffmpeg.org \
    /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