Go to the documentation of this file.
36 #define HIST_SIZE (3*256)
58 #define OFFSET(x) offsetof(ThumbContext, x)
59 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
79 "Allocation failure, try to lower the number of frames\n");
95 double err, sum_sq_err = 0;
99 sum_sq_err += err*err;
108 int i, j, best_frame_idx = 0;
109 int nb_frames =
s->n;
110 double avg_hist[
HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
114 for (
i = 0;
i < nb_frames;
i++)
115 avg_hist[j] += (
double)
s->frames[
i].histogram[j];
116 avg_hist[j] /= nb_frames;
120 for (
i = 0;
i < nb_frames;
i++) {
122 if (
i == 0 || sq_err < min_sq_err)
123 best_frame_idx =
i, min_sq_err = sq_err;
127 for (
i = 0;
i < nb_frames;
i++) {
128 memset(
s->frames[
i].histogram, 0,
sizeof(
s->frames[
i].histogram));
129 if (
i != best_frame_idx)
135 picref =
s->frames[best_frame_idx].buf;
137 av_log(
ctx,
s->loglevel,
"frame id #%d (pts_time=%f) selected "
138 "from a set of %d images\n", best_frame_idx,
140 s->frames[best_frame_idx].buf =
NULL;
149 int *hist =
s->thread_histogram +
HIST_SIZE * jobnr;
150 const int h =
frame->height;
151 const int w =
frame->width;
153 const int slice_end = (
h * (jobnr+1)) / nb_jobs;
156 memset(hist, 0,
sizeof(*hist) *
HIST_SIZE);
158 switch (
frame->format) {
162 for (
int i = 0;
i <
w;
i++) {
163 hist[0*256 + p[
i*3 ]]++;
164 hist[1*256 + p[
i*3 + 1]]++;
165 hist[2*256 + p[
i*3 + 2]]++;
167 p +=
frame->linesize[0];
175 for (
int i = 0;
i <
w;
i++) {
176 hist[0*256 + p[
i*4 ]]++;
177 hist[1*256 + p[
i*4 + 1]]++;
178 hist[2*256 + p[
i*4 + 2]]++;
180 p +=
frame->linesize[0];
188 for (
int i = 0;
i <
w;
i++) {
189 hist[0*256 + p[
i*4 + 1]]++;
190 hist[1*256 + p[
i*4 + 2]]++;
191 hist[2*256 + p[
i*4 + 3]]++;
193 p +=
frame->linesize[0];
197 for (
int plane = 0; plane < 3; plane++) {
198 const int slice_start = (
s->planeheight[plane] * jobnr) / nb_jobs;
199 const int slice_end = (
s->planeheight[plane] * (jobnr+1)) / nb_jobs;
201 const ptrdiff_t linesize =
frame->linesize[plane];
202 const int planewidth =
s->planewidth[plane];
203 int *hhist = hist + 256 * plane;
206 for (
int i = 0;
i < planewidth;
i++)
222 int *hist =
s->frames[
s->n].histogram;
231 for (
int j = 0; j <
FFMIN(
frame->height,
s->nb_threads); j++) {
232 int *thread_histogram =
s->thread_histogram +
HIST_SIZE * j;
235 hist[
i] += thread_histogram[
i];
240 if (
s->n <
s->n_frames)
250 for (
i = 0;
i <
s->n_frames &&
s->frames &&
s->frames[
i].buf;
i++)
281 if (!
s->thread_histogram)
286 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
288 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
329 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
336 .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)
#define FILTER_PIXFMTS_ARRAY(array)
#define AV_LOG_QUIET
Print no output.
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.
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.
#define FILTER_INPUTS(array)
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
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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_OUTPUTS(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".
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
@ 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)
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
@ 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
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_OPT_TYPE_INT
Underlying C type is int.
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
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ 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...
@ 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[]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
const AVFilter ff_vf_thumbnail
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)