Go to the documentation of this file.
54 #define OFFSET(x) offsetof(VMAFMotionContext, x)
55 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
65 int h, ptrdiff_t _img1_stride, ptrdiff_t _img2_stride)
67 ptrdiff_t img1_stride = _img1_stride /
sizeof(*img1);
68 ptrdiff_t img2_stride = _img2_stride /
sizeof(*img2);
72 for (
i = 0;
i <
h;
i++) {
73 for (j = 0; j <
w; j++) {
84 uint16_t *dst,
int w,
int h, ptrdiff_t _src_stride,
85 ptrdiff_t _dst_stride)
87 ptrdiff_t src_stride = _src_stride /
sizeof(*src);
88 ptrdiff_t dst_stride = _dst_stride /
sizeof(*dst);
89 int radius = filt_w / 2;
90 int borders_left = radius;
91 int borders_right =
w - (filt_w - radius);
95 for (
i = 0;
i <
h;
i++) {
96 for (j = 0; j < borders_left; j++) {
98 for (k = 0; k < filt_w; k++) {
99 int j_tap =
FFABS(j - radius + k);
101 j_tap =
w - (j_tap -
w + 1);
103 sum +=
filter[k] *
src[
i * src_stride + j_tap];
108 for (j = borders_left; j < borders_right; j++) {
110 for (k = 0; k < filt_w; k++) {
111 sum +=
filter[k] *
src[
i * src_stride + j - radius + k];
116 for (j = borders_right; j <
w; j++) {
118 for (k = 0; k < filt_w; k++) {
119 int j_tap =
FFABS(j - radius + k);
121 j_tap =
w - (j_tap -
w + 1);
123 sum +=
filter[k] *
src[
i * src_stride + j_tap];
130 #define conv_y_fn(type, bits) \
131 static void convolution_y_##bits##bit(const uint16_t *filter, int filt_w, \
132 const uint8_t *_src, uint16_t *dst, \
133 int w, int h, ptrdiff_t _src_stride, \
134 ptrdiff_t _dst_stride) \
136 const type *src = (const type *) _src; \
137 ptrdiff_t src_stride = _src_stride / sizeof(*src); \
138 ptrdiff_t dst_stride = _dst_stride / sizeof(*dst); \
139 int radius = filt_w / 2; \
140 int borders_top = radius; \
141 int borders_bottom = h - (filt_w - radius); \
145 for (i = 0; i < borders_top; i++) { \
146 for (j = 0; j < w; j++) { \
148 for (k = 0; k < filt_w; k++) { \
149 int i_tap = FFABS(i - radius + k); \
151 i_tap = h - (i_tap - h + 1); \
153 sum += filter[k] * src[i_tap * src_stride + j]; \
155 dst[i * dst_stride + j] = sum >> bits; \
158 for (i = borders_top; i < borders_bottom; i++) { \
159 for (j = 0; j < w; j++) { \
161 for (k = 0; k < filt_w; k++) { \
162 sum += filter[k] * src[(i - radius + k) * src_stride + j]; \
164 dst[i * dst_stride + j] = sum >> bits; \
167 for (i = borders_bottom; i < h; i++) { \
168 for (j = 0; j < w; j++) { \
170 for (k = 0; k < filt_w; k++) { \
171 int i_tap = FFABS(i - radius + k); \
173 i_tap = h - (i_tap - h + 1); \
175 sum += filter[k] * src[i_tap * src_stride + j]; \
177 dst[i * dst_stride + j] = sum >> bits; \
187 dsp->convolution_y = bpp == 10 ? convolution_y_10bit : convolution_y_8bit;
195 s->vmafdsp.convolution_y(
s->filter, 5,
ref->data[0],
s->temp_data,
196 s->width,
s->height,
ref->linesize[0],
s->stride);
197 s->vmafdsp.convolution_x(
s->filter, 5,
s->temp_data,
s->blur_data[0],
198 s->width,
s->height,
s->stride,
s->stride);
203 uint64_t sad =
s->vmafdsp.sad(
s->blur_data[1],
s->blur_data[0],
204 s->width,
s->height,
s->stride,
s->stride);
209 FFSWAP(uint16_t *,
s->blur_data[0],
s->blur_data[1]);
211 s->motion_sum += score;
229 set_meta(&
ref->metadata,
"lavfi.vmafmotion.score", score);
231 fprintf(
s->stats_file,
232 "n:%"PRId64
" motion:%0.2lf\n",
s->data.nb_frames, score);
249 s->stride =
FFALIGN(
w *
sizeof(uint16_t), 32);
251 data_sz = (size_t)
s->stride *
h;
258 for (
i = 0;
i < 5;
i++) {
262 vmafmotiondsp_init(&
s->vmafdsp,
desc->comp[0].depth);
277 (
desc->comp[0].depth == 8 ||
desc->comp[0].depth == 10) &&
291 ctx->inputs[0]->h,
ctx->inputs[0]->format);
300 return s->nb_frames > 0 ?
s->motion_sum /
s->nb_frames : 0.0;
314 if (
s->stats_file_str) {
315 if (!strcmp(
s->stats_file_str,
"-")) {
316 s->stats_file = stdout;
319 if (!
s->stats_file) {
324 s->stats_file_str, buf);
338 if (
s->data.nb_frames > 0) {
342 if (
s->stats_file &&
s->stats_file != stdout)
343 fclose(
s->stats_file);
356 .
name =
"vmafmotion",
361 .priv_class = &vmafmotion_class,
AVPixelFormat
Pixel format.
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
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
This structure describes decoded (raw) audio or video data.
#define FILTER_QUERY_FUNC(func)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
const char * name
Filter name.
A link between two filters.
double ff_vmafmotion_process(VMAFMotionData *s, AVFrame *ref)
static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
static void convolution_x(const uint16_t *filter, int filt_w, const uint16_t *src, uint16_t *dst, int w, int h, ptrdiff_t _src_stride, ptrdiff_t _dst_stride)
static int config_input_ref(AVFilterLink *inlink)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
int ff_vmafmotion_init(VMAFMotionData *s, int w, int h, enum AVPixelFormat fmt)
#define FILTER_INPUTS(array)
static uint8_t img1[WIDTH *HEIGHT]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Describe the class of an AVClass context structure.
AVFILTER_DEFINE_CLASS(vmafmotion)
double ff_vmafmotion_uninit(VMAFMotionData *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
static uint8_t img2[WIDTH *HEIGHT]
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
static av_cold int init(AVFilterContext *ctx)
const AVFilter ff_vf_vmafmotion
#define AV_LOG_INFO
Standard information.
static uint64_t image_sad(const uint16_t *img1, const uint16_t *img2, int w, int h, ptrdiff_t _img1_stride, ptrdiff_t _img2_stride)
#define i(width, name, range_min, range_max)
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
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
const char * name
Pad name.
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
#define FFSWAP(type, a, b)
static int query_formats(AVFilterContext *ctx)
static const float FILTER_5[5]
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
static int ref[MAX_W *MAX_W]
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
static void do_vmafmotion(AVFilterContext *ctx, AVFrame *ref)
static const AVFilterPad vmafmotion_inputs[]
#define conv_y_fn(type, bits)
static const AVOption vmafmotion_options[]
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static av_cold void uninit(AVFilterContext *ctx)
#define flags(name, subs,...)
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
static void set_meta(AVDictionary **metadata, const char *key, float d)