summaryrefslogtreecommitdiff
path: root/libavfilter/avfiltergraph.c
diff options
context:
space:
mode:
authorVitor Sessak <vitor1001@gmail.com>2008-04-04 20:04:55 +0000
committerVitor Sessak <vitor1001@gmail.com>2008-04-04 20:04:55 +0000
commitf8c77c823cc03b76946c5b97e87e81304d421166 (patch)
tree3b051578b561067a0d8f4014862bf42490c9204b /libavfilter/avfiltergraph.c
parentffcaef348580ba32c57a85e115c0809e5b857d95 (diff)
Move simple filter chain loading code over to the filter graph.
Commited in SoC by Bobby Bingham on 2007-07-14 22:26:37 Originally committed as revision 12688 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavfilter/avfiltergraph.c')
-rw-r--r--libavfilter/avfiltergraph.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 4e5bfd2f10..5211c762e1 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -19,6 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <string.h>
+#include <stddef.h>
+
#include "avfilter.h"
#include "avfiltergraph.h"
@@ -54,3 +57,62 @@ void avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
graph->filters[graph->filter_count - 1] = filter;
}
+static AVFilterContext *create_filter_with_args(char *filter)
+{
+ AVFilterContext *ret;
+ char *name, *args;
+
+ name = filter;
+ if((args = strchr(filter, '='))) {
+ /* ensure we at least have a name */
+ if(args == filter)
+ return NULL;
+
+ *args ++ = 0;
+ }
+
+ av_log(NULL, AV_LOG_INFO, "creating filter \"%s\" with args \"%s\"\n",
+ name, args ? args : "(none)");
+
+ if((ret = avfilter_create_by_name(name, NULL))) {
+ if(avfilter_init_filter(ret, args)) {
+ av_log(NULL, AV_LOG_ERROR, "error initializing filter!\n");
+ avfilter_destroy(ret);
+ ret = NULL;
+ }
+ } else av_log(NULL, AV_LOG_ERROR, "error creating filter!\n");
+
+ return ret;
+}
+
+int avfilter_graph_load_chain(AVFilterGraph *graph,
+ unsigned count, char **filter_list,
+ AVFilterContext **first, AVFilterContext **last)
+{
+ unsigned i;
+ AVFilterContext *filters[2] = {NULL,NULL};
+
+ for(i = 0; i < count; i ++) {
+ if(!(filters[1] = create_filter_with_args(filter_list[i])))
+ goto fail;
+ if(i == 0) {
+ if(first) *first = filters[1];
+ } else {
+ if(avfilter_link(filters[0], 0, filters[1], 0)) {
+ av_log(NULL, AV_LOG_ERROR, "error linking filters!\n");
+ goto fail;
+ }
+ }
+ avfilter_graph_add_filter(graph, filters[1]);
+ filters[0] = filters[1];
+ }
+
+ if(last) *last = filters[1];
+ return 0;
+
+fail:
+ destroy_graph_filters(graph);
+ *first = *last = NULL;
+ return -1;
+}
+