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 "internal.h"
30 #include "video.h"
31 
32 typedef struct {
33  int vsub; ///< vertical chroma subsampling
34 } FlipContext;
35 
37 {
38  FlipContext *flip = link->dst->priv;
39  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
40 
41  flip->vsub = desc->log2_chroma_h;
42 
43  return 0;
44 }
45 
47 {
48  FlipContext *flip = link->dst->priv;
49  AVFrame *frame;
50  int i;
51 
52  frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
53  if (!frame)
54  return NULL;
55 
56  for (i = 0; i < 4; i ++) {
57  int vsub = i == 1 || i == 2 ? flip->vsub : 0;
58 
59  if (frame->data[i]) {
60  frame->data[i] += (((h + (1<<vsub) - 1) >> vsub) - 1) * frame->linesize[i];
61  frame->linesize[i] = -frame->linesize[i];
62  }
63  }
64 
65  return frame;
66 }
67 
69 {
70  FlipContext *flip = link->dst->priv;
71  int i;
72 
73  for (i = 0; i < 4; i ++) {
74  int vsub = i == 1 || i == 2 ? flip->vsub : 0;
75 
76  if (frame->data[i]) {
77  frame->data[i] += (((link->h + (1<<vsub)-1)>> vsub)-1) * frame->linesize[i];
78  frame->linesize[i] = -frame->linesize[i];
79  }
80  }
81 
82  return ff_filter_frame(link->dst->outputs[0], frame);
83 }
85  {
86  .name = "default",
87  .type = AVMEDIA_TYPE_VIDEO,
88  .get_video_buffer = get_video_buffer,
89  .filter_frame = filter_frame,
90  .config_props = config_input,
91  },
92  { NULL }
93 };
94 
96  {
97  .name = "default",
98  .type = AVMEDIA_TYPE_VIDEO,
99  },
100  { NULL }
101 };
102 
104  .name = "vflip",
105  .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
106 
107  .priv_size = sizeof(FlipContext),
108 
109  .inputs = avfilter_vf_vflip_inputs,
110  .outputs = avfilter_vf_vflip_outputs,
111 };
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:143
output residual component w
const char * name
Pad name.
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
static const AVFilterPad avfilter_vf_vflip_inputs[]
Definition: vf_vflip.c:84
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: vf_vflip.c:68
frame
Definition: stft.m:14
A filter pad used for either input or output.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
Definition: avfilter.h:545
AVFilter avfilter_vf_vflip
Definition: vf_vflip.c:103
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
common internal API header
static int config_input(AVFilterLink *link)
Definition: vf_vflip.c:36
NULL
Definition: eval.c:55
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
const char * name
filter name
Definition: avfilter.h:437
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
static void flip(AVCodecContext *avctx, AVPicture *picture)
static const AVFilterPad avfilter_vf_vflip_outputs[]
Definition: vf_vflip.c:95
static AVFrame * get_video_buffer(AVFilterLink *link, int w, int h)
Definition: vf_vflip.c:46
int vsub
chroma subsampling
Definition: vf_hflip.c:40
internal API functions
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs