Go to the documentation of this file.
34 #define HIST_SIZE (3*256)
49 #define OFFSET(x) offsetof(ThumbContext, x)
50 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
66 "Allocation failure, try to lower the number of frames\n");
82 double err, sum_sq_err = 0;
85 err = median[
i] - (double)hist[
i];
86 sum_sq_err += err*err;
95 int i, j, best_frame_idx = 0;
97 double avg_hist[
HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
101 for (
i = 0;
i < nb_frames;
i++)
102 avg_hist[j] += (
double)
s->frames[
i].histogram[j];
103 avg_hist[j] /= nb_frames;
107 for (
i = 0;
i < nb_frames;
i++) {
109 if (
i == 0 || sq_err < min_sq_err)
110 best_frame_idx =
i, min_sq_err = sq_err;
114 for (
i = 0;
i < nb_frames;
i++) {
115 memset(
s->frames[
i].histogram, 0,
sizeof(
s->frames[
i].histogram));
116 if (
i != best_frame_idx)
122 picref =
s->frames[best_frame_idx].buf;
124 "from a set of %d images\n", best_frame_idx,
126 s->frames[best_frame_idx].buf =
NULL;
137 int *hist =
s->frames[
s->n].histogram;
144 for (j = 0; j <
inlink->h; j++) {
146 hist[0*256 + p[
i*3 ]]++;
147 hist[1*256 + p[
i*3 + 1]]++;
148 hist[2*256 + p[
i*3 + 2]]++;
150 p +=
frame->linesize[0];
155 if (
s->n <
s->n_frames)
165 for (
i = 0;
i <
s->n_frames &&
s->frames[
i].buf;
i++)
229 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
236 .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.
#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.
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...
const char * name
Filter name.
A link between two filters.
struct thumb_frame * frames
the n_frames frames
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int query_formats(AVFilterContext *ctx)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
AVRational tb
copy of the input timebase to ease access
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
int n_frames
number of frames for analysis
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
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
static int config_props(AVFilterLink *inlink)
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 inputs
@ 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)
#define AV_LOG_INFO
Standard information.
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".
const char * name
Pad name.
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
#define FF_ARRAY_ELEMS(a)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static const AVFilterPad thumbnail_inputs[]
static av_cold int init(AVFilterContext *ctx)
static const AVOption thumbnail_options[]