34 #define HIST_SIZE (3*256)
49 #define OFFSET(x) offsetof(ThumbContext, x)
50 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
66 "Allocation failure, try to lower the number of frames\n");
82 double err, sum_sq_err = 0;
85 err = median[i] - (double)hist[i];
86 sum_sq_err += err*err;
95 int i, j, best_frame_idx = 0;
97 double avg_hist[
HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
101 for (i = 0; i < nb_frames; i++)
103 avg_hist[j] /= nb_frames;
107 for (i = 0; i < nb_frames; i++) {
109 if (i == 0 || sq_err < min_sq_err)
110 best_frame_idx = i, min_sq_err = sq_err;
114 for (i = 0; i < nb_frames; i++) {
116 if (i != best_frame_idx)
124 "from a set of %d images\n", best_frame_idx,
144 for (j = 0; j < inlink->
h; j++) {
145 for (i = 0; i < inlink->
w; i++) {
146 hist[0*256 + p[i*3 ]]++;
147 hist[1*256 + p[i*3 + 1]]++;
148 hist[2*256 + p[i*3 + 2]]++;
229 .description =
NULL_IF_CONFIG_SMALL(
"Select the most representative frame in a given sequence of consecutive frames."),
234 .
inputs = thumbnail_inputs,
236 .priv_class = &thumbnail_class,
This structure describes decoded (raw) audio or video data.
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
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
struct thumb_frame * frames
the n_frames frames
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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. ...
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...
int w
agreed upon image width
static int query_formats(AVFilterContext *ctx)
packed RGB 8:8:8, 24bpp, BGRBGR...
AVFilterContext * src
source filter
static AVFrame * get_best_frame(AVFilterContext *ctx)
static const AVFilterPad outputs[]
#define FF_ARRAY_ELEMS(a)
static int request_frame(AVFilterLink *link)
static int thumbnail(AVFilterContext *ctx, int *histogram, AVFrame *in)
#define AV_LOG_INFO
Standard information.
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int config_props(AVFilterLink *inlink)
AVRational tb
copy of the input timebase to ease access
Describe the class of an AVClass context structure.
int n_frames
number of frames for analysis
Rational number (pair of numerator and denominator).
const char * name
Filter name.
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".
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVFilterContext * dst
dest filter
AVFILTER_DEFINE_CLASS(thumbnail)
static const AVOption thumbnail_options[]
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.
AVPixelFormat
Pixel format.
static const AVFilterPad thumbnail_inputs[]