History

lavd/lavfi: add graph_file option

Allow to specify a filename where to put the filtergraph description. This is useful to override limitations or glitches of particular shell environments, and allows a level of indirection for specifying filtergraphs.

Stefano Sabatini committed 14 years ago

Commit 8b03cd31 parent bd6240e3 files · +36 −1Browse files

Unified · Split

3 files
  1. doc/indevs.texi +6 −0
  2. libavdevice/lavfi.c +29 −0
  3. libavfilter/version.h +1 −1
doc/indevs.texi+6−0
@@ -320,6 +320,12 @@ label, but all the others need to be specified explicitly. · 319 unmodified lines
320320
321321 If not specified defaults to the filename specified for the input
322322 device.
323+
324+@item graph_file
325+Set the filename of the filtergraph to be read and sent to the other
326+filters. Syntax of the filtergraph is the same as the one specified by
327+the option @var{graph}.
328+
323329 @end table
324330
325331 @subsection Examples
libavdevice/lavfi.c+29−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 #include "float.h" /* DBL_MIN, DBL_MAX */
2929
3030 #include "libavutil/bprint.h"
31+#include "libavutil/file.h"
3132 #include "libavutil/log.h"
3233 #include "libavutil/mem.h"
3334 #include "libavutil/opt.h"
@@ -43,6 +44,7 @@ · 9 unmodified lines
4344 typedef struct {
4445 AVClass *class; ///< class for private options
4546 char *graph_str;
47+ char *graph_filename;
4648 char *dump_graph;
4749 AVFilterGraph *graph;
4850 AVFilterContext **sinks;
@@ -104,6 +106,32 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) · 55 unmodified lines
104106 buffersink = avfilter_get_by_name("ffbuffersink");
105107 abuffersink = avfilter_get_by_name("ffabuffersink");
106108
109+ if (lavfi->graph_filename && lavfi->graph_str) {
110+ av_log(avctx, AV_LOG_ERROR,
111+ "Only one of the graph or graph_file options must be specified\n");
112+ return AVERROR(EINVAL);
113+ }
114+
115+ if (lavfi->graph_filename) {
116+ uint8_t *file_buf, *graph_buf;
117+ size_t file_bufsize;
118+ ret = av_file_map(lavfi->graph_filename,
119+ &file_buf, &file_bufsize, 0, avctx);
120+ if (ret < 0)
121+ return ret;
122+
123+ /* create a 0-terminated string based on the read file */
124+ graph_buf = av_malloc(file_bufsize + 1);
125+ if (!graph_buf) {
126+ av_file_unmap(file_buf, file_bufsize);
127+ return AVERROR(ENOMEM);
128+ }
129+ memcpy(graph_buf, file_buf, file_bufsize);
130+ graph_buf[file_bufsize] = 0;
131+ av_file_unmap(file_buf, file_bufsize);
132+ lavfi->graph_str = graph_buf;
133+ }
134+
107135 if (!lavfi->graph_str)
108136 lavfi->graph_str = av_strdup(avctx->filename);
109137
@@ -376,6 +404,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) · 266 unmodified lines
376404
377405 static const AVOption options[] = {
378406 { "graph", "set libavfilter graph", OFFSET(graph_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
407+ { "graph_file","set libavfilter graph filename", OFFSET(graph_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
379408 { "dumpgraph", "dump graph to stderr", OFFSET(dump_graph), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
380409 { NULL },
381410 };
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030
3131 #define LIBAVFILTER_VERSION_MAJOR 3
3232 #define LIBAVFILTER_VERSION_MINOR 20
33−#define LIBAVFILTER_VERSION_MICRO 104
33+#define LIBAVFILTER_VERSION_MICRO 105
3434
3535 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
3636 LIBAVFILTER_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t