Hello everyone,
I was heavily using the -filter_script option lately and was missing a
way to put comments into the filtergraph file. So here’s a proposal to
add that functionality.
Happy new year!
From 067cb553e5ad5e47c0cbad3c78a55f3aa5c4fe7e Mon Sep 17 00:00:00 2001
From: Daniel Musketa <=>
Date: Thu, 31 Dec 2020 00:50:14 +0100
Subject: [PATCH 2/2] document the behaviour of -filter_script to ignore
commented lines
---
doc/ffmpeg.texi | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 62015d7565..b97002b9d3 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -663,6 +663,8 @@ This option is similar to @option{-filter}, the only difference is that its
argument is the name of the file from which a filtergraph description is to be
read.
+Lines beginning with "#" in the filtergraph description will be ignored.
+
@item -filter_threads @var{nb_threads} (@emph{global})
Defines how many threads are used to process a filter pipeline. Each pipeline
will produce a thread pool with this many threads available for parallel processing.
@@ -1678,6 +1680,8 @@ This option is similar to @option{-filter_complex}, the only difference is that
its argument is the name of the file from which a complex filtergraph
description is to be read.
+Lines beginning with "#" in the filtergraph description will be ignored.
+
@item -accurate_seek (@emph{input})
This option enables or disables accurate seeking in input files with the
@option{-ss} option. It is enabled by default, so seeking is accurate when
--
2.17.1
From 4a51956edcd7c4959972207d9f05e3e21d90dbd1 Mon Sep 17 00:00:00 2001
From: Daniel Musketa <=>
Date: Thu, 31 Dec 2020 00:44:06 +0100
Subject: [PATCH 1/2] add function to remove commented lines from filtergraph
Lines beginning with "#" will be removed (or rather cruelly
overridden with white space) to be able to have comments in
a filtergraph file.
---
fftools/ffmpeg_opt.c | 55 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 2 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 242468fc64..f776f4bd7f 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -20,6 +20,7 @@
*/
#include <stdint.h>
+#include <stdbool.h>
#include "ffmpeg.h"
#include "cmdutils.h"
@@ -1658,6 +1659,50 @@ static uint8_t *read_file(const char *filename)
return str;
}
+/* remove lines beginning with "#" (from filtergraph) */
+static void remove_commented_lines(char *str)
+{
+ #define COMMENT '#'
+ #define EOL '\n'
+
+
+ bool in_commented_line = false;
+ bool next_char_is_first_of_line = true;
+ int lines_affected = 0;
+
+ for (int i = 0; i < strlen(str); i++) {
+ if (str[i] == EOL) {
+ in_commented_line = false;
+ next_char_is_first_of_line = true;
+ continue;
+ }
+
+ if (next_char_is_first_of_line && str[i] == COMMENT) {
+ in_commented_line = true;
+ lines_affected++;
+ }
+
+ if (in_commented_line) {
+ str[i] = ' ';
+ }
+
+ next_char_is_first_of_line = false;
+ }
+
+ if (lines_affected) {
+ av_log(
+ NULL,
+ AV_LOG_INFO,
+ "%s: %s() removed %i commented lines from filtergraph.\n",
+ __FILE__,
+ __FUNCTION__,
+ lines_affected
+ );
+ }
+
+ return;
+}
+
static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
OutputStream *ost)
{
@@ -1669,8 +1714,11 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
exit_program(1);
}
- if (ost->filters_script)
- return read_file(ost->filters_script);
+ if (ost->filters_script) {
+ uint8_t *graph_desc = read_file(ost->filters_script);
+ remove_commented_lines(graph_desc);
+ return graph_desc;
+ }
else if (ost->filters)
return av_strdup(ost->filters);
@@ -3200,6 +3248,9 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
{
uint8_t *graph_desc = read_file(arg);
+
+ remove_commented_lines(graph_desc);
+
if (!graph_desc)
return AVERROR(EINVAL);
--
2.17.1
_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".