Go to the documentation of this file.
38 #define HIST_SIZE (3*256)
62 #define OFFSET(x) offsetof(ThumbContext, x)
63 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
83 "Allocation failure, try to lower the number of frames\n");
99 double err, sum_sq_err = 0;
103 sum_sq_err += err*err;
112 int i, j, best_frame_idx = 0;
113 int nb_frames =
s->n;
114 double avg_hist[
HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
118 for (
i = 0;
i < nb_frames;
i++)
119 avg_hist[j] += (
double)
s->frames[
i].histogram[j];
120 avg_hist[j] /= nb_frames;
124 for (
i = 0;
i < nb_frames;
i++) {
126 if (
i == 0 || sq_err < min_sq_err)
127 best_frame_idx =
i, min_sq_err = sq_err;
131 for (
i = 0;
i < nb_frames;
i++) {
132 memset(
s->frames[
i].histogram, 0,
sizeof(
s->frames[
i].histogram));
133 if (
i != best_frame_idx)
139 picref =
s->frames[best_frame_idx].buf;
141 av_log(
ctx,
s->loglevel,
"frame id #%d (pts_time=%f) selected "
142 "from a set of %d images\n", best_frame_idx,
144 s->frames[best_frame_idx].buf =
NULL;
152 int shist[4][256] = {0};
154 const int width4 =
width & ~3;
156 for (
int x = 0; x < width4; x += 4) {
157 const uint32_t v =
AV_RN32(&p[x]);
158 shist[0][(uint8_t) (v >> 0)]++;
159 shist[1][(uint8_t) (v >> 8)]++;
160 shist[2][(uint8_t) (v >> 16)]++;
161 shist[3][(uint8_t) (v >> 24)]++;
164 for (
int x = width4; x <
width; x++)
169 for (
int i = 0;
i < 4;
i++) {
170 for (
int j = 0; j < 256; j++)
171 hist[j] += shist[
i][j];
178 int shist[4][256] = {0};
180 const int width4 =
width & ~3;
182 const uint16_t *p16 = (
const uint16_t *) p;
183 for (
int x = 0; x < width4; x += 4) {
184 const uint64_t v =
AV_RN64(&p16[x]);
185 shist[0][(uint8_t) (v >> (
shift + 0))]++;
186 shist[1][(uint8_t) (v >> (
shift + 16))]++;
187 shist[2][(uint8_t) (v >> (
shift + 32))]++;
188 shist[3][(uint8_t) (v >> (
shift + 48))]++;
191 for (
int x = width4; x <
width; x++)
196 for (
int i = 0;
i < 4;
i++) {
197 for (
int j = 0; j < 256; j++)
198 hist[j] += shist[
i][j];
206 int *hist =
s->thread_histogram +
HIST_SIZE * jobnr;
207 const int h =
frame->height;
208 const int w =
frame->width;
210 const int slice_end = (
h * (jobnr+1)) / nb_jobs;
213 memset(hist, 0,
sizeof(*hist) *
HIST_SIZE);
215 switch (
frame->format) {
219 for (
int i = 0;
i <
w;
i++) {
220 hist[0*256 + p[
i*3 ]]++;
221 hist[1*256 + p[
i*3 + 1]]++;
222 hist[2*256 + p[
i*3 + 2]]++;
224 p +=
frame->linesize[0];
232 for (
int i = 0;
i <
w;
i++) {
233 hist[0*256 + p[
i*4 ]]++;
234 hist[1*256 + p[
i*4 + 1]]++;
235 hist[2*256 + p[
i*4 + 2]]++;
237 p +=
frame->linesize[0];
245 for (
int i = 0;
i <
w;
i++) {
246 hist[0*256 + p[
i*4 + 1]]++;
247 hist[1*256 + p[
i*4 + 2]]++;
248 hist[2*256 + p[
i*4 + 3]]++;
250 p +=
frame->linesize[0];
254 for (
int plane = 0; plane <
s->planes; plane++) {
255 const int slice_start = (
s->planeheight[plane] * jobnr) / nb_jobs;
256 const int slice_end = (
s->planeheight[plane] * (jobnr+1)) / nb_jobs;
258 const ptrdiff_t linesize =
frame->linesize[plane];
259 const int planewidth =
s->planewidth[plane];
260 int *hhist = hist + 256 * plane;
261 if (
s->bitdepth > 8) {
279 int *hist =
s->frames[
s->n].histogram;
288 for (
int j = 0; j <
FFMIN(
frame->height,
s->nb_threads); j++) {
289 int *thread_histogram =
s->thread_histogram +
HIST_SIZE * j;
292 hist[
i] += thread_histogram[
i];
297 if (
s->n <
s->n_frames)
307 for (
i = 0;
i <
s->n_frames &&
s->frames &&
s->frames[
i].buf;
i++)
338 if (!
s->thread_histogram)
343 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
345 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
347 s->bitdepth =
desc->comp[0].depth;
378 (
desc->nb_components < 3 ||
desc->comp[1].plane !=
desc->comp[2].plane) &&
379 desc->comp[0].depth <= 16)
408 .
p.
name =
"thumbnail",
409 .p.description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
410 .p.priv_class = &thumbnail_class,
AVPixelFormat
Pixel format.
static void get_hist8(int *hist, const uint8_t *p, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height)
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.
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
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
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).
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
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...
const char * name
Filter name.
A link between two filters.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
struct thumb_frame * frames
the n_frames frames
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
#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
static enum AVPixelFormat packed_rgb_fmts[]
static void get_hist16(int *hist, const uint8_t *p, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int shift)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
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_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
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 int shift(int a, int b)
static const AVFilterPad thumbnail_outputs[]
const FFFilter ff_vf_thumbnail
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
@ 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.
#define FILTER_QUERY_FUNC2(func)
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
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[]
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
AVFilter p
The public AVFilter.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static av_cold int init(AVFilterContext *ctx)
static const AVOption thumbnail_options[]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.