26 #include "libavutil/avstring.h"
27 #include "libavutil/eval.h"
28 #include "libavutil/fifo.h"
30 #include "libavutil/opt.h"
158 #define OFFSET(x) offsetof(SelectContext, x)
159 #define DEFINE_OPTIONS(filt_name, FLAGS) \
160 static const AVOption filt_name##_options[] = { \
161 { "expr", "set an expression to use for selecting frames", OFFSET(expr_str), AV_OPT_TYPE_STRING, { .str = "1" }, .flags=FLAGS }, \
162 { "e", "set an expression to use for selecting frames", OFFSET(expr_str), AV_OPT_TYPE_STRING, { .str = "1" }, .flags=FLAGS }, \
163 { "outputs", "set the number of outputs", OFFSET(nb_outputs), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, .flags=FLAGS }, \
164 { "n", "set the number of outputs", OFFSET(nb_outputs), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, .flags=FLAGS }, \
176 var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) {
197 #define INTERLACE_TYPE_P 0
198 #define INTERLACE_TYPE_T 1
199 #define INTERLACE_TYPE_B 2
265 int x,
y, nb_sad = 0;
270 const int linesize = frame->
linesize[0];
272 for (y = 0; y < frame->
height - 8; y += 8) {
273 for (x = 0; x < frame->
width*3 - 8; x += 8) {
274 sad += select->c.sad[1](select, p1 + x, p2 + x,
282 mafd = nb_sad ? sad / nb_sad : 0;
283 diff = fabs(mafd - select->prev_mafd);
284 ret = av_clipf(
FFMIN(mafd, diff) / 100., 0, 1);
285 select->prev_mafd = mafd;
293 #define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
294 #define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
312 switch (inlink->
type) {
336 "n:%f pts:%f t:%f key:%d",
342 switch (inlink->
type) {
360 }
else if (
isnan(res) || res < 0) {
448 #if CONFIG_ASELECT_FILTER
458 if ((ret =
init(ctx)) < 0)
469 static const AVFilterPad avfilter_af_aselect_inputs[] = {
482 .init = aselect_init,
485 .
inputs = avfilter_af_aselect_inputs,
486 .priv_class = &aselect_class,
491 #if CONFIG_SELECT_FILTER
501 if ((ret =
init(ctx)) < 0)
512 static const AVFilterPad avfilter_vf_select_inputs[] = {
529 .priv_class = &select_class,
530 .
inputs = avfilter_vf_select_inputs,
This structure describes decoded (raw) audio or video data.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
const char * name
Filter name.
static av_cold void uninit(AVFilterContext *ctx)
void * priv
private data for use by the filter
packed RGB 8:8:8, 24bpp, RGBRGB...
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
enum AVMediaType type
AVFilterPad type.
#define FF_OUTLINK_IDX(link)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
packed RGB 8:8:8, 24bpp, BGRBGR...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
int(* request_frame)(AVFilterLink *link)
Frame request callback.
static void select_frame(AVFilterContext *ctx, AVFrame *frame)
static av_always_inline av_const int isnan(float x)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static double av_q2d(AVRational a)
Convert rational to double.
#define AV_OPT_FLAG_VIDEO_PARAM
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
int interlaced_frame
The content of the picture is interlaced.
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
A filter pad used for either input or output.
A link between two filters.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
static int query_formats(AVFilterContext *ctx)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int sample_rate
samples per second
#define AV_OPT_FLAG_AUDIO_PARAM
double var_values[VAR_VARS_NB]
unsigned nb_outputs
number of output pads
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVPixelFormat
Pixel format.
int select_out
mark the selected output pad index
static int config_input(AVFilterLink *inlink)
common internal API header
enum AVPictureType pict_type
Picture type of the frame.
const AVFilter * filter
the AVFilter of which this is an instance
size_t char * av_asprintf(const char *fmt,...) av_printf_format(1
Print arguments following specified format into a large enough auto allocated buffer.
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
main external API structure.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilterContext * dst
dest filter
static int request_frame(AVFilterLink *outlink)
enum AVMediaType type
filter media type
int do_scene_detect
1 if the expression requires scene detection variables, 0 otherwise
AVFrame * prev_picref
previous frame (scene detect only)
#define DEFINE_OPTIONS(filt_name, FLAGS)
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
static av_cold int init(AVFilterContext *ctx)
int top_field_first
If the content is interlaced, is top field displayed first.
#define AVFILTER_DEFINE_CLASS(fname)
AVFilterPad * output_pads
array of output pads
static const char *const var_names[]
av_cold void avpriv_dsputil_init(DSPContext *c, AVCodecContext *avctx)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
int64_t frame_count
Number of past frames sent through the link.