History

Add format and noformat filters.

Originally committed as revision 20390 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini committed 17 years ago

Commit fcbed3c1 parent 51135d15 files · +193 −1Browse files

Unified · Split

5 files
  1. doc/libavfilter.texi +34 −0
  2. libavfilter/Makefile +2 −0
  3. libavfilter/allfilters.c +2 −0
  4. libavfilter/avfilter.h +1 −1
  5. libavfilter/vf_format.c +154 −0
doc/libavfilter.texi+34−0
@@ -111,6 +111,40 @@ corner of the input image. · 110 unmodified lines
111 111
112The default value of ``width'' and ``height'' is 0.112The default value of ``width'' and ``height'' is 0.
113 113
114@section format
115
116Convert the input video to one of the specified pixel formats.
117Libavfilter will try to pick one that is supported as the input to
118the next filter.
119
120The filter takes as argument a list of pixel format names, separated
121by ``:'', for example ``yuv420p:monow:rgb24''.
122
123The following command:
124
125@example
126./ffmpeg -i in.avi -vfilters "format=yuv420p" out.avi
127@end example
128
129will convert the input video to the format ``yuv420p''.
130
131@section noformat
132
133Force libavfilter not to use any of the specified pixel formats as the
134input to the next filter.
135
136The filter takes as argument a list of pixel format names, separated
137by ``:'', for example ``yuv420p:monow:rgb24''.
138
139The following command:
140
141@example
142./ffmpeg -i in.avi -vfilters "noformat=yuv420p, vflip" out.avi
143@end example
144
145will make libavfilter use a format different from ``yuv420p'' as the
146input to the vflip filter.
147
114@section null148@section null
115 149
116Pass the source unchanged to the output.150Pass the source unchanged to the output.
libavfilter/Makefile+2−0
@@ -12,6 +12,8 @@ OBJS = allfilters.o \ · 11 unmodified lines
12 formats.o \12 formats.o \
13 13
14OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o14OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o
15OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o
16OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
15OBJS-$(CONFIG_NULL_FILTER) += vf_null.o17OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
16OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o18OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o
17 19
libavfilter/allfilters.c+2−0
@@ -35,6 +35,8 @@ void avfilter_register_all(void) · 34 unmodified lines
35 initialized = 1;35 initialized = 1;
36 36
37 REGISTER_FILTER (CROP,crop,vf);37 REGISTER_FILTER (CROP,crop,vf);
38 REGISTER_FILTER (FORMAT,format,vf);
39 REGISTER_FILTER (NOFORMAT,noformat,vf);
38 REGISTER_FILTER (NULL,null,vf);40 REGISTER_FILTER (NULL,null,vf);
39 REGISTER_FILTER (VFLIP,vflip,vf);41 REGISTER_FILTER (VFLIP,vflip,vf);
40}42}
libavfilter/avfilter.h+1−1
@@ -23,7 +23,7 @@ · 22 unmodified lines
23#define AVFILTER_AVFILTER_H23#define AVFILTER_AVFILTER_H
24 24
25#define LIBAVFILTER_VERSION_MAJOR 125#define LIBAVFILTER_VERSION_MAJOR 1
26#define LIBAVFILTER_VERSION_MINOR 526#define LIBAVFILTER_VERSION_MINOR 6
27#define LIBAVFILTER_VERSION_MICRO 027#define LIBAVFILTER_VERSION_MICRO 0
28 28
29#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \29#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
libavfilter/vf_format.c+154−0
@@ -0,0 +1,154 @@
1/*
2 * copyright (c) 2007 Bobby Bingham
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file libavfilter/vf_format.c
23 * video format and noformat filters
24 */
25
26#include "avfilter.h"
27
28typedef struct {
29 /**
30 * List of flags telling if a given image format has been listed
31 * as argument to the filter.
32 */
33 int listed_pix_fmt_flags[PIX_FMT_NB];
34} FormatContext;
35
36#define PIX_FMT_NAME_MAXSIZE 32
37
38static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
39{
40 FormatContext *format = ctx->priv;
41 const char *cur, *sep;
42 char pix_fmt_name[PIX_FMT_NAME_MAXSIZE];
43 int pix_fmt_name_len;
44 enum PixelFormat pix_fmt;
45
46 /* parse the list of formats */
47 for (cur = args; cur; cur = sep ? sep+1 : NULL) {
48 if (!(sep = strchr(cur, ':')))
49 pix_fmt_name_len = strlen(cur);
50 else
51 pix_fmt_name_len = sep - cur;
52 if (pix_fmt_name_len >= PIX_FMT_NAME_MAXSIZE) {
53 av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
54 return -1;
55 }
56
57 memcpy(pix_fmt_name, cur, pix_fmt_name_len);
58 pix_fmt_name[pix_fmt_name_len] = 0;
59 pix_fmt = avcodec_get_pix_fmt(pix_fmt_name);
60
61 if (pix_fmt == PIX_FMT_NONE) {
62 av_log(ctx, AV_LOG_ERROR, "Unknown pixel format: %s\n", pix_fmt_name);
63 return -1;
64 }
65
66 format->listed_pix_fmt_flags[pix_fmt] = 1;
67 }
68
69 return 0;
70}
71
72static AVFilterFormats *make_format_list(FormatContext *format, int flag)
73{
74 AVFilterFormats *formats;
75 enum PixelFormat pix_fmt;
76
77 formats = av_mallocz(sizeof(AVFilterFormats));
78 formats->formats = av_malloc(sizeof(enum PixelFormat) * PIX_FMT_NB);
79
80 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
81 if (format->listed_pix_fmt_flags[pix_fmt] == flag)
82 formats->formats[formats->format_count++] = pix_fmt;
83
84 return formats;
85}
86
87static int query_formats_format(AVFilterContext *ctx)
88{
89 avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 1));
90 return 0;
91}
92
93static int query_formats_noformat(AVFilterContext *ctx)
94{
95 avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 0));
96 return 0;
97}
98
99static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
100{
101 avfilter_start_frame(link->dst->outputs[0], picref);
102}
103
104static void end_frame(AVFilterLink *link)
105{
106 avfilter_end_frame(link->dst->outputs[0]);
107}
108
109static void draw_slice(AVFilterLink *link, int y, int h)
110{
111 avfilter_draw_slice(link->dst->outputs[0], y, h);
112}
113
114AVFilter avfilter_vf_format = {
115 .name = "format",
116 .description = "Convert the input video to one of the specified pixel formats.",
117
118 .init = init,
119
120 .query_formats = query_formats_format,
121
122 .priv_size = sizeof(FormatContext),
123
124 .inputs = (AVFilterPad[]) {{ .name = "default",
125 .type = CODEC_TYPE_VIDEO,
126 .start_frame = start_frame,
127 .draw_slice = draw_slice,
128 .end_frame = end_frame, },
129 { .name = NULL}},
130 .outputs = (AVFilterPad[]) {{ .name = "default",
131 .type = CODEC_TYPE_VIDEO },
132 { .name = NULL}},
133};
134
135AVFilter avfilter_vf_noformat = {
136 .name = "noformat",
137 .description = "Force libavfilter not to use any of the specified pixel formats as the input to the next filter.",
138
139 .init = init,
140
141 .query_formats = query_formats_noformat,
142
143 .priv_size = sizeof(FormatContext),
144
145 .inputs = (AVFilterPad[]) {{ .name = "default",
146 .type = CODEC_TYPE_VIDEO,
147 .start_frame = start_frame,
148 .draw_slice = draw_slice,
149 .end_frame = end_frame, },
150 { .name = NULL}},
151 .outputs = (AVFilterPad[]) {{ .name = "default",
152 .type = CODEC_TYPE_VIDEO },
153 { .name = NULL}},
154};

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