summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog1
-rwxr-xr-xconfigure1
-rw-r--r--doc/filters.texi10
-rw-r--r--libavfilter/Makefile1
-rw-r--r--libavfilter/allfilters.c1
-rw-r--r--libavfilter/avfilter.h4
-rw-r--r--libavfilter/vf_hflip.c167
-rwxr-xr-xtests/lavfi-regression.sh1
-rw-r--r--tests/ref/lavfi/pixfmts_hflip_le72
9 files changed, 256 insertions, 2 deletions
diff --git a/Changelog b/Changelog
index eb457413f9..195e347dee 100644
--- a/Changelog
+++ b/Changelog
@@ -30,6 +30,7 @@ version <next>:
- RTP packetization of Theora and Vorbis
- RTP depacketization of MP4A-LATM
- RTP packetization and depacketization of VP8
+- hflip filter
version 0.6:
diff --git a/configure b/configure
index 5ec664c885..993d18ab9f 100755
--- a/configure
+++ b/configure
@@ -1492,6 +1492,7 @@ mpg_test_deps="mpeg1system_muxer mpegps_demuxer"
set_ne_test_deps pixdesc
set_ne_test_deps pixfmts_crop
+set_ne_test_deps pixfmts_hflip
set_ne_test_deps pixfmts_null
set_ne_test_deps pixfmts_pad
set_ne_test_deps pixfmts_scale
diff --git a/doc/filters.texi b/doc/filters.texi
index 7f0cb7141e..380d91d9a0 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -56,6 +56,16 @@ The following command:
will convert the input video to the format ``yuv420p''.
+@section hflip
+
+Flip the input video horizontally.
+
+For example to horizontally flip the video in input with
+@file{ffmpeg}:
+@example
+ffmpeg -i in.avi -vf "hflip" out.avi
+@end example
+
@section noformat
Force libavfilter not to use any of the specified pixel formats for the
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index feef16c2e3..72c510a4fd 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -17,6 +17,7 @@ OBJS = allfilters.o \
OBJS-$(CONFIG_ASPECT_FILTER) += vf_aspect.o
OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o
OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o
+OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o
OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index e8bc771012..15596bd566 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -37,6 +37,7 @@ void avfilter_register_all(void)
REGISTER_FILTER (ASPECT, aspect, vf);
REGISTER_FILTER (CROP, crop, vf);
REGISTER_FILTER (FORMAT, format, vf);
+ REGISTER_FILTER (HFLIP, hflip, vf);
REGISTER_FILTER (NOFORMAT, noformat, vf);
REGISTER_FILTER (NULL, null, vf);
REGISTER_FILTER (PAD, pad, vf);
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index d18f2a8a96..683b258f04 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -25,8 +25,8 @@
#include "libavutil/avutil.h"
#define LIBAVFILTER_VERSION_MAJOR 1
-#define LIBAVFILTER_VERSION_MINOR 34
-#define LIBAVFILTER_VERSION_MICRO 1
+#define LIBAVFILTER_VERSION_MINOR 35
+#define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
new file mode 100644
index 0000000000..3c1c3e347e
--- /dev/null
+++ b/libavfilter/vf_hflip.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2007 Benoit Fouet
+ * Copyright (c) 2010 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @flip
+ * horizontal flip filter
+ */
+
+#include "avfilter.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/intreadwrite.h"
+
+typedef struct {
+ int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes
+ int hsub, vsub; ///< chroma subsampling
+} FlipContext;
+
+static int query_formats(AVFilterContext *ctx)
+{
+ static const enum PixelFormat pix_fmts[] = {
+ PIX_FMT_RGB48BE, PIX_FMT_RGB48LE,
+ PIX_FMT_ARGB, PIX_FMT_RGBA,
+ PIX_FMT_ABGR, PIX_FMT_BGRA,
+ PIX_FMT_RGB24, PIX_FMT_BGR24,
+ PIX_FMT_RGB565BE, PIX_FMT_RGB565LE,
+ PIX_FMT_RGB555BE, PIX_FMT_RGB555LE,
+ PIX_FMT_BGR565BE, PIX_FMT_BGR565LE,
+ PIX_FMT_BGR555BE, PIX_FMT_BGR555LE,
+ PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
+ PIX_FMT_YUV420P16LE, PIX_FMT_YUV420P16BE,
+ PIX_FMT_YUV422P16LE, PIX_FMT_YUV422P16BE,
+ PIX_FMT_YUV444P16LE, PIX_FMT_YUV444P16BE,
+ PIX_FMT_YUV444P, PIX_FMT_YUV422P,
+ PIX_FMT_YUV420P, PIX_FMT_YUV411P,
+ PIX_FMT_YUV410P, PIX_FMT_YUV440P,
+ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P,
+ PIX_FMT_YUVJ420P, PIX_FMT_YUVJ440P,
+ PIX_FMT_YUVA420P,
+ PIX_FMT_RGB8, PIX_FMT_BGR8,
+ PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE,
+ PIX_FMT_PAL8, PIX_FMT_GRAY8,
+ PIX_FMT_NONE
+ };
+
+ avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+static int config_props(AVFilterLink *inlink)
+{
+ FlipContext *flip = inlink->dst->priv;
+ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
+ int i;
+
+ memset(flip->max_step, 0, sizeof(flip->max_step));
+ for (i = 0; i < 4; i++) {
+ const AVComponentDescriptor *comp = &(pix_desc->comp[i]);
+ if ((comp->step_minus1+1) > flip->max_step[comp->plane])
+ flip->max_step[comp->plane] = comp->step_minus1+1;
+ }
+
+ flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
+ flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
+
+ return 0;
+}
+
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+ FlipContext *flip = inlink->dst->priv;
+ AVFilterBufferRef *inpic = inlink->cur_buf;
+ AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
+ uint8_t *inrow, *outrow;
+ int i, j, plane, step, hsub, vsub;
+
+ for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
+ step = flip->max_step[plane];
+ hsub = (plane == 1 || plane == 2) ? flip->hsub : 0;
+ vsub = (plane == 1 || plane == 2) ? flip->vsub : 0;
+
+ outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
+ inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane] + ((inlink->w >> hsub) - 1) * step;
+ for (i = 0; i < h>>vsub; i++) {
+ switch (step) {
+ case 1:
+ {
+ for (j = 0; j < (inlink->w >> hsub); j++)
+ outrow[j] = inrow[-j];
+ }
+ break;
+
+ case 2:
+ {
+ uint16_t *outrow16 = (uint16_t *)outrow;
+ uint16_t * inrow16 = (uint16_t *) inrow;
+ for (j = 0; j < (inlink->w >> hsub); j++)
+ outrow16[j] = inrow16[-j];
+ }
+ break;
+
+ case 3:
+ {
+ uint8_t *in = inrow;
+ uint8_t *out = outrow;
+ for (j = 0; j < (inlink->w >> hsub); j++, out += 3, in -= 3) {
+ int32_t v = AV_RB24(in);
+ AV_WB24(out, v);
+ }
+ }
+ break;
+
+ case 4:
+ {
+ uint32_t *outrow32 = (uint32_t *)outrow;
+ uint32_t * inrow32 = (uint32_t *) inrow;
+ for (j = 0; j < (inlink->w >> hsub); j++)
+ outrow32[j] = inrow32[-j];
+ }
+ break;
+
+ default:
+ for (j = 0; j < (inlink->w >> hsub); j++)
+ memcpy(outrow + j*step, inrow - j*step, step);
+ }
+
+ inrow += inpic ->linesize[plane];
+ outrow += outpic->linesize[plane];
+ }
+ }
+
+ avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+}
+
+AVFilter avfilter_vf_hflip = {
+ .name = "hflip",
+ .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
+ .priv_size = sizeof(FlipContext),
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .draw_slice = draw_slice,
+ .config_props = config_props,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = NULL}},
+};
diff --git a/tests/lavfi-regression.sh b/tests/lavfi-regression.sh
index d30783f019..511e0aec25 100755
--- a/tests/lavfi-regression.sh
+++ b/tests/lavfi-regression.sh
@@ -59,6 +59,7 @@ do_lavfi_pixfmts(){
# all these filters have exactly one input and exactly one output
do_lavfi_pixfmts "crop" "100:100:100:100"
+do_lavfi_pixfmts "hflip" ""
do_lavfi_pixfmts "null" ""
do_lavfi_pixfmts "pad" "500:400:20:20"
do_lavfi_pixfmts "scale" "200:100"
diff --git a/tests/ref/lavfi/pixfmts_hflip_le b/tests/ref/lavfi/pixfmts_hflip_le
new file mode 100644
index 0000000000..50b831b04c
--- /dev/null
+++ b/tests/ref/lavfi/pixfmts_hflip_le
@@ -0,0 +1,72 @@
+49468c6c9ceee5d52b08b1270a909323 *./tests/data/lavfi/pixfmts_hflip_le-abgr.nut
+20276703 ./tests/data/lavfi/pixfmts_hflip_le-abgr.nut
+50ba9f16c6475530602f2983278b82d0 *./tests/data/lavfi/pixfmts_hflip_le-argb.nut
+20276703 ./tests/data/lavfi/pixfmts_hflip_le-argb.nut
+cc53d2011d097972db0d22756c3699e3 *./tests/data/lavfi/pixfmts_hflip_le-bgr24.nut
+15207903 ./tests/data/lavfi/pixfmts_hflip_le-bgr24.nut
+aac987e7d1a6a96477cfc0b48a4285de *./tests/data/lavfi/pixfmts_hflip_le-bgr4_byte.nut
+5070254 ./tests/data/lavfi/pixfmts_hflip_le-bgr4_byte.nut
+ccee08679bac84a1f960c6c9070c5538 *./tests/data/lavfi/pixfmts_hflip_le-bgr555le.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-bgr555le.nut
+3703466e19e1b52e03a34fd244a8e8e4 *./tests/data/lavfi/pixfmts_hflip_le-bgr565le.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-bgr565le.nut
+50b505a889f0428242305acb642da107 *./tests/data/lavfi/pixfmts_hflip_le-bgr8.nut
+5070254 ./tests/data/lavfi/pixfmts_hflip_le-bgr8.nut
+01ca21e7e6a8d1281b4553bde8e8a404 *./tests/data/lavfi/pixfmts_hflip_le-bgra.nut
+20276703 ./tests/data/lavfi/pixfmts_hflip_le-bgra.nut
+03efcb4ab52a24c0af0e03cfd26c9377 *./tests/data/lavfi/pixfmts_hflip_le-gray.nut
+5070254 ./tests/data/lavfi/pixfmts_hflip_le-gray.nut
+9bcbca979601ddc4869f846f08f3d1dd *./tests/data/lavfi/pixfmts_hflip_le-gray16be.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-gray16be.nut
+c1b8965adcc7f847ee343149ff507073 *./tests/data/lavfi/pixfmts_hflip_le-gray16le.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-gray16le.nut
+754f1722fc738590cc407ac65749bfe8 *./tests/data/lavfi/pixfmts_hflip_le-rgb24.nut
+15207903 ./tests/data/lavfi/pixfmts_hflip_le-rgb24.nut
+10743e1577dc3198dbbc7c0b3b8f429e *./tests/data/lavfi/pixfmts_hflip_le-rgb48be.nut
+30414303 ./tests/data/lavfi/pixfmts_hflip_le-rgb48be.nut
+dd945a44f39119221407bf7a04f1bc49 *./tests/data/lavfi/pixfmts_hflip_le-rgb48le.nut
+30414303 ./tests/data/lavfi/pixfmts_hflip_le-rgb48le.nut
+c8a3f995fcf3e0919239ea2c413ddc29 *./tests/data/lavfi/pixfmts_hflip_le-rgb4_byte.nut
+5070254 ./tests/data/lavfi/pixfmts_hflip_le-rgb4_byte.nut
+8778ee0cf58ce9ad1d99a1eca9f95e87 *./tests/data/lavfi/pixfmts_hflip_le-rgb555le.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-rgb555le.nut
+2cb690eb3fcb72da3771ad6a48931158 *./tests/data/lavfi/pixfmts_hflip_le-rgb565le.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-rgb565le.nut
+9e462b811b9b6173397b9cfc1f6b2f17 *./tests/data/lavfi/pixfmts_hflip_le-rgb8.nut
+5070254 ./tests/data/lavfi/pixfmts_hflip_le-rgb8.nut
+d3d0dc1ecef3ed72f26a2986d0efc204 *./tests/data/lavfi/pixfmts_hflip_le-rgba.nut
+20276703 ./tests/data/lavfi/pixfmts_hflip_le-rgba.nut
+acb543ebbbf63eefe533e6faffc006da *./tests/data/lavfi/pixfmts_hflip_le-yuv410p.nut
+5703854 ./tests/data/lavfi/pixfmts_hflip_le-yuv410p.nut
+c626cf6d191139b4ca7efc0155f957f1 *./tests/data/lavfi/pixfmts_hflip_le-yuv411p.nut
+7604654 ./tests/data/lavfi/pixfmts_hflip_le-yuv411p.nut
+2d5c80f9ba2ddd85b2aeda3564cc7d64 *./tests/data/lavfi/pixfmts_hflip_le-yuv420p.nut
+7604654 ./tests/data/lavfi/pixfmts_hflip_le-yuv420p.nut
+758b0c1e2113b15e7afde48da4e4d024 *./tests/data/lavfi/pixfmts_hflip_le-yuv420p16be.nut
+15207903 ./tests/data/lavfi/pixfmts_hflip_le-yuv420p16be.nut
+480ccd951dcb806bc875d307e02e50a0 *./tests/data/lavfi/pixfmts_hflip_le-yuv420p16le.nut
+15207903 ./tests/data/lavfi/pixfmts_hflip_le-yuv420p16le.nut
+6e728f4eb9eae287c224f396d84be6ea *./tests/data/lavfi/pixfmts_hflip_le-yuv422p.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-yuv422p.nut
+a05d43cd62b790087bd37083174557de *./tests/data/lavfi/pixfmts_hflip_le-yuv422p16be.nut
+20276703 ./tests/data/lavfi/pixfmts_hflip_le-yuv422p16be.nut
+6954abebcbc62d81068d58d0c62bdd5b *./tests/data/lavfi/pixfmts_hflip_le-yuv422p16le.nut
+20276703 ./tests/data/lavfi/pixfmts_hflip_le-yuv422p16le.nut
+a99e2b57ed601f39852715c9d675d0d3 *./tests/data/lavfi/pixfmts_hflip_le-yuv440p.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-yuv440p.nut
+947e47f7bb5fdccc659d19b7df2b6fc3 *./tests/data/lavfi/pixfmts_hflip_le-yuv444p.nut
+15207903 ./tests/data/lavfi/pixfmts_hflip_le-yuv444p.nut
+e5ef45bc3d2f5b0b2542d5151340c382 *./tests/data/lavfi/pixfmts_hflip_le-yuv444p16be.nut
+30414303 ./tests/data/lavfi/pixfmts_hflip_le-yuv444p16be.nut
+70793e3d66d0c23a0cdedabe9c24c2a7 *./tests/data/lavfi/pixfmts_hflip_le-yuv444p16le.nut
+30414303 ./tests/data/lavfi/pixfmts_hflip_le-yuv444p16le.nut
+d83ec0c01498189f179ec574918185f1 *./tests/data/lavfi/pixfmts_hflip_le-yuva420p.nut
+12673454 ./tests/data/lavfi/pixfmts_hflip_le-yuva420p.nut
+df3aaaec3bb157c3bde5f0365af30f4f *./tests/data/lavfi/pixfmts_hflip_le-yuvj420p.nut
+7604654 ./tests/data/lavfi/pixfmts_hflip_le-yuvj420p.nut
+d113871528d510a192797af59df9c05c *./tests/data/lavfi/pixfmts_hflip_le-yuvj422p.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-yuvj422p.nut
+e8f7ed76e57c892a1e9e27a3f29452db *./tests/data/lavfi/pixfmts_hflip_le-yuvj440p.nut
+10139054 ./tests/data/lavfi/pixfmts_hflip_le-yuvj440p.nut
+2c3ae369607608c6dcb0d830f00f971a *./tests/data/lavfi/pixfmts_hflip_le-yuvj444p.nut
+15207903 ./tests/data/lavfi/pixfmts_hflip_le-yuvj444p.nut