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++)
192 hist[(uint8_t) (p16[x] >>
shift)]++;
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;
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++) {
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,
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vf_thumbnail
static AVFormatContext * ctx
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.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#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 AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#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_QUIET
Print no output.
#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.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int shift(int a, int b)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ 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_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define FF_ARRAY_ELEMS(a)
static int config_props(AVBitStreamFilterLink *link)
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.
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).
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.
static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static AVFrame * get_best_frame(AVFilterContext *ctx)
static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static enum AVPixelFormat packed_rgb_fmts[]
static const AVOption thumbnail_options[]
static void get_hist8(int *hist, const uint8_t *p, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static int request_frame(AVFilterLink *link)
static const AVFilterPad thumbnail_inputs[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int config_props(AVFilterLink *inlink)
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 void get_hist16(int *hist, const uint8_t *p, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int shift)
static const AVFilterPad thumbnail_outputs[]
static int thumbnail(AVFilterContext *ctx, int *histogram, AVFrame *in)
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)