Go to the documentation of this file.
35 #define HIST_SIZE (3*256)
53 #define OFFSET(x) offsetof(ThumbContext, x)
54 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
70 "Allocation failure, try to lower the number of frames\n");
86 double err, sum_sq_err = 0;
90 sum_sq_err += err*err;
99 int i, j, best_frame_idx = 0;
100 int nb_frames =
s->n;
101 double avg_hist[
HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
105 for (
i = 0;
i < nb_frames;
i++)
106 avg_hist[j] += (
double)
s->frames[
i].histogram[j];
107 avg_hist[j] /= nb_frames;
111 for (
i = 0;
i < nb_frames;
i++) {
113 if (
i == 0 || sq_err < min_sq_err)
114 best_frame_idx =
i, min_sq_err = sq_err;
118 for (
i = 0;
i < nb_frames;
i++) {
119 memset(
s->frames[
i].histogram, 0,
sizeof(
s->frames[
i].histogram));
120 if (
i != best_frame_idx)
126 picref =
s->frames[best_frame_idx].buf;
128 "from a set of %d images\n", best_frame_idx,
130 s->frames[best_frame_idx].buf =
NULL;
141 int *hist =
s->frames[
s->n].histogram;
142 const uint8_t *p =
frame->data[0];
151 for (j = 0; j <
inlink->h; j++) {
153 hist[0*256 + p[
i*3 ]]++;
154 hist[1*256 + p[
i*3 + 1]]++;
155 hist[2*256 + p[
i*3 + 2]]++;
157 p +=
frame->linesize[0];
164 for (j = 0; j <
inlink->h; j++) {
166 hist[0*256 + p[
i*4 ]]++;
167 hist[1*256 + p[
i*4 + 1]]++;
168 hist[2*256 + p[
i*4 + 2]]++;
170 p +=
frame->linesize[0];
177 for (j = 0; j <
inlink->h; j++) {
179 hist[0*256 + p[
i*4 + 1]]++;
180 hist[1*256 + p[
i*4 + 2]]++;
181 hist[2*256 + p[
i*4 + 3]]++;
183 p +=
frame->linesize[0];
187 for (
int plane = 0; plane < 3; plane++) {
188 const uint8_t *p =
frame->data[plane];
189 for (j = 0; j <
s->planeheight[plane]; j++) {
190 for (
i = 0;
i <
s->planewidth[plane];
i++)
191 hist[256*plane + p[
i]]++;
192 p +=
frame->linesize[plane];
200 if (
s->n <
s->n_frames)
210 for (
i = 0;
i <
s->n_frames &&
s->frames &&
s->frames[
i].buf;
i++)
240 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
242 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
283 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
290 .priv_class = &thumbnail_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
AVFILTER_DEFINE_CLASS(thumbnail)
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)
#define AVERROR_EOF
End of file.
int histogram[HIST_SIZE]
RGB color distribution histogram of the frame.
#define FILTER_PIXFMTS_ARRAY(array)
AVFrame * buf
cached frame
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
static enum AVPixelFormat pix_fmts[]
struct thumb_frame * frames
the n_frames frames
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
A filter pad used for either input or output.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_CEIL_RSHIFT(a, b)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
AVRational tb
copy of the input timebase to ease access
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int n_frames
number of frames for analysis
#define FILTER_INPUTS(array)
static AVFrame * get_best_frame(AVFilterContext *ctx)
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
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static int config_props(AVFilterLink *inlink)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int request_frame(AVFilterLink *link)
static const AVFilterPad thumbnail_outputs[]
static av_cold void uninit(AVFilterContext *ctx)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
#define AV_LOG_INFO
Standard information.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
static int thumbnail(AVFilterContext *ctx, int *histogram, AVFrame *in)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define i(width, name, range_min, range_max)
static double frame_sum_square_err(const int *hist, const double *median)
Compute Sum-square deviation to estimate "closeness".
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
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
static const AVFilterPad thumbnail_inputs[]
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static av_cold int init(AVFilterContext *ctx)
static const AVOption thumbnail_options[]
const AVFilter ff_vf_thumbnail
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)