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;
89 err = median[
i] - (double)hist[
i];
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;
151 for (j = 0; j < inlink->
h; j++) {
152 for (
i = 0;
i < inlink->
w;
i++) {
153 hist[0*256 + p[
i*3 ]]++;
154 hist[1*256 + p[
i*3 + 1]]++;
155 hist[2*256 + p[
i*3 + 2]]++;
164 for (j = 0; j < inlink->
h; j++) {
165 for (
i = 0;
i < inlink->
w;
i++) {
166 hist[0*256 + p[
i*4 ]]++;
167 hist[1*256 + p[
i*4 + 1]]++;
168 hist[2*256 + p[
i*4 + 2]]++;
177 for (j = 0; j < inlink->
h; j++) {
178 for (
i = 0;
i < inlink->
w;
i++) {
179 hist[0*256 + p[
i*4 + 1]]++;
180 hist[1*256 + p[
i*4 + 2]]++;
181 hist[2*256 + p[
i*4 + 3]]++;
187 for (
int plane = 0; plane < 3; 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]]++;
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;
292 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
299 .priv_class = &thumbnail_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Main libavfilter public API header.
#define flags(name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVERROR_EOF
End of file.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ 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_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
@ 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_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
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).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
AVRational tb
copy of the input timebase to ease access
struct thumb_frame * frames
the n_frames frames
int n_frames
number of frames for analysis
AVFrame * buf
cached frame
int histogram[HIST_SIZE]
RGB color distribution histogram of the frame.
AVFILTER_DEFINE_CLASS(thumbnail)
static const AVOption thumbnail_options[]
static int query_formats(AVFilterContext *ctx)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static AVFrame * get_best_frame(AVFilterContext *ctx)
static int request_frame(AVFilterLink *link)
static const AVFilterPad thumbnail_inputs[]
static int config_props(AVFilterLink *inlink)
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static double frame_sum_square_err(const int *hist, const double *median)
Compute Sum-square deviation to estimate "closeness".
static const AVFilterPad thumbnail_outputs[]
static int thumbnail(AVFilterContext *ctx, int *histogram, AVFrame *in)