FFmpeg
Loading...
Searching...
No Matches
vf_vflip.c
Go to the documentation of this file.
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
23 * video vertical flip filter
24 */
25
26#include "libavutil/internal.h"
27#include "libavutil/pixdesc.h"
28#include "avfilter.h"
29#include "filters.h"
30#include "video.h"
31
32typedef struct FlipContext {
33 int vsub; ///< vertical chroma subsampling
34 int bayer;
36
37static int config_input(AVFilterLink *link)
38{
39 FlipContext *flip = link->dst->priv;
41
42 flip->vsub = desc->log2_chroma_h;
43 flip->bayer = !!(desc->flags & AV_PIX_FMT_FLAG_BAYER);
44
45 return 0;
46}
47
48static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
49{
50 FlipContext *flip = link->dst->priv;
52 int i;
53
54 frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
55 if (!frame)
56 return NULL;
57
58 for (i = 0; i < 4; i ++) {
59 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
60 int height = AV_CEIL_RSHIFT(h, vsub);
61
62 if (frame->data[i]) {
63 frame->data[i] += (height - 1) * frame->linesize[i];
64 frame->linesize[i] = -frame->linesize[i];
65 }
66 }
67
68 return frame;
69}
70
71static int flip_bayer(AVFilterLink *link, AVFrame *in)
72{
73 AVFilterContext *ctx = link->dst;
74 AVFilterLink *outlink = ctx->outputs[0];
75 AVFrame *out;
76 uint8_t *inrow = in->data[0], *outrow;
77 int i, width = outlink->w << (av_pix_fmt_desc_get(link->format)->comp[0].step > 1);
78 if (outlink->h & 1) {
79 av_log(ctx, AV_LOG_ERROR, "Bayer vertical flip needs even height\n");
81 }
82
83 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
84 if (!out) {
85 av_frame_free(&in);
86 return AVERROR(ENOMEM);
87 }
89 outrow = out->data[0] + out->linesize[0] * (outlink->h - 2);
90 for (i = 0; i < outlink->h >> 1; i++) {
91 memcpy(outrow, inrow, width);
92 memcpy(outrow + out->linesize[0], inrow + in->linesize[0], width);
93 inrow += 2 * in->linesize[0];
94 outrow -= 2 * out->linesize[0];
95 }
96 av_frame_free(&in);
97 return ff_filter_frame(outlink, out);
98}
99
101{
102 FlipContext *flip = link->dst->priv;
103 int i;
104
105 if (flip->bayer)
106 return flip_bayer(link, frame);
107
108 for (i = 0; i < 4; i ++) {
109 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
110 int height = AV_CEIL_RSHIFT(link->h, vsub);
111
112 if (frame->data[i]) {
113 frame->data[i] += (height - 1) * frame->linesize[i];
114 frame->linesize[i] = -frame->linesize[i];
115 }
116 }
117
118 return ff_filter_frame(link->dst->outputs[0], frame);
119}
121 {
122 .name = "default",
123 .type = AVMEDIA_TYPE_VIDEO,
124 .get_buffer.video = get_video_buffer,
125 .filter_frame = filter_frame,
126 .config_props = config_input,
127 },
128};
129
131 .p.name = "vflip",
132 .p.description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
134 .priv_size = sizeof(FlipContext),
137};
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_vflip
Definition vf_vflip.c:130
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition avf_concat.c:205
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
static AVFrame * frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static void flip(AVCodecContext *avctx, AVFrame *frame)
Definition rawdec.c:131
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
Definition pixdesc.h:152
int step
Number of elements between 2 horizontally consecutive pixels.
Definition pixdesc.h:40
An instance of a filter.
Definition avfilter.h:273
void * priv
private data for use by the filter
Definition avfilter.h:288
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
int vsub
vertical chroma subsampling
Definition vf_vflip.c:33
#define av_log(a,...)
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static int flip_bayer(AVFilterLink *link, AVFrame *in)
Definition vf_vflip.c:71
static AVFrame * get_video_buffer(AVFilterLink *link, int w, int h)
Definition vf_vflip.c:48
static const AVFilterPad avfilter_vf_vflip_inputs[]
Definition vf_vflip.c:120
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition vf_vflip.c:100
static int config_input(AVFilterLink *link)
Definition vf_vflip.c:37
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89