Originally committed as revision 20352 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -115,4 +115,12 @@ The default value of ``w'' and ``h'' is 0. |
| 115 | 115 |
|
| 116 | 116 |
Pass the source unchanged to the output. |
| 117 | 117 |
|
| 118 |
+@section vflip |
|
| 119 |
+ |
|
| 120 |
+Flip the input video vertically. |
|
| 121 |
+ |
|
| 122 |
+@example |
|
| 123 |
+./ffmpeg -i in.avi -vfilters "vflip" out.avi |
|
| 124 |
+@end example |
|
| 125 |
+ |
|
| 118 | 126 |
@bye |
| 40 | 41 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,102 @@ |
| 0 |
+/* |
|
| 1 |
+ * copyright (c) 2007 Bobby Bingham |
|
| 2 |
+ * |
|
| 3 |
+ * This file is part of FFmpeg. |
|
| 4 |
+ * |
|
| 5 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 7 |
+ * License as published by the Free Software Foundation; either |
|
| 8 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 9 |
+ * |
|
| 10 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 |
+ * Lesser General Public License for more details. |
|
| 14 |
+ * |
|
| 15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 16 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 17 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 18 |
+ */ |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @file libavfilter/vf_vflip.c |
|
| 22 |
+ * video vertical flip filter |
|
| 23 |
+ */ |
|
| 24 |
+ |
|
| 25 |
+#include "avfilter.h" |
|
| 26 |
+ |
|
| 27 |
+typedef struct {
|
|
| 28 |
+ int vsub; ///< vertical chroma subsampling |
|
| 29 |
+} FlipContext; |
|
| 30 |
+ |
|
| 31 |
+static int config_input(AVFilterLink *link) |
|
| 32 |
+{
|
|
| 33 |
+ FlipContext *flip = link->dst->priv; |
|
| 34 |
+ int tmp; |
|
| 35 |
+ |
|
| 36 |
+ avcodec_get_chroma_sub_sample(link->format, &tmp, &flip->vsub); |
|
| 37 |
+ |
|
| 38 |
+ return 0; |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms, |
|
| 42 |
+ int w, int h) |
|
| 43 |
+{
|
|
| 44 |
+ FlipContext *flip = link->dst->priv; |
|
| 45 |
+ int i; |
|
| 46 |
+ |
|
| 47 |
+ AVFilterPicRef *picref = avfilter_get_video_buffer(link->dst->outputs[0], |
|
| 48 |
+ perms, w, h); |
|
| 49 |
+ |
|
| 50 |
+ picref->data[0] += (h-1) * picref->linesize[0]; |
|
| 51 |
+ picref->linesize[0] = -picref->linesize[0]; |
|
| 52 |
+ for (i = 1; i < 4; i ++) {
|
|
| 53 |
+ if (picref->data[i]) {
|
|
| 54 |
+ picref->data[i] += ((h >> flip->vsub)-1) * picref->linesize[i]; |
|
| 55 |
+ picref->linesize[i] = -picref->linesize[i]; |
|
| 56 |
+ } |
|
| 57 |
+ } |
|
| 58 |
+ |
|
| 59 |
+ return picref; |
|
| 60 |
+} |
|
| 61 |
+ |
|
| 62 |
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref) |
|
| 63 |
+{
|
|
| 64 |
+ FlipContext *flip = link->dst->priv; |
|
| 65 |
+ AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0); |
|
| 66 |
+ int i; |
|
| 67 |
+ |
|
| 68 |
+ ref2->data[0] += (link->h-1) * ref2->linesize[0]; |
|
| 69 |
+ ref2->linesize[0] = -ref2->linesize[0]; |
|
| 70 |
+ for (i = 1; i < 4; i ++) {
|
|
| 71 |
+ if (ref2->data[i]) {
|
|
| 72 |
+ ref2->data[i] += ((link->h >> flip->vsub)-1) * ref2->linesize[i]; |
|
| 73 |
+ ref2->linesize[i] = -ref2->linesize[i]; |
|
| 74 |
+ } |
|
| 75 |
+ } |
|
| 76 |
+ |
|
| 77 |
+ avfilter_start_frame(link->dst->outputs[0], ref2); |
|
| 78 |
+} |
|
| 79 |
+ |
|
| 80 |
+static void draw_slice(AVFilterLink *link, int y, int h) |
|
| 81 |
+{
|
|
| 82 |
+ AVFilterContext *ctx = link->dst; |
|
| 83 |
+ |
|
| 84 |
+ avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h); |
|
| 85 |
+} |
|
| 86 |
+ |
|
| 87 |
+AVFilter avfilter_vf_vflip = {
|
|
| 88 |
+ .name = "vflip", |
|
| 89 |
+ .priv_size = sizeof(FlipContext), |
|
| 90 |
+ |
|
| 91 |
+ .inputs = (AVFilterPad[]) {{ .name = "default",
|
|
| 92 |
+ .type = CODEC_TYPE_VIDEO, |
|
| 93 |
+ .get_video_buffer = get_video_buffer, |
|
| 94 |
+ .start_frame = start_frame, |
|
| 95 |
+ .draw_slice = draw_slice, |
|
| 96 |
+ .config_props = config_input, }, |
|
| 97 |
+ { .name = NULL}},
|
|
| 98 |
+ .outputs = (AVFilterPad[]) {{ .name = "default",
|
|
| 99 |
+ .type = CODEC_TYPE_VIDEO, }, |
|
| 100 |
+ { .name = NULL}},
|
|
| 101 |
+}; |