Go to the documentation of this file.
35 #define HIST_SIZE (3*256)
57 #define OFFSET(x) offsetof(ThumbContext, x)
58 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
78 "Allocation failure, try to lower the number of frames\n");
94 double err, sum_sq_err = 0;
98 sum_sq_err += err*err;
107 int i, j, best_frame_idx = 0;
108 int nb_frames =
s->n;
109 double avg_hist[
HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
113 for (
i = 0;
i < nb_frames;
i++)
114 avg_hist[j] += (
double)
s->frames[
i].histogram[j];
115 avg_hist[j] /= nb_frames;
119 for (
i = 0;
i < nb_frames;
i++) {
121 if (
i == 0 || sq_err < min_sq_err)
122 best_frame_idx =
i, min_sq_err = sq_err;
126 for (
i = 0;
i < nb_frames;
i++) {
127 memset(
s->frames[
i].histogram, 0,
sizeof(
s->frames[
i].histogram));
128 if (
i != best_frame_idx)
134 picref =
s->frames[best_frame_idx].buf;
136 av_log(
ctx,
s->loglevel,
"frame id #%d (pts_time=%f) selected "
137 "from a set of %d images\n", best_frame_idx,
139 s->frames[best_frame_idx].buf =
NULL;
148 int *hist =
s->thread_histogram +
HIST_SIZE * jobnr;
152 const int slice_end = (
h * (jobnr+1)) / nb_jobs;
155 memset(hist, 0,
sizeof(*hist) *
HIST_SIZE);
161 for (
int i = 0;
i <
w;
i++) {
162 hist[0*256 + p[
i*3 ]]++;
163 hist[1*256 + p[
i*3 + 1]]++;
164 hist[2*256 + p[
i*3 + 2]]++;
174 for (
int i = 0;
i <
w;
i++) {
175 hist[0*256 + p[
i*4 ]]++;
176 hist[1*256 + p[
i*4 + 1]]++;
177 hist[2*256 + p[
i*4 + 2]]++;
187 for (
int i = 0;
i <
w;
i++) {
188 hist[0*256 + p[
i*4 + 1]]++;
189 hist[1*256 + p[
i*4 + 2]]++;
190 hist[2*256 + p[
i*4 + 3]]++;
196 for (
int plane = 0; plane < 3; plane++) {
197 const int slice_start = (
s->planeheight[plane] * jobnr) / nb_jobs;
198 const int slice_end = (
s->planeheight[plane] * (jobnr+1)) / nb_jobs;
201 const int planewidth =
s->planewidth[plane];
202 int *hhist = hist + 256 * plane;
205 for (
int i = 0;
i < planewidth;
i++)
221 int *hist =
s->frames[
s->n].histogram;
231 int *thread_histogram =
s->thread_histogram +
HIST_SIZE * j;
234 hist[
i] += thread_histogram[
i];
239 if (
s->n <
s->n_frames)
249 for (
i = 0;
i <
s->n_frames &&
s->frames &&
s->frames[
i].buf;
i++)
280 if (!
s->thread_histogram)
285 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
287 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
328 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
335 .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 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.
#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.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static enum AVPixelFormat pix_fmts[]
struct thumb_frame * frames
the n_frames frames
@ 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 ...
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
#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 int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
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)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
@ 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)
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
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...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ 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[]
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
const AVFilter ff_vf_thumbnail
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)