* [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files
@ 2025-05-16 23:08 Marton Balint
2025-05-16 23:08 ` [FFmpeg-devel] [PATCH 2/4] fftools/cmdutils: factorize loading a file from the datadir Marton Balint
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Marton Balint @ 2025-05-16 23:08 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 2/4] fftools/cmdutils: factorize loading a file from the datadir
2025-05-16 23:08 [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files Marton Balint
@ 2025-05-16 23:08 ` 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-16 23:09 ` [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression" Marton Balint
2 siblings, 0 replies; 10+ messages in thread
From: Marton Balint @ 2025-05-16 23:08 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
This changes the order of preset file loading slighly to be in line with the
documentation, because before the patch codec-prefixed presets were probed
before trying the next directory.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
fftools/cmdutils.c | 46 ++++++++++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index e516ee6ebd..1de670c2e4 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -920,9 +920,7 @@ int read_yesno(void)
return yesno;
}
-FILE *get_preset_file(AVBPrint *filename,
- const char *preset_name, int is_path,
- const char *codec_name)
+static FILE *get_datadir_file_fmt(AVBPrint *filename, const char *fmt, ...)
{
FILE *f = NULL;
int i;
@@ -935,11 +933,6 @@ FILE *get_preset_file(AVBPrint *filename,
env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
FFMPEG_DATADIR, };
- if (is_path) {
- 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);
base[2] = NULL;
@@ -969,21 +962,21 @@ FILE *get_preset_file(AVBPrint *filename,
}
}
#endif
+
+ {
+ va_list ap;
+
for (i = 0; i < 3 && !f; i++) {
if (!base[i])
continue;
av_bprint_clear(filename);
- av_bprintf(filename, "%s%s/%s.ffpreset", base[i],
- i != 1 ? "" : "/.ffmpeg", preset_name);
+ av_bprintf(filename, "%s%s/", base[i], i != 1 ? "" : "/.ffmpeg");
+ va_start(ap, fmt);
+ av_vbprintf(filename, fmt, ap);
+ va_end(ap);
+ if (!av_bprint_is_complete(filename))
+ break;
f = fopen_utf8(filename->str, "r");
- if (!f && codec_name) {
- 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->str, "r");
- }
}
}
@@ -995,6 +988,23 @@ FILE *get_preset_file(AVBPrint *filename,
return f;
}
+FILE *get_preset_file(AVBPrint *filename,
+ const char *preset_name, int is_path,
+ const char *codec_name)
+{
+ FILE *f = NULL;
+ if (is_path) {
+ av_bprintf(filename, "%s", preset_name);
+ if (av_bprint_is_complete(filename))
+ f = fopen_utf8(filename->str, "r");
+ } else {
+ f = get_datadir_file_fmt(filename, "%s.ffpreset", preset_name);
+ if (!f && codec_name)
+ f = get_datadir_file_fmt(filename, "%s%s/%s-%s.ffpreset", codec_name, preset_name);
+ }
+ return f;
+}
+
int cmdutils_isalnum(char c)
{
return (c >= '0' && c <= '9') ||
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories
2025-05-16 23:08 [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files Marton Balint
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 ` Marton Balint
2025-05-17 2:21 ` softworkz .
2025-05-16 23:09 ` [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression" Marton Balint
2 siblings, 1 reply; 10+ messages in thread
From: Marton Balint @ 2025-05-16 23:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
Similar to how it is done for ffpreset files. This allows the users to change
the HTML/CSS templates at will.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
Makefile | 2 +-
doc/ffmpeg.texi | 4 ++-
fftools/cmdutils.c | 48 +++++++++++++++++++++++++++++++++
fftools/cmdutils.h | 2 ++
fftools/graph/graphprint.c | 16 ++++++++---
fftools/textformat/tf_mermaid.h | 4 +--
6 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index e2250f6bc6..ebc50bb510 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ FFLIBS-$(CONFIG_SWSCALE) += swscale
FFLIBS := avutil
-DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset) $(SRC_PATH)/doc/ffprobe.xsd
+DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset) $(SRC_PATH)/doc/ffprobe.xsd $(SRC_PATH)/fftools/resources/graph.css $(SRC_PATH)/fftools/resources/graph.html
SKIPHEADERS = compat/w32pthreads.h
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 35675b5309..8edf188ab9 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1402,7 +1402,9 @@ Writes execution graph details to the specified file in the format set via -prin
@item -print_graphs_format @var{format} (@emph{global})
Sets the output format (available formats are: default, compact, csv, flat, ini, json, xml, mermaid, mermaidhtml)
-The default format is json.
+The default format is json. The mermarid and mermaidhtml formats need graph.css
+and graph.html resources which are searched in the FFMPEG data directories,
+similar to ffpreset files.
@item -progress @var{url} (@emph{global})
Send program-friendly progress information to @var{url}.
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 1de670c2e4..01e57d91e8 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1005,6 +1005,54 @@ FILE *get_preset_file(AVBPrint *filename,
return f;
}
+int file_read_from_datadir(const char *filename, char **outbuf)
+{
+ FILE *f;
+ char *buf = NULL;
+ long size;
+ AVBPrint bp;
+
+ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+ f = get_datadir_file_fmt(&bp, "%s", filename);
+ if (!f)
+ return AVERROR(errno);
+
+ if (fseek(f, 0, SEEK_END)) {
+ int ret = AVERROR(errno);
+ fclose(f);
+ return ret;
+ }
+
+ size = ftell(f);
+ if (size < 0 || size >= INT_MAX) {
+ fclose(f);
+ return AVERROR(EINVAL);
+ }
+
+ if (fseek(f, 0, SEEK_SET)) {
+ int ret = AVERROR(errno);
+ fclose(f);
+ return ret;
+ }
+
+ buf = av_malloc(size + 1);
+ if (!buf) {
+ fclose(f);
+ return AVERROR(ENOMEM);
+ }
+
+ if (fread(buf, 1, size, f) != size) {
+ fclose(f);
+ return AVERROR(EIO);
+ }
+ buf[size] = 0;
+
+ fclose(f);
+
+ *outbuf = buf;
+ return 0;
+}
+
int cmdutils_isalnum(char c)
{
return (c >= '0' && c <= '9') ||
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 216a2bcfe7..b324e5fc65 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -504,6 +504,8 @@ int read_yesno(void);
FILE *get_preset_file(AVBPrint *filename,
const char *preset_name, int is_path, const char *codec_name);
+int file_read_from_datadir(const char *filename, char **buf);
+
/**
* Realloc array to hold new_size elements of elem_size.
*
diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c
index fc94a75797..fbcb7f1b75 100644
--- a/fftools/graph/graphprint.c
+++ b/fftools/graph/graphprint.c
@@ -41,7 +41,6 @@
#include "libavutil/hwcontext.h"
#include "fftools/textformat/avtextformat.h"
#include "fftools/textformat/tf_mermaid.h"
-#include "fftools/resources/resman.h"
typedef enum {
SECTION_ID_ROOT,
@@ -935,10 +934,19 @@ static int init_graphprint(GraphPrintContext **pgpc, AVBPrint *target_buf)
}
if (!strcmp(text_formatter->name, "mermaid") || !strcmp(text_formatter->name, "mermaidhtml")) {
- gpc->diagram_config.diagram_css = ff_resman_get_string(FF_RESOURCE_GRAPH_CSS);
+ ret = file_read_from_datadir("graph.css", &gpc->diagram_config.diagram_css);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "graph.css needed for mermaid graph format cannot be opened: %s\n", av_err2str(ret));
+ goto fail;
+ }
- if (!strcmp(text_formatter->name, "mermaidhtml"))
- gpc->diagram_config.html_template = ff_resman_get_string(FF_RESOURCE_GRAPH_HTML);
+ if (!strcmp(text_formatter->name, "mermaidhtml")) {
+ ret = file_read_from_datadir("graph.html", &gpc->diagram_config.html_template);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "graph.html needed for mermaridhtml graph format cannot be opened: %s\n", av_err2str(ret));
+ goto fail;
+ }
+ }
av_diagram_init(tfc, &gpc->diagram_config);
}
diff --git a/fftools/textformat/tf_mermaid.h b/fftools/textformat/tf_mermaid.h
index 6e8f2a9b42..0b34d8ab20 100644
--- a/fftools/textformat/tf_mermaid.h
+++ b/fftools/textformat/tf_mermaid.h
@@ -28,8 +28,8 @@ typedef enum {
typedef struct AVDiagramConfig {
AVDiagramType diagram_type;
- const char *diagram_css;
- const char *html_template;
+ char *diagram_css;
+ char *html_template;
} AVDiagramConfig;
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression"
2025-05-16 23:08 [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files Marton Balint
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-16 23:09 ` Marton Balint
2025-06-14 14:43 ` Kacper Michajlow
2 siblings, 1 reply; 10+ messages in thread
From: Marton Balint @ 2025-05-16 23:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
This reverts commit 517a8055655798970d94a4c5ea912511362520ea.
Building resources directly in the ffmpeg util needs quite a bit of code,
increases binary size and makes it harder for the users to change those
resources at will.
The only user of this, the mermaid and mermaidhtml graph formats were converted
in an erlier commit to use file loading from the FFMPEG data dirs similar to
ffpreset files. Therefore the infrastucture to build resources directly into
ffmpeg CLI tools can be removed now.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
configure | 5 -
ffbuild/common.mak | 43 +------
fftools/Makefile | 5 +-
fftools/resources/.gitignore | 4 -
fftools/resources/Makefile | 13 --
fftools/resources/resman.c | 231 -----------------------------------
fftools/resources/resman.h | 50 --------
7 files changed, 3 insertions(+), 348 deletions(-)
delete mode 100644 fftools/resources/.gitignore
delete mode 100644 fftools/resources/Makefile
delete mode 100644 fftools/resources/resman.c
delete mode 100644 fftools/resources/resman.h
diff --git a/configure b/configure
index 0609dac4ab..2e69b3c56c 100755
--- a/configure
+++ b/configure
@@ -523,7 +523,6 @@ Developer options (useful when working on FFmpeg itself):
--enable-macos-kperf enable macOS kperf (private) API
--disable-large-tests disable tests that use a large amount of memory
--disable-ptx-compression don't compress CUDA PTX code even when possible
- --disable-resource-compression don't compress resources even when possible
--disable-version-tracking don't include the git/release version in the build
NOTE: Object files are built at the place where configure is launched.
@@ -2124,7 +2123,6 @@ CONFIG_LIST="
ossfuzz
pic
ptx_compression
- resource_compression
thumb
valgrind_backtrace
xmm_clobber_test
@@ -4181,7 +4179,6 @@ enable iamf
enable large_tests
enable optimizations
enable ptx_compression
-enable resource_compression
enable runtime_cpudetect
enable safe_bitstream_reader
enable static
@@ -6907,8 +6904,6 @@ EOF
enabled zlib_gzip && enabled gzip || disable ptx_compression
-enabled zlib_gzip && enabled gzip || disable resource_compression
-
# On some systems dynamic loading requires no extra linker flags
check_lib libdl dlfcn.h "dlopen dlsym" || check_lib libdl dlfcn.h "dlopen dlsym" -ldl
diff --git a/ffbuild/common.mak b/ffbuild/common.mak
index 0e1eb1f62b..ca45a0f368 100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@ -139,44 +139,6 @@ else
$(BIN2C) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<) $@ $(subst .,_,$(basename $(notdir $@)))
endif
-# 1) Preprocess CSS to a minified version
-%.css.min: %.css
- # Must start with a tab in the real Makefile
- sed 's!/\\*.*\\*/!!g' $< \
- | tr '\n' ' ' \
- | tr -s ' ' \
- | sed 's/^ //; s/ $$//' \
- > $@
-
-ifdef CONFIG_RESOURCE_COMPRESSION
-
-# 2) Gzip the minified CSS
-%.css.min.gz: %.css.min
- $(M)gzip -nc9 $< > $@
-
-# 3) Convert the gzipped CSS to a .c array
-%.css.c: %.css.min.gz $(BIN2CEXE)
- $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
-
-# 4) Gzip the HTML file (no minification needed)
-%.html.gz: %.html
- $(M)gzip -nc9 $< > $@
-
-# 5) Convert the gzipped HTML to a .c array
-%.html.c: %.html.gz $(BIN2CEXE)
- $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
-
-else # NO COMPRESSION
-
-# 2) Convert the minified CSS to a .c array
-%.css.c: %.css.min $(BIN2CEXE)
- $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
-
-# 3) Convert the plain HTML to a .c array
-%.html.c: %.html $(BIN2CEXE)
- $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
-endif
-
clean::
$(RM) $(BIN2CEXE) $(CLEANSUFFIXES:%=ffbuild/%)
@@ -229,10 +191,9 @@ SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
HOBJS = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
PTXOBJS = $(filter %.ptx.o,$(OBJS))
-RESOURCEOBJS = $(filter %.css.o %.html.o,$(OBJS))
$(HOBJS): CCFLAGS += $(CFLAGS_HEADERS)
checkheaders: $(HOBJS)
-.SECONDARY: $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=) $(RESOURCEOBJS:.o=.c) $(RESOURCEOBJS:%.css.o=%.css.min) $(RESOURCEOBJS:%.css.o=%.css.min.gz) $(RESOURCEOBJS:%.html.o=%.html.gz) $(RESOURCEOBJS:.o=)
+.SECONDARY: $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=)
alltools: $(TOOLS)
@@ -253,7 +214,7 @@ $(TOOLOBJS): | tools
OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS))
-CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *.html.gz *.html.c *.css.gz *.css.c *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
+CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
define RULES
diff --git a/fftools/Makefile b/fftools/Makefile
index 361a4fd574..57e3c0e518 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -9,8 +9,6 @@ AVBASENAMES = ffmpeg ffplay ffprobe
ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
-include $(SRC_PATH)/fftools/resources/Makefile
-
OBJS-ffmpeg += \
fftools/ffmpeg_dec.o \
fftools/ffmpeg_demux.o \
@@ -59,7 +57,7 @@ ifdef HAVE_GNU_WINDRES
OBJS-$(1) += fftools/fftoolsres.o
endif
$(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
-$$(OBJS-$(1)): | fftools fftools/textformat fftools/resources fftools/graph
+$$(OBJS-$(1)): | fftools fftools/textformat fftools/graph
$$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
$(1)$(PROGSSUF)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
$(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
@@ -73,7 +71,6 @@ all: $(AVPROGS)
fftools/ffprobe.o fftools/cmdutils.o: libavutil/ffversion.h | fftools
OUTDIRS += fftools
OUTDIRS += fftools/textformat
-OUTDIRS += fftools/resources
OUTDIRS += fftools/graph
ifdef AVPROGS
diff --git a/fftools/resources/.gitignore b/fftools/resources/.gitignore
deleted file mode 100644
index 5f496535a6..0000000000
--- a/fftools/resources/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-*.html.c
-*.css.c
-*.html.gz
-*.css.gz
diff --git a/fftools/resources/Makefile b/fftools/resources/Makefile
deleted file mode 100644
index 8579a52678..0000000000
--- a/fftools/resources/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-clean::
- $(RM) $(CLEANSUFFIXES:%=fftools/resources/%)
-
-vpath %.html $(SRC_PATH)
-vpath %.css $(SRC_PATH)
-
-# Uncomment to prevent deletion during build
-#.PRECIOUS: %.css.c %.css.min %.css.gz %.css.min.gz %.html.gz %.html.c
-
-OBJS-resman += \
- fftools/resources/resman.o \
- fftools/resources/graph.html.o \
- fftools/resources/graph.css.o \
diff --git a/fftools/resources/resman.c b/fftools/resources/resman.c
deleted file mode 100644
index a9e21626fa..0000000000
--- a/fftools/resources/resman.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2025 - softworkz
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * output writers for filtergraph details
- */
-
-#include "config.h"
-
-#include <string.h>
-
-#if CONFIG_RESOURCE_COMPRESSION
-#include <zlib.h>
-#endif
-
-#include "resman.h"
-#include "fftools/ffmpeg_filter.h"
-#include "libavutil/avassert.h"
-#include "libavutil/pixdesc.h"
-#include "libavutil/dict.h"
-#include "libavutil/common.h"
-
-extern const unsigned char ff_graph_html_data[];
-extern const unsigned int ff_graph_html_len;
-
-extern const unsigned char ff_graph_css_data[];
-extern const unsigned ff_graph_css_len;
-
-static const FFResourceDefinition resource_definitions[] = {
- [FF_RESOURCE_GRAPH_CSS] = { FF_RESOURCE_GRAPH_CSS, "graph.css", &ff_graph_css_data[0], &ff_graph_css_len },
- [FF_RESOURCE_GRAPH_HTML] = { FF_RESOURCE_GRAPH_HTML, "graph.html", &ff_graph_html_data[0], &ff_graph_html_len },
-};
-
-
-static const AVClass resman_class = {
- .class_name = "ResourceManager",
-};
-
-typedef struct ResourceManagerContext {
- const AVClass *class;
- AVDictionary *resource_dic;
-} ResourceManagerContext;
-
-static AVMutex mutex = AV_MUTEX_INITIALIZER;
-
-ResourceManagerContext *resman_ctx = NULL;
-
-
-#if CONFIG_RESOURCE_COMPRESSION
-
-static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in_len, char **out, size_t *out_len)
-{
- z_stream strm;
- unsigned chunk = 65534;
- int ret;
- uint8_t *buf;
-
- *out = NULL;
- memset(&strm, 0, sizeof(strm));
-
- // Allocate output buffer with extra byte for null termination
- buf = (uint8_t *)av_mallocz(chunk + 1);
- if (!buf) {
- av_log(ctx, AV_LOG_ERROR, "Failed to allocate decompression buffer\n");
- return AVERROR(ENOMEM);
- }
-
- // 15 + 16 tells zlib to detect GZIP or zlib automatically
- ret = inflateInit2(&strm, 15 + 16);
- if (ret != Z_OK) {
- av_log(ctx, AV_LOG_ERROR, "Error during zlib initialization: %s\n", strm.msg);
- av_free(buf);
- return AVERROR(ENOSYS);
- }
-
- strm.avail_in = in_len;
- strm.next_in = in;
- strm.avail_out = chunk;
- strm.next_out = buf;
-
- ret = inflate(&strm, Z_FINISH);
- if (ret != Z_OK && ret != Z_STREAM_END) {
- av_log(ctx, AV_LOG_ERROR, "Inflate failed: %d, %s\n", ret, strm.msg);
- inflateEnd(&strm);
- av_free(buf);
- return (ret == Z_STREAM_END) ? Z_OK : ((ret == Z_OK) ? Z_BUF_ERROR : ret);
- }
-
- if (strm.avail_out == 0) {
- // TODO: Error or loop decoding?
- av_log(ctx, AV_LOG_WARNING, "Decompression buffer may be too small\n");
- }
-
- *out_len = chunk - strm.avail_out;
- buf[*out_len] = 0; // Ensure null termination
-
- inflateEnd(&strm);
- *out = (char *)buf;
- return Z_OK;
-}
-#endif
-
-static ResourceManagerContext *get_resman_context(void)
-{
- ResourceManagerContext *res = resman_ctx;
-
- ff_mutex_lock(&mutex);
-
- if (res)
- goto end;
-
- res = av_mallocz(sizeof(ResourceManagerContext));
- if (!res) {
- av_log(NULL, AV_LOG_ERROR, "Failed to allocate resource manager context\n");
- goto end;
- }
-
- res->class = &resman_class;
- resman_ctx = res;
-
-end:
- ff_mutex_unlock(&mutex);
- return res;
-}
-
-
-void ff_resman_uninit(void)
-{
- ff_mutex_lock(&mutex);
-
- if (resman_ctx) {
- if (resman_ctx->resource_dic)
- av_dict_free(&resman_ctx->resource_dic);
- av_freep(&resman_ctx);
- }
-
- ff_mutex_unlock(&mutex);
-}
-
-
-char *ff_resman_get_string(FFResourceId resource_id)
-{
- ResourceManagerContext *ctx = get_resman_context();
- FFResourceDefinition resource_definition = { 0 };
- AVDictionaryEntry *dic_entry;
- char *res = NULL;
-
- if (!ctx)
- return NULL;
-
- for (unsigned i = 0; i < FF_ARRAY_ELEMS(resource_definitions); ++i) {
- FFResourceDefinition def = resource_definitions[i];
- if (def.resource_id == resource_id) {
- resource_definition = def;
- break;
- }
- }
-
- if (!resource_definition.name) {
- av_log(ctx, AV_LOG_ERROR, "Unable to find resource with ID %d\n", resource_id);
- return NULL;
- }
-
- ff_mutex_lock(&mutex);
-
- dic_entry = av_dict_get(ctx->resource_dic, resource_definition.name, NULL, 0);
-
- if (!dic_entry) {
- int dict_ret;
-
-#if CONFIG_RESOURCE_COMPRESSION
-
- char *out = NULL;
- size_t out_len;
-
- int ret = decompress_gzip(ctx, (uint8_t *)resource_definition.data, *resource_definition.data_len, &out, &out_len);
-
- if (ret) {
- av_log(NULL, AV_LOG_ERROR, "Unable to decompress the resource with ID %d\n", resource_id);
- goto end;
- }
-
- dict_ret = av_dict_set(&ctx->resource_dic, resource_definition.name, out, 0);
- if (dict_ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Failed to store decompressed resource in dictionary: %d\n", dict_ret);
- av_freep(&out);
- goto end;
- }
-
- av_freep(&out);
-#else
-
- dict_ret = av_dict_set(&ctx->resource_dic, resource_definition.name, (const char *)resource_definition.data, 0);
- if (dict_ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Failed to store resource in dictionary: %d\n", dict_ret);
- goto end;
- }
-
-#endif
- dic_entry = av_dict_get(ctx->resource_dic, resource_definition.name, NULL, 0);
-
- if (!dic_entry) {
- av_log(NULL, AV_LOG_ERROR, "Failed to retrieve resource from dictionary after storing it\n");
- goto end;
- }
- }
-
- res = dic_entry->value;
-
-end:
- ff_mutex_unlock(&mutex);
- return res;
-}
diff --git a/fftools/resources/resman.h b/fftools/resources/resman.h
deleted file mode 100644
index 6485db5091..0000000000
--- a/fftools/resources/resman.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2025 - softworkz
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef FFTOOLS_RESOURCES_RESMAN_H
-#define FFTOOLS_RESOURCES_RESMAN_H
-
-#include <stdint.h>
-
-#include "config.h"
-#include "fftools/ffmpeg.h"
-#include "libavutil/avutil.h"
-#include "libavutil/bprint.h"
-#include "fftools/textformat/avtextformat.h"
-
-typedef enum {
- FF_RESOURCE_GRAPH_CSS,
- FF_RESOURCE_GRAPH_HTML,
-} FFResourceId;
-
-typedef struct FFResourceDefinition {
- FFResourceId resource_id;
- const char *name;
-
- const unsigned char *data;
- const unsigned *data_len;
-
-} FFResourceDefinition;
-
-void ff_resman_uninit(void);
-
-char *ff_resman_get_string(FFResourceId resource_id);
-
-#endif /* FFTOOLS_RESOURCES_RESMAN_H */
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories
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
0 siblings, 1 reply; 10+ messages in thread
From: softworkz . @ 2025-05-17 2:21 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Marton Balint
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
> Balint
> Sent: Samstag, 17. Mai 2025 01:09
> To: ffmpeg-devel@ffmpeg.org
> Cc: Marton Balint <cus@passwd.hu>
> Subject: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and
> HTML resources from ffmpeg data directories
>
> Similar to how it is done for ffpreset files. This allows the users to change
> the HTML/CSS templates at will.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> Makefile | 2 +-
> doc/ffmpeg.texi | 4 ++-
> fftools/cmdutils.c | 48 +++++++++++++++++++++++++++++++++
> fftools/cmdutils.h | 2 ++
> fftools/graph/graphprint.c | 16 ++++++++---
> fftools/textformat/tf_mermaid.h | 4 +--
> 6 files changed, 68 insertions(+), 8 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index e2250f6bc6..ebc50bb510 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -32,7 +32,7 @@ FFLIBS-$(CONFIG_SWSCALE) += swscale
>
> FFLIBS := avutil
>
> -DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
> $(SRC_PATH)/doc/ffprobe.xsd
> +DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
> $(SRC_PATH)/doc/ffprobe.xsd $(SRC_PATH)/fftools/resources/graph.css
> $(SRC_PATH)/fftools/resources/graph.html
>
> SKIPHEADERS = compat/w32pthreads.h
>
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index 35675b5309..8edf188ab9 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -1402,7 +1402,9 @@ Writes execution graph details to the specified file in
> the format set via -prin
>
> @item -print_graphs_format @var{format} (@emph{global})
> Sets the output format (available formats are: default, compact, csv, flat,
> ini, json, xml, mermaid, mermaidhtml)
> -The default format is json.
> +The default format is json. The mermarid and mermaidhtml formats need
> graph.css
> +and graph.html resources which are searched in the FFMPEG data directories,
> +similar to ffpreset files.
>
> @item -progress @var{url} (@emph{global})
> Send program-friendly progress information to @var{url}.
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 1de670c2e4..01e57d91e8 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -1005,6 +1005,54 @@ FILE *get_preset_file(AVBPrint *filename,
> return f;
> }
>
> +int file_read_from_datadir(const char *filename, char **outbuf)
> +{
> + FILE *f;
> + char *buf = NULL;
> + long size;
> + AVBPrint bp;
> +
> + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> + f = get_datadir_file_fmt(&bp, "%s", filename);
> + if (!f)
> + return AVERROR(errno);
> +
> + if (fseek(f, 0, SEEK_END)) {
> + int ret = AVERROR(errno);
> + fclose(f);
> + return ret;
> + }
> +
> + size = ftell(f);
> + if (size < 0 || size >= INT_MAX) {
> + fclose(f);
> + return AVERROR(EINVAL);
> + }
> +
> + if (fseek(f, 0, SEEK_SET)) {
> + int ret = AVERROR(errno);
> + fclose(f);
> + return ret;
> + }
> +
> + buf = av_malloc(size + 1);
> + if (!buf) {
> + fclose(f);
> + return AVERROR(ENOMEM);
> + }
> +
> + if (fread(buf, 1, size, f) != size) {
> + fclose(f);
> + return AVERROR(EIO);
> + }
> + buf[size] = 0;
> +
> + fclose(f);
> +
> + *outbuf = buf;
> + return 0;
> +}
> +
> int cmdutils_isalnum(char c)
> {
> return (c >= '0' && c <= '9') ||
> diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
> index 216a2bcfe7..b324e5fc65 100644
> --- a/fftools/cmdutils.h
> +++ b/fftools/cmdutils.h
> @@ -504,6 +504,8 @@ int read_yesno(void);
> FILE *get_preset_file(AVBPrint *filename,
> const char *preset_name, int is_path, const char
> *codec_name);
>
> +int file_read_from_datadir(const char *filename, char **buf);
> +
> /**
> * Realloc array to hold new_size elements of elem_size.
> *
> diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c
> index fc94a75797..fbcb7f1b75 100644
> --- a/fftools/graph/graphprint.c
> +++ b/fftools/graph/graphprint.c
> @@ -41,7 +41,6 @@
> #include "libavutil/hwcontext.h"
> #include "fftools/textformat/avtextformat.h"
> #include "fftools/textformat/tf_mermaid.h"
> -#include "fftools/resources/resman.h"
>
> typedef enum {
> SECTION_ID_ROOT,
> @@ -935,10 +934,19 @@ static int init_graphprint(GraphPrintContext **pgpc,
> AVBPrint *target_buf)
> }
>
> if (!strcmp(text_formatter->name, "mermaid") || !strcmp(text_formatter-
> >name, "mermaidhtml")) {
> - gpc->diagram_config.diagram_css =
> ff_resman_get_string(FF_RESOURCE_GRAPH_CSS);
> + ret = file_read_from_datadir("graph.css", &gpc-
> >diagram_config.diagram_css);
> + if (ret < 0) {
> + av_log(NULL, AV_LOG_ERROR, "graph.css needed for mermaid graph
> format cannot be opened: %s\n", av_err2str(ret));
> + goto fail;
> + }
>
> - if (!strcmp(text_formatter->name, "mermaidhtml"))
> - gpc->diagram_config.html_template =
> ff_resman_get_string(FF_RESOURCE_GRAPH_HTML);
> + if (!strcmp(text_formatter->name, "mermaidhtml")) {
> + ret = file_read_from_datadir("graph.html", &gpc-
> >diagram_config.html_template);
> + if (ret < 0) {
> + av_log(NULL, AV_LOG_ERROR, "graph.html needed for
> mermaridhtml graph format cannot be opened: %s\n", av_err2str(ret));
> + goto fail;
> + }
> + }
>
> av_diagram_init(tfc, &gpc->diagram_config);
> }
> diff --git a/fftools/textformat/tf_mermaid.h b/fftools/textformat/tf_mermaid.h
> index 6e8f2a9b42..0b34d8ab20 100644
> --- a/fftools/textformat/tf_mermaid.h
> +++ b/fftools/textformat/tf_mermaid.h
> @@ -28,8 +28,8 @@ typedef enum {
>
> typedef struct AVDiagramConfig {
> AVDiagramType diagram_type;
> - const char *diagram_css;
> - const char *html_template;
> + char *diagram_css;
> + char *html_template;
> } AVDiagramConfig;
>
>
> --
NAK - I totally disagree to this change
1. It makes the feature widely unusable. In all those years I've never seen
or dealt with an "FFmpeg data folder" and I know that everywhere I would
want to use this feature, there's no such folder nor files
2. The html and the CSS are in no way like exchangeable templates. They are
part of the implementation of the feature - especially the CSS.
Another - yet unsubmitted - feature (data schema graphs) will have its
own and different html and css, which is also very specific.
3. Even when considering the files as something different than templates,
this will still not fly. The code in FFmpeg is tightly coupled and
dependent of the html and css. When the feature gets updated or extended
this will almost certainly include changes to the css, which means that
it would be incompatible with the css from a different FFmpeg version.
There's no logical independence and hence the files cannot be delivered
separately
PS: If you look at the html and want to reply that it doesn't appear to be
very specific:
1. Then look at the CSS
2. The specific part in the html is the Mermaid version. And there are
breaking changes across mermaid versions and the CSS depends on the
Mermaid version as well, which means that these two are also tied
together and both in turn with the code.
sw
_______________________________________________
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories
2025-05-17 2:21 ` softworkz .
@ 2025-05-17 9:13 ` Marton Balint
2025-05-17 17:22 ` softworkz .
0 siblings, 1 reply; 10+ messages in thread
From: Marton Balint @ 2025-05-17 9:13 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 17 May 2025, softworkz . wrote:
>
>
>> -----Original Message-----
>> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
>> Balint
>> Sent: Samstag, 17. Mai 2025 01:09
>> To: ffmpeg-devel@ffmpeg.org
>> Cc: Marton Balint <cus@passwd.hu>
>> Subject: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and
>> HTML resources from ffmpeg data directories
>>
>> Similar to how it is done for ffpreset files. This allows the users to change
>> the HTML/CSS templates at will.
>>
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>> Makefile | 2 +-
>> doc/ffmpeg.texi | 4 ++-
>> fftools/cmdutils.c | 48 +++++++++++++++++++++++++++++++++
>> fftools/cmdutils.h | 2 ++
>> fftools/graph/graphprint.c | 16 ++++++++---
>> fftools/textformat/tf_mermaid.h | 4 +--
>> 6 files changed, 68 insertions(+), 8 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index e2250f6bc6..ebc50bb510 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -32,7 +32,7 @@ FFLIBS-$(CONFIG_SWSCALE) += swscale
>>
>> FFLIBS := avutil
>>
>> -DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
>> $(SRC_PATH)/doc/ffprobe.xsd
>> +DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
>> $(SRC_PATH)/doc/ffprobe.xsd $(SRC_PATH)/fftools/resources/graph.css
>> $(SRC_PATH)/fftools/resources/graph.html
>>
>> SKIPHEADERS = compat/w32pthreads.h
>>
>> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
>> index 35675b5309..8edf188ab9 100644
>> --- a/doc/ffmpeg.texi
>> +++ b/doc/ffmpeg.texi
>> @@ -1402,7 +1402,9 @@ Writes execution graph details to the specified file in
>> the format set via -prin
>>
>> @item -print_graphs_format @var{format} (@emph{global})
>> Sets the output format (available formats are: default, compact, csv, flat,
>> ini, json, xml, mermaid, mermaidhtml)
>> -The default format is json.
>> +The default format is json. The mermarid and mermaidhtml formats need
>> graph.css
>> +and graph.html resources which are searched in the FFMPEG data directories,
>> +similar to ffpreset files.
>>
>> @item -progress @var{url} (@emph{global})
>> Send program-friendly progress information to @var{url}.
>> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
>> index 1de670c2e4..01e57d91e8 100644
>> --- a/fftools/cmdutils.c
>> +++ b/fftools/cmdutils.c
>> @@ -1005,6 +1005,54 @@ FILE *get_preset_file(AVBPrint *filename,
>> return f;
>> }
>>
>> +int file_read_from_datadir(const char *filename, char **outbuf)
>> +{
>> + FILE *f;
>> + char *buf = NULL;
>> + long size;
>> + AVBPrint bp;
>> +
>> + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
>> + f = get_datadir_file_fmt(&bp, "%s", filename);
>> + if (!f)
>> + return AVERROR(errno);
>> +
>> + if (fseek(f, 0, SEEK_END)) {
>> + int ret = AVERROR(errno);
>> + fclose(f);
>> + return ret;
>> + }
>> +
>> + size = ftell(f);
>> + if (size < 0 || size >= INT_MAX) {
>> + fclose(f);
>> + return AVERROR(EINVAL);
>> + }
>> +
>> + if (fseek(f, 0, SEEK_SET)) {
>> + int ret = AVERROR(errno);
>> + fclose(f);
>> + return ret;
>> + }
>> +
>> + buf = av_malloc(size + 1);
>> + if (!buf) {
>> + fclose(f);
>> + return AVERROR(ENOMEM);
>> + }
>> +
>> + if (fread(buf, 1, size, f) != size) {
>> + fclose(f);
>> + return AVERROR(EIO);
>> + }
>> + buf[size] = 0;
>> +
>> + fclose(f);
>> +
>> + *outbuf = buf;
>> + return 0;
>> +}
>> +
>> int cmdutils_isalnum(char c)
>> {
>> return (c >= '0' && c <= '9') ||
>> diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
>> index 216a2bcfe7..b324e5fc65 100644
>> --- a/fftools/cmdutils.h
>> +++ b/fftools/cmdutils.h
>> @@ -504,6 +504,8 @@ int read_yesno(void);
>> FILE *get_preset_file(AVBPrint *filename,
>> const char *preset_name, int is_path, const char
>> *codec_name);
>>
>> +int file_read_from_datadir(const char *filename, char **buf);
>> +
>> /**
>> * Realloc array to hold new_size elements of elem_size.
>> *
>> diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c
>> index fc94a75797..fbcb7f1b75 100644
>> --- a/fftools/graph/graphprint.c
>> +++ b/fftools/graph/graphprint.c
>> @@ -41,7 +41,6 @@
>> #include "libavutil/hwcontext.h"
>> #include "fftools/textformat/avtextformat.h"
>> #include "fftools/textformat/tf_mermaid.h"
>> -#include "fftools/resources/resman.h"
>>
>> typedef enum {
>> SECTION_ID_ROOT,
>> @@ -935,10 +934,19 @@ static int init_graphprint(GraphPrintContext **pgpc,
>> AVBPrint *target_buf)
>> }
>>
>> if (!strcmp(text_formatter->name, "mermaid") || !strcmp(text_formatter-
>>> name, "mermaidhtml")) {
>> - gpc->diagram_config.diagram_css =
>> ff_resman_get_string(FF_RESOURCE_GRAPH_CSS);
>> + ret = file_read_from_datadir("graph.css", &gpc-
>>> diagram_config.diagram_css);
>> + if (ret < 0) {
>> + av_log(NULL, AV_LOG_ERROR, "graph.css needed for mermaid graph
>> format cannot be opened: %s\n", av_err2str(ret));
>> + goto fail;
>> + }
>>
>> - if (!strcmp(text_formatter->name, "mermaidhtml"))
>> - gpc->diagram_config.html_template =
>> ff_resman_get_string(FF_RESOURCE_GRAPH_HTML);
>> + if (!strcmp(text_formatter->name, "mermaidhtml")) {
>> + ret = file_read_from_datadir("graph.html", &gpc-
>>> diagram_config.html_template);
>> + if (ret < 0) {
>> + av_log(NULL, AV_LOG_ERROR, "graph.html needed for
>> mermaridhtml graph format cannot be opened: %s\n", av_err2str(ret));
>> + goto fail;
>> + }
>> + }
>>
>> av_diagram_init(tfc, &gpc->diagram_config);
>> }
>> diff --git a/fftools/textformat/tf_mermaid.h b/fftools/textformat/tf_mermaid.h
>> index 6e8f2a9b42..0b34d8ab20 100644
>> --- a/fftools/textformat/tf_mermaid.h
>> +++ b/fftools/textformat/tf_mermaid.h
>> @@ -28,8 +28,8 @@ typedef enum {
>>
>> typedef struct AVDiagramConfig {
>> AVDiagramType diagram_type;
>> - const char *diagram_css;
>> - const char *html_template;
>> + char *diagram_css;
>> + char *html_template;
>> } AVDiagramConfig;
>>
>>
>> --
>
> NAK - I totally disagree to this change
>
>
> 1. It makes the feature widely unusable. In all those years I've never seen
> or dealt with an "FFmpeg data folder" and I know that everywhere I would
> want to use this feature, there's no such folder nor files
Using external folders for resources is quite common, admittedly not in
ffmpeg, but for other programs it is.
>
> 2. The html and the CSS are in no way like exchangeable templates. They are
> part of the implementation of the feature - especially the CSS.
> Another - yet unsubmitted - feature (data schema graphs) will have its
> own and different html and css, which is also very specific.
>
> 3. Even when considering the files as something different than templates,
> this will still not fly. The code in FFmpeg is tightly coupled and
> dependent of the html and css. When the feature gets updated or extended
> this will almost certainly include changes to the css, which means that
> it would be incompatible with the css from a different FFmpeg version.
> There's no logical independence and hence the files cannot be delivered
> separately
If that is the case, then I am not sure if it is a good idea to maintain
the styling of these output variants embedded in ffmpeg CLI.
Considering that you already depend on CDNs, IMHO it would make more sense
to generate some minimal HTML with the graph data embedded in JSON in it,
and then generate the required mermarid format via JS also loaded from
some CDN, or even better, ffmpeg.org.
Thanks,
Marton
_______________________________________________
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories
2025-05-17 9:13 ` Marton Balint
@ 2025-05-17 17:22 ` softworkz .
2025-05-17 20:33 ` softworkz .
0 siblings, 1 reply; 10+ messages in thread
From: softworkz . @ 2025-05-17 17:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
> Balint
> Sent: Samstag, 17. Mai 2025 11:14
> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and
> HTML resources from ffmpeg data directories
>
>
>
> On Sat, 17 May 2025, softworkz . wrote:
>
> >
> >
> >> -----Original Message-----
> >> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
> >> Balint
> >> Sent: Samstag, 17. Mai 2025 01:09
> >> To: ffmpeg-devel@ffmpeg.org
> >> Cc: Marton Balint <cus@passwd.hu>
> >> Subject: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and
> >> HTML resources from ffmpeg data directories
> >>
> >> Similar to how it is done for ffpreset files. This allows the users to
> change
> >> the HTML/CSS templates at will.
> >>
> >> Signed-off-by: Marton Balint <cus@passwd.hu>
> >> ---
> >> Makefile | 2 +-
> >> doc/ffmpeg.texi | 4 ++-
> >> fftools/cmdutils.c | 48 +++++++++++++++++++++++++++++++++
> >> fftools/cmdutils.h | 2 ++
> >> fftools/graph/graphprint.c | 16 ++++++++---
> >> fftools/textformat/tf_mermaid.h | 4 +--
> >> 6 files changed, 68 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/Makefile b/Makefile
> >> index e2250f6bc6..ebc50bb510 100644
> >> --- a/Makefile
> >> +++ b/Makefile
> >> @@ -32,7 +32,7 @@ FFLIBS-$(CONFIG_SWSCALE) += swscale
> >>
> >> FFLIBS := avutil
> >>
> >> -DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
> >> $(SRC_PATH)/doc/ffprobe.xsd
> >> +DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
> >> $(SRC_PATH)/doc/ffprobe.xsd $(SRC_PATH)/fftools/resources/graph.css
> >> $(SRC_PATH)/fftools/resources/graph.html
> >>
> >> SKIPHEADERS = compat/w32pthreads.h
> >>
> >> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> >> index 35675b5309..8edf188ab9 100644
> >> --- a/doc/ffmpeg.texi
> >> +++ b/doc/ffmpeg.texi
> >> @@ -1402,7 +1402,9 @@ Writes execution graph details to the specified file
> in
> >> the format set via -prin
> >>
> >> @item -print_graphs_format @var{format} (@emph{global})
> >> Sets the output format (available formats are: default, compact, csv,
> flat,
> >> ini, json, xml, mermaid, mermaidhtml)
> >> -The default format is json.
> >> +The default format is json. The mermarid and mermaidhtml formats need
> >> graph.css
> >> +and graph.html resources which are searched in the FFMPEG data
> directories,
> >> +similar to ffpreset files.
> >>
> >> @item -progress @var{url} (@emph{global})
> >> Send program-friendly progress information to @var{url}.
> >> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> >> index 1de670c2e4..01e57d91e8 100644
> >> --- a/fftools/cmdutils.c
> >> +++ b/fftools/cmdutils.c
> >> @@ -1005,6 +1005,54 @@ FILE *get_preset_file(AVBPrint *filename,
> >> return f;
> >> }
> >>
> >> +int file_read_from_datadir(const char *filename, char **outbuf)
> >> +{
> >> + FILE *f;
> >> + char *buf = NULL;
> >> + long size;
> >> + AVBPrint bp;
> >> +
> >> + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> >> + f = get_datadir_file_fmt(&bp, "%s", filename);
> >> + if (!f)
> >> + return AVERROR(errno);
> >> +
> >> + if (fseek(f, 0, SEEK_END)) {
> >> + int ret = AVERROR(errno);
> >> + fclose(f);
> >> + return ret;
> >> + }
> >> +
> >> + size = ftell(f);
> >> + if (size < 0 || size >= INT_MAX) {
> >> + fclose(f);
> >> + return AVERROR(EINVAL);
> >> + }
> >> +
> >> + if (fseek(f, 0, SEEK_SET)) {
> >> + int ret = AVERROR(errno);
> >> + fclose(f);
> >> + return ret;
> >> + }
> >> +
> >> + buf = av_malloc(size + 1);
> >> + if (!buf) {
> >> + fclose(f);
> >> + return AVERROR(ENOMEM);
> >> + }
> >> +
> >> + if (fread(buf, 1, size, f) != size) {
> >> + fclose(f);
> >> + return AVERROR(EIO);
> >> + }
> >> + buf[size] = 0;
> >> +
> >> + fclose(f);
> >> +
> >> + *outbuf = buf;
> >> + return 0;
> >> +}
> >> +
> >> int cmdutils_isalnum(char c)
> >> {
> >> return (c >= '0' && c <= '9') ||
> >> diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
> >> index 216a2bcfe7..b324e5fc65 100644
> >> --- a/fftools/cmdutils.h
> >> +++ b/fftools/cmdutils.h
> >> @@ -504,6 +504,8 @@ int read_yesno(void);
> >> FILE *get_preset_file(AVBPrint *filename,
> >> const char *preset_name, int is_path, const char
> >> *codec_name);
> >>
> >> +int file_read_from_datadir(const char *filename, char **buf);
> >> +
> >> /**
> >> * Realloc array to hold new_size elements of elem_size.
> >> *
> >> diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c
> >> index fc94a75797..fbcb7f1b75 100644
> >> --- a/fftools/graph/graphprint.c
> >> +++ b/fftools/graph/graphprint.c
> >> @@ -41,7 +41,6 @@
> >> #include "libavutil/hwcontext.h"
> >> #include "fftools/textformat/avtextformat.h"
> >> #include "fftools/textformat/tf_mermaid.h"
> >> -#include "fftools/resources/resman.h"
> >>
> >> typedef enum {
> >> SECTION_ID_ROOT,
> >> @@ -935,10 +934,19 @@ static int init_graphprint(GraphPrintContext **pgpc,
> >> AVBPrint *target_buf)
> >> }
> >>
> >> if (!strcmp(text_formatter->name, "mermaid") ||
> !strcmp(text_formatter-
> >>> name, "mermaidhtml")) {
> >> - gpc->diagram_config.diagram_css =
> >> ff_resman_get_string(FF_RESOURCE_GRAPH_CSS);
> >> + ret = file_read_from_datadir("graph.css", &gpc-
> >>> diagram_config.diagram_css);
> >> + if (ret < 0) {
> >> + av_log(NULL, AV_LOG_ERROR, "graph.css needed for mermaid graph
> >> format cannot be opened: %s\n", av_err2str(ret));
> >> + goto fail;
> >> + }
> >>
> >> - if (!strcmp(text_formatter->name, "mermaidhtml"))
> >> - gpc->diagram_config.html_template =
> >> ff_resman_get_string(FF_RESOURCE_GRAPH_HTML);
> >> + if (!strcmp(text_formatter->name, "mermaidhtml")) {
> >> + ret = file_read_from_datadir("graph.html", &gpc-
> >>> diagram_config.html_template);
> >> + if (ret < 0) {
> >> + av_log(NULL, AV_LOG_ERROR, "graph.html needed for
> >> mermaridhtml graph format cannot be opened: %s\n", av_err2str(ret));
> >> + goto fail;
> >> + }
> >> + }
> >>
> >> av_diagram_init(tfc, &gpc->diagram_config);
> >> }
> >> diff --git a/fftools/textformat/tf_mermaid.h
> b/fftools/textformat/tf_mermaid.h
> >> index 6e8f2a9b42..0b34d8ab20 100644
> >> --- a/fftools/textformat/tf_mermaid.h
> >> +++ b/fftools/textformat/tf_mermaid.h
> >> @@ -28,8 +28,8 @@ typedef enum {
> >>
> >> typedef struct AVDiagramConfig {
> >> AVDiagramType diagram_type;
> >> - const char *diagram_css;
> >> - const char *html_template;
> >> + char *diagram_css;
> >> + char *html_template;
> >> } AVDiagramConfig;
> >>
> >>
> >> --
> >
> > NAK - I totally disagree to this change
> >
> >
> > 1. It makes the feature widely unusable. In all those years I've never seen
> > or dealt with an "FFmpeg data folder" and I know that everywhere I would
> > want to use this feature, there's no such folder nor files
>
> Using external folders for resources is quite common, admittedly not in
> ffmpeg, but for other programs it is.
>
> >
> > 2. The html and the CSS are in no way like exchangeable templates. They are
> > part of the implementation of the feature - especially the CSS.
> > Another - yet unsubmitted - feature (data schema graphs) will have its
> > own and different html and css, which is also very specific.
> >
> > 3. Even when considering the files as something different than templates,
> > this will still not fly. The code in FFmpeg is tightly coupled and
> > dependent of the html and css. When the feature gets updated or extended
> > this will almost certainly include changes to the css, which means that
> > it would be incompatible with the css from a different FFmpeg version.
> > There's no logical independence and hence the files cannot be delivered
> > separately
>
> If that is the case, then I am not sure if it is a good idea to maintain
> the styling of these output variants embedded in ffmpeg CLI.
For styling Mermaid diagrams, the CSS must be part of the Mermaid graph
definition - this is what is taken from the CSS resource file. It gets
transformed and escaped into the Mermaid definition.
When you specify -print_graphs_format mermaid, then you get the plain
Mermaid definition as a valid .mmd (or .mermaid) file - all without a
CDN. Then you can open that in an application or just copy/paste it into
a code block in most Markdown system. You might need to care about the
version, though. For example to make it work in the current GitHub Markdown,
you need to specify an extra parameter (until GitHub updates their Mermaid
libs).
So far, this is all offline. In earlier versions, I had the CSS included
in plain C strings, but I thought it would be a better practice to include
it as compressed resource, to optimize the size of the binaries and that
allowed to reduce it to 25% of the size.
This route (mermaid format) is also the way to got when you want to embed
the diagram a custom html document, but then you are responsible for any
compatibility issues.
The mermaidhtml output on the other hand is the reliable and quick way
when you just want to see the diagram that always works without any worries
and without any pre-conditions.
The compressed sizes are about 1k for the html and 2.5k for the CSS, that
really not that big and it doesn't got into any libs, just the ffmpeg
binary. Given the high value of the feature, I do believe that this is
more than justified.
> Considering that you already depend on CDNs, IMHO it would make more sense
> to generate some minimal HTML with the graph data embedded in JSON in it,
> and then generate the required mermarid format via JS also loaded from
> some CDN, or even better, ffmpeg.org.
That doesn't work, because for the Mermaid creation, the AVTextFormat APIs
have a few extension features which are giving some extra information that
is not included in the plain JSON output.
Thanks for your interest in the feature,
sw
_______________________________________________
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories
2025-05-17 17:22 ` softworkz .
@ 2025-05-17 20:33 ` softworkz .
0 siblings, 0 replies; 10+ messages in thread
From: softworkz . @ 2025-05-17 20:33 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of softworkz .
> Sent: Samstag, 17. Mai 2025 19:22
> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and
> HTML resources from ffmpeg data directories
>
>
>
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
> > Balint
> > Sent: Samstag, 17. Mai 2025 11:14
> > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS
> and
> > HTML resources from ffmpeg data directories
> >
> >
> >
> > On Sat, 17 May 2025, softworkz . wrote:
> >
> > >
> > >
> > >> -----Original Message-----
> > >> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
> > >> Balint
> > >> Sent: Samstag, 17. Mai 2025 01:09
> > >> To: ffmpeg-devel@ffmpeg.org
> > >> Cc: Marton Balint <cus@passwd.hu>
> > >> Subject: [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS
> and
> > >> HTML resources from ffmpeg data directories
> > >>
> > >> Similar to how it is done for ffpreset files. This allows the users to
> > change
> > >> the HTML/CSS templates at will.
> > >>
> > >> Signed-off-by: Marton Balint <cus@passwd.hu>
> > >> ---
> > >> Makefile | 2 +-
> > >> doc/ffmpeg.texi | 4 ++-
> > >> fftools/cmdutils.c | 48 +++++++++++++++++++++++++++++++++
> > >> fftools/cmdutils.h | 2 ++
> > >> fftools/graph/graphprint.c | 16 ++++++++---
> > >> fftools/textformat/tf_mermaid.h | 4 +--
> > >> 6 files changed, 68 insertions(+), 8 deletions(-)
> > >>
> > >> diff --git a/Makefile b/Makefile
> > >> index e2250f6bc6..ebc50bb510 100644
> > >> --- a/Makefile
> > >> +++ b/Makefile
> > >> @@ -32,7 +32,7 @@ FFLIBS-$(CONFIG_SWSCALE) += swscale
> > >>
> > >> FFLIBS := avutil
> > >>
> > >> -DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
> > >> $(SRC_PATH)/doc/ffprobe.xsd
> > >> +DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
> > >> $(SRC_PATH)/doc/ffprobe.xsd $(SRC_PATH)/fftools/resources/graph.css
> > >> $(SRC_PATH)/fftools/resources/graph.html
> > >>
> > >> SKIPHEADERS = compat/w32pthreads.h
> > >>
> > >> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> > >> index 35675b5309..8edf188ab9 100644
> > >> --- a/doc/ffmpeg.texi
> > >> +++ b/doc/ffmpeg.texi
> > >> @@ -1402,7 +1402,9 @@ Writes execution graph details to the specified
> file
> > in
> > >> the format set via -prin
> > >>
> > >> @item -print_graphs_format @var{format} (@emph{global})
> > >> Sets the output format (available formats are: default, compact, csv,
> > flat,
> > >> ini, json, xml, mermaid, mermaidhtml)
> > >> -The default format is json.
> > >> +The default format is json. The mermarid and mermaidhtml formats need
> > >> graph.css
> > >> +and graph.html resources which are searched in the FFMPEG data
> > directories,
> > >> +similar to ffpreset files.
> > >>
> > >> @item -progress @var{url} (@emph{global})
> > >> Send program-friendly progress information to @var{url}.
> > >> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> > >> index 1de670c2e4..01e57d91e8 100644
> > >> --- a/fftools/cmdutils.c
> > >> +++ b/fftools/cmdutils.c
> > >> @@ -1005,6 +1005,54 @@ FILE *get_preset_file(AVBPrint *filename,
> > >> return f;
> > >> }
> > >>
> > >> +int file_read_from_datadir(const char *filename, char **outbuf)
> > >> +{
> > >> + FILE *f;
> > >> + char *buf = NULL;
> > >> + long size;
> > >> + AVBPrint bp;
> > >> +
> > >> + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> > >> + f = get_datadir_file_fmt(&bp, "%s", filename);
> > >> + if (!f)
> > >> + return AVERROR(errno);
> > >> +
> > >> + if (fseek(f, 0, SEEK_END)) {
> > >> + int ret = AVERROR(errno);
> > >> + fclose(f);
> > >> + return ret;
> > >> + }
> > >> +
> > >> + size = ftell(f);
> > >> + if (size < 0 || size >= INT_MAX) {
> > >> + fclose(f);
> > >> + return AVERROR(EINVAL);
> > >> + }
> > >> +
> > >> + if (fseek(f, 0, SEEK_SET)) {
> > >> + int ret = AVERROR(errno);
> > >> + fclose(f);
> > >> + return ret;
> > >> + }
> > >> +
> > >> + buf = av_malloc(size + 1);
> > >> + if (!buf) {
> > >> + fclose(f);
> > >> + return AVERROR(ENOMEM);
> > >> + }
> > >> +
> > >> + if (fread(buf, 1, size, f) != size) {
> > >> + fclose(f);
> > >> + return AVERROR(EIO);
> > >> + }
> > >> + buf[size] = 0;
> > >> +
> > >> + fclose(f);
> > >> +
> > >> + *outbuf = buf;
> > >> + return 0;
> > >> +}
> > >> +
> > >> int cmdutils_isalnum(char c)
> > >> {
> > >> return (c >= '0' && c <= '9') ||
> > >> diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
> > >> index 216a2bcfe7..b324e5fc65 100644
> > >> --- a/fftools/cmdutils.h
> > >> +++ b/fftools/cmdutils.h
> > >> @@ -504,6 +504,8 @@ int read_yesno(void);
> > >> FILE *get_preset_file(AVBPrint *filename,
> > >> const char *preset_name, int is_path, const char
> > >> *codec_name);
> > >>
> > >> +int file_read_from_datadir(const char *filename, char **buf);
> > >> +
> > >> /**
> > >> * Realloc array to hold new_size elements of elem_size.
> > >> *
> > >> diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c
> > >> index fc94a75797..fbcb7f1b75 100644
> > >> --- a/fftools/graph/graphprint.c
> > >> +++ b/fftools/graph/graphprint.c
> > >> @@ -41,7 +41,6 @@
> > >> #include "libavutil/hwcontext.h"
> > >> #include "fftools/textformat/avtextformat.h"
> > >> #include "fftools/textformat/tf_mermaid.h"
> > >> -#include "fftools/resources/resman.h"
> > >>
> > >> typedef enum {
> > >> SECTION_ID_ROOT,
> > >> @@ -935,10 +934,19 @@ static int init_graphprint(GraphPrintContext
> **pgpc,
> > >> AVBPrint *target_buf)
> > >> }
> > >>
> > >> if (!strcmp(text_formatter->name, "mermaid") ||
> > !strcmp(text_formatter-
> > >>> name, "mermaidhtml")) {
> > >> - gpc->diagram_config.diagram_css =
> > >> ff_resman_get_string(FF_RESOURCE_GRAPH_CSS);
> > >> + ret = file_read_from_datadir("graph.css", &gpc-
> > >>> diagram_config.diagram_css);
> > >> + if (ret < 0) {
> > >> + av_log(NULL, AV_LOG_ERROR, "graph.css needed for mermaid
> graph
> > >> format cannot be opened: %s\n", av_err2str(ret));
> > >> + goto fail;
> > >> + }
> > >>
> > >> - if (!strcmp(text_formatter->name, "mermaidhtml"))
> > >> - gpc->diagram_config.html_template =
> > >> ff_resman_get_string(FF_RESOURCE_GRAPH_HTML);
> > >> + if (!strcmp(text_formatter->name, "mermaidhtml")) {
> > >> + ret = file_read_from_datadir("graph.html", &gpc-
> > >>> diagram_config.html_template);
> > >> + if (ret < 0) {
> > >> + av_log(NULL, AV_LOG_ERROR, "graph.html needed for
> > >> mermaridhtml graph format cannot be opened: %s\n", av_err2str(ret));
> > >> + goto fail;
> > >> + }
> > >> + }
> > >>
> > >> av_diagram_init(tfc, &gpc->diagram_config);
> > >> }
> > >> diff --git a/fftools/textformat/tf_mermaid.h
> > b/fftools/textformat/tf_mermaid.h
> > >> index 6e8f2a9b42..0b34d8ab20 100644
> > >> --- a/fftools/textformat/tf_mermaid.h
> > >> +++ b/fftools/textformat/tf_mermaid.h
> > >> @@ -28,8 +28,8 @@ typedef enum {
> > >>
> > >> typedef struct AVDiagramConfig {
> > >> AVDiagramType diagram_type;
> > >> - const char *diagram_css;
> > >> - const char *html_template;
> > >> + char *diagram_css;
> > >> + char *html_template;
> > >> } AVDiagramConfig;
> > >>
> > >>
> > >> --
> > >
> > > NAK - I totally disagree to this change
> > >
> > >
> > > 1. It makes the feature widely unusable. In all those years I've never
> seen
> > > or dealt with an "FFmpeg data folder" and I know that everywhere I would
> > > want to use this feature, there's no such folder nor files
> >
> > Using external folders for resources is quite common, admittedly not in
> > ffmpeg, but for other programs it is.
> >
> > >
> > > 2. The html and the CSS are in no way like exchangeable templates. They
> are
> > > part of the implementation of the feature - especially the CSS.
> > > Another - yet unsubmitted - feature (data schema graphs) will have its
> > > own and different html and css, which is also very specific.
> > >
> > > 3. Even when considering the files as something different than templates,
> > > this will still not fly. The code in FFmpeg is tightly coupled and
> > > dependent of the html and css. When the feature gets updated or extended
> > > this will almost certainly include changes to the css, which means that
> > > it would be incompatible with the css from a different FFmpeg version.
> > > There's no logical independence and hence the files cannot be delivered
> > > separately
> >
> > If that is the case, then I am not sure if it is a good idea to maintain
> > the styling of these output variants embedded in ffmpeg CLI.
>
> For styling Mermaid diagrams, the CSS must be part of the Mermaid graph
> definition - this is what is taken from the CSS resource file. It gets
> transformed and escaped into the Mermaid definition.
>
> When you specify -print_graphs_format mermaid, then you get the plain
> Mermaid definition as a valid .mmd (or .mermaid) file - all without a
> CDN. Then you can open that in an application or just copy/paste it into
> a code block in most Markdown system. You might need to care about the
> version, though. For example to make it work in the current GitHub Markdown,
> you need to specify an extra parameter (until GitHub updates their Mermaid
> libs).
>
> So far, this is all offline. In earlier versions, I had the CSS included
> in plain C strings, but I thought it would be a better practice to include
> it as compressed resource, to optimize the size of the binaries and that
> allowed to reduce it to 25% of the size.
>
> This route (mermaid format) is also the way to got when you want to embed
> the diagram a custom html document, but then you are responsible for any
> compatibility issues.
>
> The mermaidhtml output on the other hand is the reliable and quick way
> when you just want to see the diagram that always works without any worries
> and without any pre-conditions.
>
> The compressed sizes are about 1k for the html and 2.5k for the CSS, that
> really not that big and it doesn't got into any libs, just the ffmpeg
> binary. Given the high value of the feature, I do believe that this is
> more than justified.
>
> > Considering that you already depend on CDNs, IMHO it would make more sense
> > to generate some minimal HTML with the graph data embedded in JSON in it,
> > and then generate the required mermarid format via JS also loaded from
> > some CDN, or even better, ffmpeg.org.
>
> That doesn't work, because for the Mermaid creation, the AVTextFormat APIs
> have a few extension features which are giving some extra information that
> is not included in the plain JSON output.
>
>
> Thanks for your interest in the feature,
> sw
> _______________________________________________
Hi Marton,
as you had mentioned the use of CDN, I wanted to share my thoughts and
reasonings about it.
In the first place, a full offline solution would clearly be preferable from
my point of view. The html loads two packages: Mermaid and a simple zoom/pan
library. I had thought about eliminating the zoom/pan lib by writing a custom
one. I'm not 100% satisfied with the current lib, but it was the best among
almost a dozen of libs I had tried, most of them heavily bloated.
Eventually I've been too afraid of objections on the ML regarding the resource
sizes, so kept it external.
When looking at what the browser loads from the CDN, it sums up to 207kB.
I'm not sure how much potential there might be left for compression, that
would need to be determined. But let's say it's maybe around 100kB of size
that would be required to make it work fully offline without CDN.
It might also be possible to further reduce the size by creating a custom
build of Mermaid. It currently supports 22 types of diagrams and we need
only one or two.
Personally, I don't care about the size. With binary sizes of >50 MB for
static ffmpeg, those 100kB don't really matter. I think among those >50 MB,
there's a lot of stuff that is less important.
But others may see it differently, so I'm not sure. If there would be
interest in turning it into a fully offline solution though, I can try to
transform it accordingly.
Thanks,
sw
_______________________________________________
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression"
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
0 siblings, 1 reply; 10+ messages in thread
From: Kacper Michajlow @ 2025-06-14 14:43 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 17 May 2025 at 01:11, Marton Balint <cus@passwd.hu> wrote:
>
> This reverts commit 517a8055655798970d94a4c5ea912511362520ea.
>
> Building resources directly in the ffmpeg util needs quite a bit of code,
> increases binary size and makes it harder for the users to change those
> resources at will.
>
> The only user of this, the mermaid and mermaidhtml graph formats were converted
> in an erlier commit to use file loading from the FFMPEG data dirs similar to
> ffpreset files. Therefore the infrastucture to build resources directly into
> ffmpeg CLI tools can be removed now.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> configure | 5 -
> ffbuild/common.mak | 43 +------
> fftools/Makefile | 5 +-
> fftools/resources/.gitignore | 4 -
> fftools/resources/Makefile | 13 --
> fftools/resources/resman.c | 231 -----------------------------------
> fftools/resources/resman.h | 50 --------
> 7 files changed, 3 insertions(+), 348 deletions(-)
> delete mode 100644 fftools/resources/.gitignore
> delete mode 100644 fftools/resources/Makefile
> delete mode 100644 fftools/resources/resman.c
> delete mode 100644 fftools/resources/resman.h
>
> diff --git a/configure b/configure
> index 0609dac4ab..2e69b3c56c 100755
> --- a/configure
> +++ b/configure
> @@ -523,7 +523,6 @@ Developer options (useful when working on FFmpeg itself):
> --enable-macos-kperf enable macOS kperf (private) API
> --disable-large-tests disable tests that use a large amount of memory
> --disable-ptx-compression don't compress CUDA PTX code even when possible
> - --disable-resource-compression don't compress resources even when possible
> --disable-version-tracking don't include the git/release version in the build
>
> NOTE: Object files are built at the place where configure is launched.
> @@ -2124,7 +2123,6 @@ CONFIG_LIST="
> ossfuzz
> pic
> ptx_compression
> - resource_compression
> thumb
> valgrind_backtrace
> xmm_clobber_test
> @@ -4181,7 +4179,6 @@ enable iamf
> enable large_tests
> enable optimizations
> enable ptx_compression
> -enable resource_compression
> enable runtime_cpudetect
> enable safe_bitstream_reader
> enable static
> @@ -6907,8 +6904,6 @@ EOF
>
> enabled zlib_gzip && enabled gzip || disable ptx_compression
>
> -enabled zlib_gzip && enabled gzip || disable resource_compression
> -
> # On some systems dynamic loading requires no extra linker flags
> check_lib libdl dlfcn.h "dlopen dlsym" || check_lib libdl dlfcn.h "dlopen dlsym" -ldl
>
> diff --git a/ffbuild/common.mak b/ffbuild/common.mak
> index 0e1eb1f62b..ca45a0f368 100644
> --- a/ffbuild/common.mak
> +++ b/ffbuild/common.mak
> @@ -139,44 +139,6 @@ else
> $(BIN2C) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<) $@ $(subst .,_,$(basename $(notdir $@)))
> endif
>
> -# 1) Preprocess CSS to a minified version
> -%.css.min: %.css
> - # Must start with a tab in the real Makefile
> - sed 's!/\\*.*\\*/!!g' $< \
> - | tr '\n' ' ' \
> - | tr -s ' ' \
> - | sed 's/^ //; s/ $$//' \
> - > $@
> -
> -ifdef CONFIG_RESOURCE_COMPRESSION
> -
> -# 2) Gzip the minified CSS
> -%.css.min.gz: %.css.min
> - $(M)gzip -nc9 $< > $@
> -
> -# 3) Convert the gzipped CSS to a .c array
> -%.css.c: %.css.min.gz $(BIN2CEXE)
> - $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
> -
> -# 4) Gzip the HTML file (no minification needed)
> -%.html.gz: %.html
> - $(M)gzip -nc9 $< > $@
> -
> -# 5) Convert the gzipped HTML to a .c array
> -%.html.c: %.html.gz $(BIN2CEXE)
> - $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
> -
> -else # NO COMPRESSION
> -
> -# 2) Convert the minified CSS to a .c array
> -%.css.c: %.css.min $(BIN2CEXE)
> - $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
> -
> -# 3) Convert the plain HTML to a .c array
> -%.html.c: %.html $(BIN2CEXE)
> - $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@)))
> -endif
> -
> clean::
> $(RM) $(BIN2CEXE) $(CLEANSUFFIXES:%=ffbuild/%)
>
> @@ -229,10 +191,9 @@ SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
> SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
> HOBJS = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
> PTXOBJS = $(filter %.ptx.o,$(OBJS))
> -RESOURCEOBJS = $(filter %.css.o %.html.o,$(OBJS))
> $(HOBJS): CCFLAGS += $(CFLAGS_HEADERS)
> checkheaders: $(HOBJS)
> -.SECONDARY: $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=) $(RESOURCEOBJS:.o=.c) $(RESOURCEOBJS:%.css.o=%.css.min) $(RESOURCEOBJS:%.css.o=%.css.min.gz) $(RESOURCEOBJS:%.html.o=%.html.gz) $(RESOURCEOBJS:.o=)
> +.SECONDARY: $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=)
>
> alltools: $(TOOLS)
>
> @@ -253,7 +214,7 @@ $(TOOLOBJS): | tools
>
> OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS))
>
> -CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *.html.gz *.html.c *.css.gz *.css.c *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
> +CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
> LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
>
> define RULES
> diff --git a/fftools/Makefile b/fftools/Makefile
> index 361a4fd574..57e3c0e518 100644
> --- a/fftools/Makefile
> +++ b/fftools/Makefile
> @@ -9,8 +9,6 @@ AVBASENAMES = ffmpeg ffplay ffprobe
> ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
> ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
>
> -include $(SRC_PATH)/fftools/resources/Makefile
> -
> OBJS-ffmpeg += \
> fftools/ffmpeg_dec.o \
> fftools/ffmpeg_demux.o \
> @@ -59,7 +57,7 @@ ifdef HAVE_GNU_WINDRES
> OBJS-$(1) += fftools/fftoolsres.o
> endif
> $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
> -$$(OBJS-$(1)): | fftools fftools/textformat fftools/resources fftools/graph
> +$$(OBJS-$(1)): | fftools fftools/textformat fftools/graph
> $$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
> $(1)$(PROGSSUF)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
> $(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
> @@ -73,7 +71,6 @@ all: $(AVPROGS)
> fftools/ffprobe.o fftools/cmdutils.o: libavutil/ffversion.h | fftools
> OUTDIRS += fftools
> OUTDIRS += fftools/textformat
> -OUTDIRS += fftools/resources
> OUTDIRS += fftools/graph
>
> ifdef AVPROGS
> diff --git a/fftools/resources/.gitignore b/fftools/resources/.gitignore
> deleted file mode 100644
> index 5f496535a6..0000000000
> --- a/fftools/resources/.gitignore
> +++ /dev/null
> @@ -1,4 +0,0 @@
> -*.html.c
> -*.css.c
> -*.html.gz
> -*.css.gz
> diff --git a/fftools/resources/Makefile b/fftools/resources/Makefile
> deleted file mode 100644
> index 8579a52678..0000000000
> --- a/fftools/resources/Makefile
> +++ /dev/null
> @@ -1,13 +0,0 @@
> -clean::
> - $(RM) $(CLEANSUFFIXES:%=fftools/resources/%)
> -
> -vpath %.html $(SRC_PATH)
> -vpath %.css $(SRC_PATH)
> -
> -# Uncomment to prevent deletion during build
> -#.PRECIOUS: %.css.c %.css.min %.css.gz %.css.min.gz %.html.gz %.html.c
> -
> -OBJS-resman += \
> - fftools/resources/resman.o \
> - fftools/resources/graph.html.o \
> - fftools/resources/graph.css.o \
> diff --git a/fftools/resources/resman.c b/fftools/resources/resman.c
> deleted file mode 100644
> index a9e21626fa..0000000000
> --- a/fftools/resources/resman.c
> +++ /dev/null
> @@ -1,231 +0,0 @@
> -/*
> - * Copyright (c) 2025 - softworkz
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -/**
> - * @file
> - * output writers for filtergraph details
> - */
> -
> -#include "config.h"
> -
> -#include <string.h>
> -
> -#if CONFIG_RESOURCE_COMPRESSION
> -#include <zlib.h>
> -#endif
> -
> -#include "resman.h"
> -#include "fftools/ffmpeg_filter.h"
> -#include "libavutil/avassert.h"
> -#include "libavutil/pixdesc.h"
> -#include "libavutil/dict.h"
> -#include "libavutil/common.h"
> -
> -extern const unsigned char ff_graph_html_data[];
> -extern const unsigned int ff_graph_html_len;
> -
> -extern const unsigned char ff_graph_css_data[];
> -extern const unsigned ff_graph_css_len;
> -
> -static const FFResourceDefinition resource_definitions[] = {
> - [FF_RESOURCE_GRAPH_CSS] = { FF_RESOURCE_GRAPH_CSS, "graph.css", &ff_graph_css_data[0], &ff_graph_css_len },
> - [FF_RESOURCE_GRAPH_HTML] = { FF_RESOURCE_GRAPH_HTML, "graph.html", &ff_graph_html_data[0], &ff_graph_html_len },
> -};
> -
> -
> -static const AVClass resman_class = {
> - .class_name = "ResourceManager",
> -};
> -
> -typedef struct ResourceManagerContext {
> - const AVClass *class;
> - AVDictionary *resource_dic;
> -} ResourceManagerContext;
> -
> -static AVMutex mutex = AV_MUTEX_INITIALIZER;
> -
> -ResourceManagerContext *resman_ctx = NULL;
> -
> -
> -#if CONFIG_RESOURCE_COMPRESSION
> -
> -static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in_len, char **out, size_t *out_len)
> -{
> - z_stream strm;
> - unsigned chunk = 65534;
> - int ret;
> - uint8_t *buf;
> -
> - *out = NULL;
> - memset(&strm, 0, sizeof(strm));
> -
> - // Allocate output buffer with extra byte for null termination
> - buf = (uint8_t *)av_mallocz(chunk + 1);
> - if (!buf) {
> - av_log(ctx, AV_LOG_ERROR, "Failed to allocate decompression buffer\n");
> - return AVERROR(ENOMEM);
> - }
> -
> - // 15 + 16 tells zlib to detect GZIP or zlib automatically
> - ret = inflateInit2(&strm, 15 + 16);
> - if (ret != Z_OK) {
> - av_log(ctx, AV_LOG_ERROR, "Error during zlib initialization: %s\n", strm.msg);
> - av_free(buf);
> - return AVERROR(ENOSYS);
> - }
> -
> - strm.avail_in = in_len;
> - strm.next_in = in;
> - strm.avail_out = chunk;
> - strm.next_out = buf;
> -
> - ret = inflate(&strm, Z_FINISH);
> - if (ret != Z_OK && ret != Z_STREAM_END) {
> - av_log(ctx, AV_LOG_ERROR, "Inflate failed: %d, %s\n", ret, strm.msg);
> - inflateEnd(&strm);
> - av_free(buf);
> - return (ret == Z_STREAM_END) ? Z_OK : ((ret == Z_OK) ? Z_BUF_ERROR : ret);
> - }
> -
> - if (strm.avail_out == 0) {
> - // TODO: Error or loop decoding?
> - av_log(ctx, AV_LOG_WARNING, "Decompression buffer may be too small\n");
> - }
> -
> - *out_len = chunk - strm.avail_out;
> - buf[*out_len] = 0; // Ensure null termination
> -
> - inflateEnd(&strm);
> - *out = (char *)buf;
> - return Z_OK;
> -}
> -#endif
> -
> -static ResourceManagerContext *get_resman_context(void)
> -{
> - ResourceManagerContext *res = resman_ctx;
> -
> - ff_mutex_lock(&mutex);
> -
> - if (res)
> - goto end;
> -
> - res = av_mallocz(sizeof(ResourceManagerContext));
> - if (!res) {
> - av_log(NULL, AV_LOG_ERROR, "Failed to allocate resource manager context\n");
> - goto end;
> - }
> -
> - res->class = &resman_class;
> - resman_ctx = res;
> -
> -end:
> - ff_mutex_unlock(&mutex);
> - return res;
> -}
> -
> -
> -void ff_resman_uninit(void)
> -{
> - ff_mutex_lock(&mutex);
> -
> - if (resman_ctx) {
> - if (resman_ctx->resource_dic)
> - av_dict_free(&resman_ctx->resource_dic);
> - av_freep(&resman_ctx);
> - }
> -
> - ff_mutex_unlock(&mutex);
> -}
> -
> -
> -char *ff_resman_get_string(FFResourceId resource_id)
> -{
> - ResourceManagerContext *ctx = get_resman_context();
> - FFResourceDefinition resource_definition = { 0 };
> - AVDictionaryEntry *dic_entry;
> - char *res = NULL;
> -
> - if (!ctx)
> - return NULL;
> -
> - for (unsigned i = 0; i < FF_ARRAY_ELEMS(resource_definitions); ++i) {
> - FFResourceDefinition def = resource_definitions[i];
> - if (def.resource_id == resource_id) {
> - resource_definition = def;
> - break;
> - }
> - }
> -
> - if (!resource_definition.name) {
> - av_log(ctx, AV_LOG_ERROR, "Unable to find resource with ID %d\n", resource_id);
> - return NULL;
> - }
> -
> - ff_mutex_lock(&mutex);
> -
> - dic_entry = av_dict_get(ctx->resource_dic, resource_definition.name, NULL, 0);
> -
> - if (!dic_entry) {
> - int dict_ret;
> -
> -#if CONFIG_RESOURCE_COMPRESSION
> -
> - char *out = NULL;
> - size_t out_len;
> -
> - int ret = decompress_gzip(ctx, (uint8_t *)resource_definition.data, *resource_definition.data_len, &out, &out_len);
> -
> - if (ret) {
> - av_log(NULL, AV_LOG_ERROR, "Unable to decompress the resource with ID %d\n", resource_id);
> - goto end;
> - }
> -
> - dict_ret = av_dict_set(&ctx->resource_dic, resource_definition.name, out, 0);
> - if (dict_ret < 0) {
> - av_log(NULL, AV_LOG_ERROR, "Failed to store decompressed resource in dictionary: %d\n", dict_ret);
> - av_freep(&out);
> - goto end;
> - }
> -
> - av_freep(&out);
> -#else
> -
> - dict_ret = av_dict_set(&ctx->resource_dic, resource_definition.name, (const char *)resource_definition.data, 0);
> - if (dict_ret < 0) {
> - av_log(NULL, AV_LOG_ERROR, "Failed to store resource in dictionary: %d\n", dict_ret);
> - goto end;
> - }
> -
> -#endif
> - dic_entry = av_dict_get(ctx->resource_dic, resource_definition.name, NULL, 0);
> -
> - if (!dic_entry) {
> - av_log(NULL, AV_LOG_ERROR, "Failed to retrieve resource from dictionary after storing it\n");
> - goto end;
> - }
> - }
> -
> - res = dic_entry->value;
> -
> -end:
> - ff_mutex_unlock(&mutex);
> - return res;
> -}
> diff --git a/fftools/resources/resman.h b/fftools/resources/resman.h
> deleted file mode 100644
> index 6485db5091..0000000000
> --- a/fftools/resources/resman.h
> +++ /dev/null
> @@ -1,50 +0,0 @@
> -/*
> - * Copyright (c) 2025 - softworkz
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -#ifndef FFTOOLS_RESOURCES_RESMAN_H
> -#define FFTOOLS_RESOURCES_RESMAN_H
> -
> -#include <stdint.h>
> -
> -#include "config.h"
> -#include "fftools/ffmpeg.h"
> -#include "libavutil/avutil.h"
> -#include "libavutil/bprint.h"
> -#include "fftools/textformat/avtextformat.h"
> -
> -typedef enum {
> - FF_RESOURCE_GRAPH_CSS,
> - FF_RESOURCE_GRAPH_HTML,
> -} FFResourceId;
> -
> -typedef struct FFResourceDefinition {
> - FFResourceId resource_id;
> - const char *name;
> -
> - const unsigned char *data;
> - const unsigned *data_len;
> -
> -} FFResourceDefinition;
> -
> -void ff_resman_uninit(void);
> -
> -char *ff_resman_get_string(FFResourceId resource_id);
> -
> -#endif /* FFTOOLS_RESOURCES_RESMAN_H */
> --
> 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".
Hi Marton,
Is this still on track to be merged? Resource embedding is broken on
some Windows builds and not sure if I should care to debug/fix that or
this code will be nuked anyway?
Thanks,
Kacper
_______________________________________________
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression"
2025-06-14 14:43 ` Kacper Michajlow
@ 2025-06-14 16:11 ` Marton Balint
0 siblings, 0 replies; 10+ messages in thread
From: Marton Balint @ 2025-06-14 16:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 14 Jun 2025, Kacper Michajlow wrote:
> On Sat, 17 May 2025 at 01:11, Marton Balint <cus@passwd.hu> wrote:
>>
>> This reverts commit 517a8055655798970d94a4c5ea912511362520ea.
>>
>> Building resources directly in the ffmpeg util needs quite a bit of code,
>> increases binary size and makes it harder for the users to change those
>> resources at will.
>>
>> The only user of this, the mermaid and mermaidhtml graph formats were converted
>> in an erlier commit to use file loading from the FFMPEG data dirs similar to
>> ffpreset files. Therefore the infrastucture to build resources directly into
>> ffmpeg CLI tools can be removed now.
>>
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>> configure | 5 -
>> ffbuild/common.mak | 43 +------
>> fftools/Makefile | 5 +-
>> fftools/resources/.gitignore | 4 -
>> fftools/resources/Makefile | 13 --
>> fftools/resources/resman.c | 231 -----------------------------------
>> fftools/resources/resman.h | 50 --------
>> 7 files changed, 3 insertions(+), 348 deletions(-)
>> delete mode 100644 fftools/resources/.gitignore
>> delete mode 100644 fftools/resources/Makefile
>> delete mode 100644 fftools/resources/resman.c
>> delete mode 100644 fftools/resources/resman.h
>>
[...]
>
> Hi Marton,
>
> Is this still on track to be merged? Resource embedding is broken on
> some Windows builds and not sure if I should care to debug/fix that or
> this code will be nuked anyway?
Softworkz was strongly against nuking it, so I guess it will stay. I am
not sure if there are pendig fixes for it.
Regards,
Marton
_______________________________________________
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-06-14 16:14 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-16 23:08 [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files Marton Balint
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
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