FFmpeg
vf_thumbnail.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Smartjog S.A.S, Clément Bœsch <[email protected]>
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  * Potential thumbnail lookup filter to reduce the risk of an inappropriate
24  * selection (such as a black frame) we could get with an absolute seek.
25  *
26  * Simplified version of algorithm by Vadim Zaliva <[email protected]>.
27  * @see http://notbrainsurgery.livejournal.com/29773.html
28  */
29 
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 #include "avfilter.h"
35 #include "filters.h"
36 #include "formats.h"
37 
38 #define HIST_SIZE (3*256)
39 
40 struct thumb_frame {
41  AVFrame *buf; ///< cached frame
42  int histogram[HIST_SIZE]; ///< RGB color distribution histogram of the frame
43 };
44 
45 typedef struct ThumbContext {
46  const AVClass *class;
47  int n; ///< current frame
48  int loglevel;
49  int n_frames; ///< number of frames for analysis
50  struct thumb_frame *frames; ///< the n_frames frames
51  AVRational tb; ///< copy of the input timebase to ease access
52 
55 
56  int planewidth[4];
57  int planeheight[4];
58  int planes;
59  int bitdepth;
60 } ThumbContext;
61 
62 #define OFFSET(x) offsetof(ThumbContext, x)
63 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
64 
65 static const AVOption thumbnail_options[] = {
66  { "n", "set the frames batch size", OFFSET(n_frames), AV_OPT_TYPE_INT, {.i64=100}, 2, INT_MAX, FLAGS },
67  { "log", "force stats logging level", OFFSET(loglevel), AV_OPT_TYPE_INT, {.i64 = AV_LOG_INFO}, INT_MIN, INT_MAX, FLAGS, .unit = "level" },
68  { "quiet", "logging disabled", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_QUIET}, 0, 0, FLAGS, .unit = "level" },
69  { "info", "information logging level", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_INFO}, 0, 0, FLAGS, .unit = "level" },
70  { "verbose", "verbose logging level", 0, AV_OPT_TYPE_CONST, {.i64 = AV_LOG_VERBOSE}, 0, 0, FLAGS, .unit = "level" },
71  { NULL }
72 };
73 
75 
77 {
78  ThumbContext *s = ctx->priv;
79 
80  s->frames = av_calloc(s->n_frames, sizeof(*s->frames));
81  if (!s->frames) {
83  "Allocation failure, try to lower the number of frames\n");
84  return AVERROR(ENOMEM);
85  }
86  av_log(ctx, AV_LOG_VERBOSE, "batch size: %d frames\n", s->n_frames);
87  return 0;
88 }
89 
90 /**
91  * @brief Compute Sum-square deviation to estimate "closeness".
92  * @param hist color distribution histogram
93  * @param median average color distribution histogram
94  * @return sum of squared errors
95  */
96 static double frame_sum_square_err(const int *hist, const double *median)
97 {
98  int i;
99  double err, sum_sq_err = 0;
100 
101  for (i = 0; i < HIST_SIZE; i++) {
102  err = median[i] - (double)hist[i];
103  sum_sq_err += err*err;
104  }
105  return sum_sq_err;
106 }
107 
109 {
110  AVFrame *picref;
111  ThumbContext *s = ctx->priv;
112  int i, j, best_frame_idx = 0;
113  int nb_frames = s->n;
114  double avg_hist[HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
115 
116  // average histogram of the N frames
117  for (j = 0; j < FF_ARRAY_ELEMS(avg_hist); j++) {
118  for (i = 0; i < nb_frames; i++)
119  avg_hist[j] += (double)s->frames[i].histogram[j];
120  avg_hist[j] /= nb_frames;
121  }
122 
123  // find the frame closer to the average using the sum of squared errors
124  for (i = 0; i < nb_frames; i++) {
125  sq_err = frame_sum_square_err(s->frames[i].histogram, avg_hist);
126  if (i == 0 || sq_err < min_sq_err)
127  best_frame_idx = i, min_sq_err = sq_err;
128  }
129 
130  // free and reset everything (except the best frame buffer)
131  for (i = 0; i < nb_frames; i++) {
132  memset(s->frames[i].histogram, 0, sizeof(s->frames[i].histogram));
133  if (i != best_frame_idx)
134  av_frame_free(&s->frames[i].buf);
135  }
136  s->n = 0;
137 
138  // raise the chosen one
139  picref = s->frames[best_frame_idx].buf;
140  if (s->loglevel != AV_LOG_QUIET)
141  av_log(ctx, s->loglevel, "frame id #%d (pts_time=%f) selected "
142  "from a set of %d images\n", best_frame_idx,
143  picref->pts * av_q2d(s->tb), nb_frames);
144  s->frames[best_frame_idx].buf = NULL;
145 
146  return picref;
147 }
148 
149 static void get_hist8(int *hist, const uint8_t *p, ptrdiff_t stride,
150  ptrdiff_t width, ptrdiff_t height)
151 {
152  int shist[4][256] = {0};
153 
154  const int width4 = width & ~3;
155  while (height--) {
156  for (int x = 0; x < width4; x += 4) {
157  const uint32_t v = AV_RN32(&p[x]);
158  shist[0][(uint8_t) (v >> 0)]++;
159  shist[1][(uint8_t) (v >> 8)]++;
160  shist[2][(uint8_t) (v >> 16)]++;
161  shist[3][(uint8_t) (v >> 24)]++;
162  }
163  /* handle tail */
164  for (int x = width4; x < width; x++)
165  hist[p[x]]++;
166  p += stride;
167  }
168 
169  for (int i = 0; i < 4; i++) {
170  for (int j = 0; j < 256; j++)
171  hist[j] += shist[i][j];
172  }
173 }
174 
175 static void get_hist16(int *hist, const uint8_t *p, ptrdiff_t stride,
176  ptrdiff_t width, ptrdiff_t height, int shift)
177 {
178  int shist[4][256] = {0};
179 
180  const int width4 = width & ~3;
181  while (height--) {
182  const uint16_t *p16 = (const uint16_t *) p;
183  for (int x = 0; x < width4; x += 4) {
184  const uint64_t v = AV_RN64(&p16[x]);
185  shist[0][(uint8_t) (v >> (shift + 0))]++;
186  shist[1][(uint8_t) (v >> (shift + 16))]++;
187  shist[2][(uint8_t) (v >> (shift + 32))]++;
188  shist[3][(uint8_t) (v >> (shift + 48))]++;
189  }
190  /* handle tail */
191  for (int x = width4; x < width; x++)
192  hist[p16[x]]++;
193  p += stride;
194  }
195 
196  for (int i = 0; i < 4; i++) {
197  for (int j = 0; j < 256; j++)
198  hist[j] += shist[i][j];
199  }
200 }
201 
202 static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
203 {
204  ThumbContext *s = ctx->priv;
205  AVFrame *frame = arg;
206  int *hist = s->thread_histogram + HIST_SIZE * jobnr;
207  const int h = frame->height;
208  const int w = frame->width;
209  const int slice_start = (h * jobnr) / nb_jobs;
210  const int slice_end = (h * (jobnr+1)) / nb_jobs;
211  const uint8_t *p = frame->data[0] + slice_start * frame->linesize[0];
212 
213  memset(hist, 0, sizeof(*hist) * HIST_SIZE);
214 
215  switch (frame->format) {
216  case AV_PIX_FMT_RGB24:
217  case AV_PIX_FMT_BGR24:
218  for (int j = slice_start; j < slice_end; j++) {
219  for (int i = 0; i < w; i++) {
220  hist[0*256 + p[i*3 ]]++;
221  hist[1*256 + p[i*3 + 1]]++;
222  hist[2*256 + p[i*3 + 2]]++;
223  }
224  p += frame->linesize[0];
225  }
226  break;
227  case AV_PIX_FMT_RGB0:
228  case AV_PIX_FMT_BGR0:
229  case AV_PIX_FMT_RGBA:
230  case AV_PIX_FMT_BGRA:
231  for (int j = slice_start; j < slice_end; j++) {
232  for (int i = 0; i < w; i++) {
233  hist[0*256 + p[i*4 ]]++;
234  hist[1*256 + p[i*4 + 1]]++;
235  hist[2*256 + p[i*4 + 2]]++;
236  }
237  p += frame->linesize[0];
238  }
239  break;
240  case AV_PIX_FMT_0RGB:
241  case AV_PIX_FMT_0BGR:
242  case AV_PIX_FMT_ARGB:
243  case AV_PIX_FMT_ABGR:
244  for (int j = slice_start; j < slice_end; j++) {
245  for (int i = 0; i < w; i++) {
246  hist[0*256 + p[i*4 + 1]]++;
247  hist[1*256 + p[i*4 + 2]]++;
248  hist[2*256 + p[i*4 + 3]]++;
249  }
250  p += frame->linesize[0];
251  }
252  break;
253  default:
254  for (int plane = 0; plane < s->planes; plane++) {
255  const int slice_start = (s->planeheight[plane] * jobnr) / nb_jobs;
256  const int slice_end = (s->planeheight[plane] * (jobnr+1)) / nb_jobs;
257  const uint8_t *p = frame->data[plane] + slice_start * frame->linesize[plane];
258  const ptrdiff_t linesize = frame->linesize[plane];
259  const int planewidth = s->planewidth[plane];
260  int *hhist = hist + 256 * plane;
261  if (s->bitdepth > 8) {
262  get_hist16(hhist, p, linesize, planewidth, slice_end - slice_start,
263  s->bitdepth - 8);
264  } else {
265  get_hist8(hhist, p, linesize, planewidth, slice_end - slice_start);
266  }
267  }
268  break;
269  }
270 
271  return 0;
272 }
273 
275 {
276  AVFilterContext *ctx = inlink->dst;
277  ThumbContext *s = ctx->priv;
278  AVFilterLink *outlink = ctx->outputs[0];
279  int *hist = s->frames[s->n].histogram;
280 
281  // keep a reference of each frame
282  s->frames[s->n].buf = frame;
283 
285  FFMIN(frame->height, s->nb_threads));
286 
287  // update current frame histogram
288  for (int j = 0; j < FFMIN(frame->height, s->nb_threads); j++) {
289  int *thread_histogram = s->thread_histogram + HIST_SIZE * j;
290 
291  for (int i = 0; i < HIST_SIZE; i++)
292  hist[i] += thread_histogram[i];
293  }
294 
295  // no selection until the buffer of N frames is filled up
296  s->n++;
297  if (s->n < s->n_frames)
298  return 0;
299 
300  return ff_filter_frame(outlink, get_best_frame(ctx));
301 }
302 
304 {
305  int i;
306  ThumbContext *s = ctx->priv;
307  for (i = 0; i < s->n_frames && s->frames && s->frames[i].buf; i++)
308  av_frame_free(&s->frames[i].buf);
309  av_freep(&s->frames);
310  av_freep(&s->thread_histogram);
311 }
312 
314 {
315  AVFilterContext *ctx = link->src;
316  ThumbContext *s = ctx->priv;
317  int ret = ff_request_frame(ctx->inputs[0]);
318 
319  if (ret == AVERROR_EOF && s->n) {
321  if (ret < 0)
322  return ret;
323  ret = AVERROR_EOF;
324  }
325  if (ret < 0)
326  return ret;
327  return 0;
328 }
329 
331 {
332  AVFilterContext *ctx = inlink->dst;
333  ThumbContext *s = ctx->priv;
335 
336  s->nb_threads = ff_filter_get_nb_threads(ctx);
337  s->thread_histogram = av_calloc(HIST_SIZE, s->nb_threads * sizeof(*s->thread_histogram));
338  if (!s->thread_histogram)
339  return AVERROR(ENOMEM);
340 
341  s->tb = inlink->time_base;
342  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
343  s->planewidth[0] = s->planewidth[3] = inlink->w;
344  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
345  s->planeheight[0] = s->planeheight[3] = inlink->h;
346  s->planes = av_pix_fmt_count_planes(inlink->format) - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
347  s->bitdepth = desc->comp[0].depth;
348 
349  return 0;
350 }
351 
352 static const enum AVPixelFormat packed_rgb_fmts[] = {
359 };
360 
362  AVFilterFormatsConfig **cfg_in,
363  AVFilterFormatsConfig **cfg_out)
364 {
365  const AVPixFmtDescriptor *desc = NULL;
367 
369  if (!formats)
370  return AVERROR(ENOMEM);
371 
372 
373  while ((desc = av_pix_fmt_desc_next(desc))) {
374  int color_comps = desc->nb_components - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
375  if ((color_comps == 1 || (desc->flags & AV_PIX_FMT_FLAG_PLANAR)) &&
377  (desc->comp[0].depth <= 8 || HAVE_BIGENDIAN == !!(desc->flags & AV_PIX_FMT_FLAG_BE)) &&
378  (desc->nb_components < 3 || desc->comp[1].plane != desc->comp[2].plane) &&
379  desc->comp[0].depth <= 16)
380  {
382  if (ret < 0)
383  return ret;
384  }
385  }
386 
387  return ff_set_common_formats2(ctx, cfg_in, cfg_out, formats);
388 }
389 
390 static const AVFilterPad thumbnail_inputs[] = {
391  {
392  .name = "default",
393  .type = AVMEDIA_TYPE_VIDEO,
394  .config_props = config_props,
395  .filter_frame = filter_frame,
396  },
397 };
398 
399 static const AVFilterPad thumbnail_outputs[] = {
400  {
401  .name = "default",
402  .type = AVMEDIA_TYPE_VIDEO,
403  .request_frame = request_frame,
404  },
405 };
406 
408  .p.name = "thumbnail",
409  .p.description = NULL_IF_CONFIG_SMALL("Select the most representative frame in a given sequence of consecutive frames."),
410  .p.priv_class = &thumbnail_class,
413  .priv_size = sizeof(ThumbContext),
414  .init = init,
415  .uninit = uninit,
419 };
formats
formats
Definition: signature.h:47
ThumbContext
Definition: vf_thumbnail.c:45
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
get_hist8
static void get_hist8(int *hist, const uint8_t *p, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height)
Definition: vf_thumbnail.c:149
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
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(thumbnail)
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:435
AV_LOG_QUIET
#define AV_LOG_QUIET
Print no output.
Definition: log.h:192
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3441
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
thumb_frame::histogram
int histogram[HIST_SIZE]
RGB color distribution histogram of the frame.
Definition: vf_thumbnail.c:42
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1007
thumb_frame::buf
AVFrame * buf
cached frame
Definition: vf_thumbnail.c:41
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_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:158
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:364
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:523
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:429
av_pix_fmt_desc_next
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:3448
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:480
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:215
OFFSET
#define OFFSET(x)
Definition: vf_thumbnail.c:62
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
thumb_frame
Definition: vf_thumbnail.c:40
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3481
ThumbContext::frames
struct thumb_frame * frames
the n_frames frames
Definition: vf_thumbnail.c:50
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition: mpeg12dec.c:1688
do_slice
static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_thumbnail.c:202
ThumbContext::planes
int planes
Definition: vf_thumbnail.c:58
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
FFFilter
Definition: filters.h:266
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_thumbnail.c:361
ThumbContext::planeheight
int planeheight[4]
Definition: vf_thumbnail.c:57
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
ThumbContext::tb
AVRational tb
copy of the input timebase to ease access
Definition: vf_thumbnail.c:51
packed_rgb_fmts
static enum AVPixelFormat packed_rgb_fmts[]
Definition: vf_thumbnail.c:352
filters.h
get_hist16
static void get_hist16(int *hist, const uint8_t *p, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int shift)
Definition: vf_thumbnail.c:175
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ThumbContext::n_frames
int n_frames
number of frames for analysis
Definition: vf_thumbnail.c:49
ThumbContext::loglevel
int loglevel
Definition: vf_thumbnail.c:48
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
get_best_frame
static AVFrame * get_best_frame(AVFilterContext *ctx)
Definition: vf_thumbnail.c:108
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
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
arg
const char * arg
Definition: jacosubdec.c:67
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
FLAGS
#define FLAGS
Definition: vf_thumbnail.c:63
ThumbContext::bitdepth
int bitdepth
Definition: vf_thumbnail.c:59
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:504
double
double
Definition: af_crystalizer.c:132
config_props
static int config_props(AVFilterLink *inlink)
Definition: vf_thumbnail.c:330
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:265
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:121
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
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
request_frame
static int request_frame(AVFilterLink *link)
Definition: vf_thumbnail.c:313
height
#define height
Definition: dsp.h:89
shift
static int shift(int a, int b)
Definition: bonk.c:261
thumbnail_outputs
static const AVFilterPad thumbnail_outputs[]
Definition: vf_thumbnail.c:399
ff_vf_thumbnail
const FFFilter ff_vf_thumbnail
Definition: vf_thumbnail.c:407
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_thumbnail.c:303
AV_PIX_FMT_FLAG_BITSTREAM
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:124
ThumbContext::n
int n
current frame
Definition: vf_thumbnail.c:47
av_pix_fmt_desc_get_id
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:3460
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:263
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:192
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
thumbnail
static int thumbnail(AVFilterContext *ctx, int *histogram, AVFrame *in)
Definition: vf_thumbnail_cuda.c:200
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_thumbnail.c:274
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
frame_sum_square_err
static double frame_sum_square_err(const int *hist, const double *median)
Compute Sum-square deviation to estimate "closeness".
Definition: vf_thumbnail.c:96
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:840
ThumbContext::thread_histogram
int * thread_histogram
Definition: vf_thumbnail.c:54
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:240
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_FLAG_BE
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:116
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:845
stride
#define stride
Definition: h264pred_template.c:536
ret
ret
Definition: filter_design.txt:187
HIST_SIZE
#define HIST_SIZE
Definition: vf_thumbnail.c:38
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:264
frame
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
ff_filter_execute
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:1686
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
thumbnail_inputs
static const AVFilterPad thumbnail_inputs[]
Definition: vf_thumbnail.c:390
avfilter.h
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
AVFilterContext
An instance of a filter.
Definition: avfilter.h:269
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:162
desc
const char * desc
Definition: libsvtav1.c:79
ThumbContext::nb_threads
int nb_threads
Definition: vf_thumbnail.c:53
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
mem.h
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:262
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_thumbnail.c:76
h
h
Definition: vp9dsp_template.c:2070
width
#define width
Definition: dsp.h:89
thumbnail_options
static const AVOption thumbnail_options[]
Definition: vf_thumbnail.c:65
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
ThumbContext::planewidth
int planewidth[4]
Definition: vf_thumbnail.c:56