Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 A'rpi
3  * Copyright (C) 2012 Clément Bœsch
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
22 /**
23  * @file
24  * libpostproc filter, ported from MPlayer.
25  */
27 #include "libavutil/avassert.h"
28 #include "libavutil/opt.h"
29 #include "internal.h"
33 typedef struct PPFilterContext {
34  const AVClass *class;
35  char *subfilters;
36  int mode_id;
38  void *pp_ctx;
41 #define OFFSET(x) offsetof(PPFilterContext, x)
43 static const AVOption pp_options[] = {
44  { "subfilters", "set postprocess subfilters", OFFSET(subfilters), AV_OPT_TYPE_STRING, {.str="de"}, .flags = FLAGS },
45  { NULL }
46 };
51 {
52  int i;
53  PPFilterContext *pp = ctx->priv;
55  for (i = 0; i <= PP_QUALITY_MAX; i++) {
57  if (!pp->modes[i])
59  }
60  pp->mode_id = PP_QUALITY_MAX;
61  return 0;
62 }
64 static int pp_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
65  char *res, int res_len, int flags)
66 {
67  PPFilterContext *pp = ctx->priv;
69  if (!strcmp(cmd, "quality")) {
70  pp->mode_id = av_clip(strtol(args, NULL, 10), 0, PP_QUALITY_MAX);
71  return 0;
72  }
73  return AVERROR(ENOSYS);
74 }
77 {
78  static const enum AVPixelFormat pix_fmts[] = {
87  };
89  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
90  if (!fmts_list)
91  return AVERROR(ENOMEM);
92  return ff_set_common_formats(ctx, fmts_list);
93 }
96 {
97  int flags = PP_CPU_CAPS_AUTO;
98  PPFilterContext *pp = inlink->dst->priv;
100  switch (inlink->format) {
101  case AV_PIX_FMT_GRAY8:
102  case AV_PIX_FMT_YUVJ420P:
103  case AV_PIX_FMT_YUV420P: flags |= PP_FORMAT_420; break;
104  case AV_PIX_FMT_YUVJ422P:
105  case AV_PIX_FMT_YUV422P: flags |= PP_FORMAT_422; break;
106  case AV_PIX_FMT_YUV411P: flags |= PP_FORMAT_411; break;
107  case AV_PIX_FMT_GBRP:
108  case AV_PIX_FMT_YUVJ444P:
109  case AV_PIX_FMT_YUV444P: flags |= PP_FORMAT_444; break;
110  case AV_PIX_FMT_YUVJ440P:
111  case AV_PIX_FMT_YUV440P: flags |= PP_FORMAT_440; break;
112  default: av_assert0(0);
113  }
115  pp->pp_ctx = pp_get_context(inlink->w, inlink->h, flags);
116  if (!pp->pp_ctx)
117  return AVERROR(ENOMEM);
118  return 0;
119 }
122 {
123  AVFilterContext *ctx = inlink->dst;
124  PPFilterContext *pp = ctx->priv;
125  AVFilterLink *outlink = ctx->outputs[0];
126  const int aligned_w = FFALIGN(outlink->w, 8);
127  const int aligned_h = FFALIGN(outlink->h, 8);
128  AVFrame *outbuf;
129  int qstride, qp_type;
130  int8_t *qp_table ;
132  outbuf = ff_get_video_buffer(outlink, aligned_w, aligned_h);
133  if (!outbuf) {
134  av_frame_free(&inbuf);
135  return AVERROR(ENOMEM);
136  }
137  av_frame_copy_props(outbuf, inbuf);
138  outbuf->width = inbuf->width;
139  outbuf->height = inbuf->height;
140  qp_table = av_frame_get_qp_table(inbuf, &qstride, &qp_type);
142  pp_postprocess((const uint8_t **)inbuf->data, inbuf->linesize,
143  outbuf->data, outbuf->linesize,
144  aligned_w, outlink->h,
145  qp_table,
146  qstride,
147  pp->modes[pp->mode_id],
148  pp->pp_ctx,
149  outbuf->pict_type | (qp_type ? PP_PICT_TYPE_QP2 : 0));
151  av_frame_free(&inbuf);
152  return ff_filter_frame(outlink, outbuf);
153 }
156 {
157  int i;
158  PPFilterContext *pp = ctx->priv;
160  for (i = 0; i <= PP_QUALITY_MAX; i++)
161  pp_free_mode(pp->modes[i]);
162  if (pp->pp_ctx)
163  pp_free_context(pp->pp_ctx);
164 }
166 static const AVFilterPad pp_inputs[] = {
167  {
168  .name = "default",
169  .type = AVMEDIA_TYPE_VIDEO,
170  .config_props = pp_config_props,
171  .filter_frame = pp_filter_frame,
172  },
173  { NULL }
174 };
176 static const AVFilterPad pp_outputs[] = {
177  {
178  .name = "default",
179  .type = AVMEDIA_TYPE_VIDEO,
180  },
181  { NULL }
182 };
185  .name = "pp",
186  .description = NULL_IF_CONFIG_SMALL("Filter video using libpostproc."),
187  .priv_size = sizeof(PPFilterContext),
188  .init = pp_init,
189  .uninit = pp_uninit,
191  .inputs = pp_inputs,
192  .outputs = pp_outputs,
194  .priv_class = &pp_class,
196 };
static av_cold void pp_uninit(AVFilterContext *ctx)
Definition: vf_pp.c:155
#define NULL
Definition: coverity.c:32
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
Definition: opt.h:248
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
av_cold void pp_free_context(void *vc)
Definition: postprocess.c:912
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
pp_mode * pp_get_mode_by_name_and_quality(const char *name, int quality)
Return a pp_mode or NULL if an error occurred.
Definition: postprocess.c:641
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
av_cold pp_context * pp_get_context(int width, int height, int cpuCaps)
Definition: postprocess.c:879
#define PP_FORMAT_422
Definition: postprocess.h:96
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:287
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:126
const char * name
Pad name.
Definition: internal.h:60
static const AVFilterPad pp_outputs[]
Definition: vf_pp.c:176
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static const AVOption pp_options[]
Definition: vf_pp.c:43
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1091
void pp_postprocess(const uint8_t *src[3], const int srcStride[3], uint8_t *dst[3], const int dstStride[3], int width, int height, const int8_t *QP_store, int QPStride, pp_mode *vm, void *vc, int pict_type)
Definition: postprocess.c:935
#define av_cold
Definition: attributes.h:88
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
static av_cold int pp_init(AVFilterContext *ctx)
Definition: vf_pp.c:50
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define FFALIGN(x, a)
Definition: macros.h:48
A filter pad used for either input or output.
Definition: internal.h:54
Definition: postprocess.h:54
int width
Definition: frame.h:366
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:588
void pp_mode
Definition: postprocess.h:59
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
void * priv
private data for use by the filter
Definition: avfilter.h:354
simple assert() macros that are a bit more flexible than ISO C assert().
#define PP_FORMAT_411
Definition: postprocess.h:97
int mode_id
Definition: vf_pp.c:36
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:391
#define PP_PICT_TYPE_QP2
MPEG2 style QScale.
Definition: postprocess.h:101
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
void pp_free_mode(pp_mode *mode)
Definition: postprocess.c:837
AVFormatContext * ctx
Definition: movenc.c:48
char * subfilters
Definition: vf_pp.c:35
static const AVFilterPad pp_inputs[]
Definition: vf_pp.c:166
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AVFilter ff_vf_pp
Definition: vf_pp.c:184
external API header
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:339
#define PP_FORMAT_440
Definition: postprocess.h:99
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
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
static int pp_filter_frame(AVFilterLink *inlink, AVFrame *inbuf)
Definition: vf_pp.c:121
const char * name
Filter name.
Definition: avfilter.h:149
#define PP_FORMAT_444
Definition: postprocess.h:98
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:351
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:300
#define flags(name, subs,...)
Definition: cbs_av1.c:560
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:322
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: postprocess.h:92
void * pp_ctx
Definition: vf_pp.c:38
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
#define FLAGS
Definition: vf_pp.c:42
#define PP_FORMAT_420
Definition: postprocess.h:95
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
static int pp_query_formats(AVFilterContext *ctx)
Definition: vf_pp.c:76
A list of supported formats for one end of a filter link.
Definition: formats.h:65
An instance of a filter.
Definition: avfilter.h:339
static int pp_process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_pp.c:64
int height
Definition: frame.h:366
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_afftdn.c:1374
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
internal API functions
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int8_t * av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
Definition: frame.c:91
pp_mode * modes[PP_QUALITY_MAX+1]
Definition: vf_pp.c:37
Generic error in an external library.
Definition: error.h:57
Pixel format.
Definition: pixfmt.h:64
#define OFFSET(x)
Definition: vf_pp.c:41
static int pp_config_props(AVFilterLink *inlink)
Definition: vf_pp.c:95
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:671
int i
Definition: input.c:407