FFmpeg
vf_scale_vt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Zhao Zhili <zhilizhao@tencent.com>
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 #include <VideoToolbox/VideoToolbox.h>
22 
23 #include "libavutil/hwcontext.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 
28 #include "filters.h"
29 #include "scale_eval.h"
30 #include "video.h"
31 
32 typedef struct ScaleVtContext {
33  AVClass *class;
34 
35  VTPixelTransferSessionRef transfer;
38  char *w_expr;
39  char *h_expr;
40 
48 
50 {
51  ScaleVtContext *s = avctx->priv;
52  int ret;
53  CFStringRef value;
54 
55  ret = VTPixelTransferSessionCreate(kCFAllocatorDefault, &s->transfer);
56  if (ret != noErr) {
57  av_log(avctx, AV_LOG_ERROR, "transfer session create failed, %d\n", ret);
58  return AVERROR_EXTERNAL;
59  }
60 
61 #define STRING_OPTION(var_name, func_name, default_value) \
62  do { \
63  if (s->var_name##_string) { \
64  int var = av_##func_name##_from_name(s->var_name##_string); \
65  if (var < 0) { \
66  av_log(avctx, AV_LOG_ERROR, "Invalid %s.\n", #var_name); \
67  return AVERROR(EINVAL); \
68  } \
69  s->var_name = var; \
70  } else { \
71  s->var_name = default_value; \
72  } \
73  } while (0)
74 
76  STRING_OPTION(colour_transfer, color_transfer, AVCOL_TRC_UNSPECIFIED);
77  STRING_OPTION(colour_matrix, color_space, AVCOL_SPC_UNSPECIFIED);
78 
79  if (s->colour_primaries != AVCOL_PRI_UNSPECIFIED) {
81  if (!value) {
82  av_log(avctx, AV_LOG_ERROR,
83  "Doesn't support converting to colour primaries %s\n",
84  s->colour_primaries_string);
85  return AVERROR(ENOTSUP);
86  }
87  VTSessionSetProperty(s->transfer, kVTPixelTransferPropertyKey_DestinationColorPrimaries, value);
88  }
89 
90  if (s->colour_transfer != AVCOL_TRC_UNSPECIFIED) {
91  value = av_map_videotoolbox_color_trc_from_av(s->colour_transfer);
92  if (!value) {
93  av_log(avctx, AV_LOG_ERROR,
94  "Doesn't support converting to trc %s\n",
95  s->colour_transfer_string);
96  return AVERROR(ENOTSUP);
97  }
98  VTSessionSetProperty(s->transfer, kVTPixelTransferPropertyKey_DestinationTransferFunction, value);
99  }
100 
101  if (s->colour_matrix != AVCOL_SPC_UNSPECIFIED) {
103  if (!value) {
104  av_log(avctx, AV_LOG_ERROR,
105  "Doesn't support converting to colorspace %s\n",
106  s->colour_matrix_string);
107  return AVERROR(ENOTSUP);
108  }
109  VTSessionSetProperty(s->transfer, kVTPixelTransferPropertyKey_DestinationYCbCrMatrix, value);
110  }
111 
112  VTSessionSetProperty(s->transfer, kVTPixelTransferPropertyKey_ScalingMode, kVTScalingMode_CropSourceToCleanAperture);
113 
114  return 0;
115 }
116 
118 {
119  ScaleVtContext *s = avctx->priv;
120 
121  if (s->transfer) {
122  VTPixelTransferSessionInvalidate(s->transfer);
123  CFRelease(s->transfer);
124  s->transfer = NULL;
125  }
126 }
127 
129 {
130  int ret;
131  AVFilterContext *ctx = link->dst;
132  ScaleVtContext *s = ctx->priv;
133  AVFilterLink *outlink = ctx->outputs[0];
134  CVPixelBufferRef src;
135  CVPixelBufferRef dst;
136 
137  int left;
138  int top;
139  int width;
140  int height;
141  CFNumberRef crop_width_num;
142  CFNumberRef crop_height_num;
143  CFNumberRef crop_offset_left_num;
144  CFNumberRef crop_offset_top_num;
145  const void *clean_aperture_keys[4];
146  const void *source_clean_aperture_values[4];
147  CFDictionaryRef source_clean_aperture;
148 
149  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
150  if (!out) {
151  ret = AVERROR(ENOMEM);
152  goto fail;
153  }
154 
155  ret = av_frame_copy_props(out, in);
156  if (ret < 0)
157  goto fail;
158 
159  out->crop_left = 0;
160  out->crop_top = 0;
161  out->crop_right = 0;
162  out->crop_bottom = 0;
163 
164  av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
165  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
166  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
167  INT_MAX);
168  if (s->colour_primaries != AVCOL_PRI_UNSPECIFIED)
169  out->color_primaries = s->colour_primaries;
170  if (s->colour_transfer != AVCOL_TRC_UNSPECIFIED)
171  out->color_trc = s->colour_transfer;
172  if (s->colour_matrix != AVCOL_SPC_UNSPECIFIED)
173  out->colorspace = s->colour_matrix;
174 
175  width = (in->width - in->crop_right) - in->crop_left;
176  height = (in->height - in->crop_bottom) - in->crop_top;
177  // The crop offsets are relative to the center of the frame.
178  // the crop width and crop height are relative to the center of the crop rect, not top left as normal.
179  left = in->crop_left - in->width / 2 + width / 2;
180  top = in->crop_top - in->height / 2 + height / 2;
181  crop_width_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &width);
182  crop_height_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &height);
183  crop_offset_left_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &left);
184  crop_offset_top_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &top);
185 
186  clean_aperture_keys[0] = kCVImageBufferCleanApertureWidthKey;
187  clean_aperture_keys[1] = kCVImageBufferCleanApertureHeightKey;
188  clean_aperture_keys[2] = kCVImageBufferCleanApertureHorizontalOffsetKey;
189  clean_aperture_keys[3] = kCVImageBufferCleanApertureVerticalOffsetKey;
190 
191  source_clean_aperture_values[0] = crop_width_num;
192  source_clean_aperture_values[1] = crop_height_num;
193  source_clean_aperture_values[2] = crop_offset_left_num;
194  source_clean_aperture_values[3] = crop_offset_top_num;
195 
196  source_clean_aperture = CFDictionaryCreate(kCFAllocatorDefault,
197  clean_aperture_keys,
198  source_clean_aperture_values,
199  4,
200  &kCFTypeDictionaryKeyCallBacks,
201  &kCFTypeDictionaryValueCallBacks);
202 
203  CFRelease(crop_width_num);
204  CFRelease(crop_height_num);
205  CFRelease(crop_offset_left_num);
206  CFRelease(crop_offset_top_num);
207 
208  src = (CVPixelBufferRef)in->data[3];
209  dst = (CVPixelBufferRef)out->data[3];
210  CVBufferSetAttachment(src, kCVImageBufferCleanApertureKey,
211  source_clean_aperture, kCVAttachmentMode_ShouldPropagate);
212  ret = VTPixelTransferSessionTransferImage(s->transfer, src, dst);
213  CFRelease(source_clean_aperture);
214  if (ret != noErr) {
215  av_log(ctx, AV_LOG_ERROR, "transfer image failed, %d\n", ret);
217  goto fail;
218  }
219 
220  av_frame_free(&in);
221 
222  return ff_filter_frame(outlink, out);
223 
224 fail:
225  av_frame_free(&in);
226  av_frame_free(&out);
227  return ret;
228 }
229 
231 {
232  int err;
233  FilterLink *outl = ff_filter_link(outlink);
234  AVFilterContext *avctx = outlink->src;
235  ScaleVtContext *s = avctx->priv;
236  AVFilterLink *inlink = outlink->src->inputs[0];
238  AVHWFramesContext *hw_frame_ctx_in;
239  AVHWFramesContext *hw_frame_ctx_out;
240 
241  err = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
242  &s->output_width,
243  &s->output_height);
244  if (err < 0)
245  return err;
246 
247  ff_scale_adjust_dimensions(inlink, &s->output_width, &s->output_height, 0, 1);
248 
249  outlink->w = s->output_width;
250  outlink->h = s->output_height;
251 
252  if (inlink->sample_aspect_ratio.num) {
253  AVRational r = {outlink->h * inlink->w, outlink->w * inlink->h};
254  outlink->sample_aspect_ratio = av_mul_q(r, inlink->sample_aspect_ratio);
255  } else {
256  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
257  }
258 
259  hw_frame_ctx_in = (AVHWFramesContext *)inl->hw_frames_ctx->data;
260 
262  outl->hw_frames_ctx = av_hwframe_ctx_alloc(hw_frame_ctx_in->device_ref);
263  hw_frame_ctx_out = (AVHWFramesContext *)outl->hw_frames_ctx->data;
264  hw_frame_ctx_out->format = AV_PIX_FMT_VIDEOTOOLBOX;
265  hw_frame_ctx_out->sw_format = hw_frame_ctx_in->sw_format;
266  hw_frame_ctx_out->width = outlink->w;
267  hw_frame_ctx_out->height = outlink->h;
268  ((AVVTFramesContext *)hw_frame_ctx_out->hwctx)->color_range = ((AVVTFramesContext *)hw_frame_ctx_in->hwctx)->color_range;
269 
270  err = ff_filter_init_hw_frames(avctx, outlink, 1);
271  if (err < 0)
272  return err;
273 
274  err = av_hwframe_ctx_init(outl->hw_frames_ctx);
275  if (err < 0) {
276  av_log(avctx, AV_LOG_ERROR,
277  "Failed to init videotoolbox frame context, %s\n",
278  av_err2str(err));
279  return err;
280  }
281 
282  return 0;
283 }
284 
285 #define OFFSET(x) offsetof(ScaleVtContext, x)
286 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
287 static const AVOption scale_vt_options[] = {
288  { "w", "Output video width",
289  OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = FLAGS },
290  { "h", "Output video height",
291  OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = FLAGS },
292  { "color_matrix", "Output colour matrix coefficient set",
293  OFFSET(colour_matrix_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
294  { "color_primaries", "Output colour primaries",
295  OFFSET(colour_primaries_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
296  { "color_transfer", "Output colour transfer characteristics",
297  OFFSET(colour_transfer_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
298  { NULL },
299 };
300 
301 AVFILTER_DEFINE_CLASS(scale_vt);
302 
303 static const AVFilterPad scale_vt_inputs[] = {
304  {
305  .name = "default",
306  .type = AVMEDIA_TYPE_VIDEO,
307  .filter_frame = &scale_vt_filter_frame,
308  },
309 };
310 
311 static const AVFilterPad scale_vt_outputs[] = {
312  {
313  .name = "default",
314  .type = AVMEDIA_TYPE_VIDEO,
315  .config_props = &scale_vt_config_output,
316  },
317 };
318 
320  .name = "scale_vt",
321  .description = NULL_IF_CONFIG_SMALL("Scale Videotoolbox frames"),
322  .priv_size = sizeof(ScaleVtContext),
323  .init = scale_vt_init,
328  .priv_class = &scale_vt_class,
329  .flags = AVFILTER_FLAG_HWDEVICE,
330  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
331 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
av_map_videotoolbox_color_trc_from_av
CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteristic trc)
Convert an AVColorTransferCharacteristic to a VideoToolbox/CoreVideo color transfer function string.
Definition: hwcontext_videotoolbox.c:490
r
const char * r
Definition: vf_curves.c:127
AVERROR
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
opt.h
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:611
out
FILE * out
Definition: movenc.c:55
av_map_videotoolbox_color_matrix_from_av
CFStringRef av_map_videotoolbox_color_matrix_from_av(enum AVColorSpace space)
Convert an AVColorSpace to a VideoToolbox/CoreVideo color matrix string.
Definition: hwcontext_videotoolbox.c:438
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1061
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:197
ff_vf_scale_vt
const AVFilter ff_vf_scale_vt
Definition: vf_scale_vt.c:319
int64_t
long long int64_t
Definition: coverity.c:34
inlink
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: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:322
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
AVFrame::width
int width
Definition: frame.h:461
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:248
AVOption
AVOption.
Definition: opt.h:429
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:614
ff_scale_eval_dimensions
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
Definition: scale_eval.c:57
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:586
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:217
video.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
scale_vt_filter_frame
static int scale_vt_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_vt.c:128
FLAGS
#define FLAGS
Definition: vf_scale_vt.c:286
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:472
fail
#define fail()
Definition: checkasm.h:189
scale_vt_init
static av_cold int scale_vt_init(AVFilterContext *avctx)
Definition: vf_scale_vt.c:49
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
OFFSET
#define OFFSET(x)
Definition: vf_scale_vt.c:285
scale_vt_config_output
static int scale_vt_config_output(AVFilterLink *outlink)
Definition: vf_scale_vt.c:230
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
av_map_videotoolbox_color_primaries_from_av
CFStringRef av_map_videotoolbox_color_primaries_from_av(enum AVColorPrimaries pri)
Convert an AVColorPrimaries to a VideoToolbox/CoreVideo color primaries string.
Definition: hwcontext_videotoolbox.c:465
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
AVHWFramesContext::height
int height
Definition: hwcontext.h:217
s
#define s(width, name)
Definition: cbs_vp9.c:198
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVFrame::crop_right
size_t crop_right
Definition: frame.h:769
color_range
color_range
Definition: vf_selectivecolor.c:43
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:589
AVVTFramesContext
Definition: hwcontext_videotoolbox.h:45
link
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 link
Definition: filter_design.txt:23
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:210
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:725
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
ScaleVtContext::output_width
int output_width
Definition: vf_scale_vt.c:36
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:126
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:465
ScaleVtContext::colour_primaries_string
char * colour_primaries_string
Definition: vf_scale_vt.c:44
ScaleVtContext::w_expr
char * w_expr
Definition: vf_scale_vt.c:38
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
AVFrame::crop_bottom
size_t crop_bottom
Definition: frame.h:767
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:206
color_primaries
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition: csp.c:76
hwcontext_videotoolbox.h
AVFrame::crop_left
size_t crop_left
Definition: frame.h:768
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
ScaleVtContext::colour_primaries
enum AVColorPrimaries colour_primaries
Definition: vf_scale_vt.c:41
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
ScaleVtContext::h_expr
char * h_expr
Definition: vf_scale_vt.c:39
height
#define height
Definition: dsp.h:85
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:173
ScaleVtContext::transfer
VTPixelTransferSessionRef transfer
Definition: vf_scale_vt.c:35
scale_eval.h
ScaleVtContext::output_height
int output_height
Definition: vf_scale_vt.c:37
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
scale_vt_uninit
static av_cold void scale_vt_uninit(AVFilterContext *avctx)
Definition: vf_scale_vt.c:117
ScaleVtContext::colour_transfer_string
char * colour_transfer_string
Definition: vf_scale_vt.c:45
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:640
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
scale_vt_options
static const AVOption scale_vt_options[]
Definition: vf_scale_vt.c:287
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:643
scale_vt_outputs
static const AVFilterPad scale_vt_outputs[]
Definition: vf_scale_vt.c:311
ScaleVtContext::colour_transfer
enum AVColorTransferCharacteristic colour_transfer
Definition: vf_scale_vt.c:42
AVFilter
Filter definition.
Definition: avfilter.h:201
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
ret
ret
Definition: filter_design.txt:187
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:150
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:496
ff_scale_adjust_dimensions
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
Definition: scale_eval.c:113
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(scale_vt)
AVFrame::height
int height
Definition: frame.h:461
AVRational::den
int den
Denominator.
Definition: rational.h:60
scale_vt_inputs
static const AVFilterPad scale_vt_inputs[]
Definition: vf_scale_vt.c:303
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
STRING_OPTION
#define STRING_OPTION(var_name, func_name, default_value)
AVFrame::crop_top
size_t crop_top
Definition: frame.h:766
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
width
#define width
Definition: dsp.h:85
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252
ScaleVtContext::colour_matrix
enum AVColorSpace colour_matrix
Definition: vf_scale_vt.c:43
ScaleVtContext::colour_matrix_string
char * colour_matrix_string
Definition: vf_scale_vt.c:46
src
#define src
Definition: vp8dsp.c:248
ff_filter_init_hw_frames
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
Definition: avfilter.c:1638
ScaleVtContext
Definition: vf_scale_vt.c:32