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++)
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++) {
120 if (i != best_frame_idx)
128 "from a set of %d images\n", best_frame_idx,
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++) {
191 hist[256*plane + p[i]]++;
292 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
297 .
inputs = thumbnail_inputs,
299 .priv_class = &thumbnail_class,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVFilterContext *ctx)
int h
agreed upon image height
#define FF_ARRAY_ELEMS(a)
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVFrame * buf
cached frame
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
struct thumb_frame * frames
the n_frames frames
static double av_q2d(AVRational a)
Convert an AVRational to a double.
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
A filter pad used for either input or output.
A link between two filters.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
void * priv
private data for use by the filter
static const AVFilterPad thumbnail_outputs[]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
static int query_formats(AVFilterContext *ctx)
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
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
packed RGB 8:8:8, 24bpp, BGRBGR...
AVFilterContext * src
source filter
static AVFrame * get_best_frame(AVFilterContext *ctx)
static const AVFilterPad outputs[]
int format
agreed upon media format
static int request_frame(AVFilterLink *link)
static int thumbnail(AVFilterContext *ctx, int *histogram, AVFrame *in)
#define AV_LOG_INFO
Standard information.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
static int config_props(AVFilterLink *inlink)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVRational tb
copy of the input timebase to ease access
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
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
int n_frames
number of frames for analysis
Rational number (pair of numerator and denominator).
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
const char * name
Filter name.
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
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
AVFilterLink ** outputs
array of pointers to output links
static av_cold void uninit(AVFilterContext *ctx)
static enum AVPixelFormat pix_fmts[]
static double frame_sum_square_err(const int *hist, const double *median)
Compute Sum-square deviation to estimate "closeness".
#define flags(name, subs,...)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar GBRA 4:4:4:4 32bpp
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
AVFilterContext * dst
dest filter
AVFILTER_DEFINE_CLASS(thumbnail)
static const AVOption thumbnail_options[]
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
int histogram[HIST_SIZE]
RGB color distribution histogram of the frame.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
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
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
AVPixelFormat
Pixel format.
static const AVFilterPad thumbnail_inputs[]
#define AV_CEIL_RSHIFT(a, b)