Go to the documentation of this file.
270 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with frame variables 'n', 't', 'pos' are not valid in init eval_mode.\n");
280 int ret, is_inited = 0;
281 char *old_str_expr =
NULL;
292 old_pexpr = *pexpr_ptr;
325 *pexpr_ptr = old_pexpr;
339 scale->sws->threads = 0;
358 "Size and width/height expressions cannot be set at the same time.\n");
365 if (
scale->size_str) {
369 "Invalid size '%s'\n",
scale->size_str);
412 if (
scale->param[
i] != DBL_MAX)
415 scale->sws->src_h_chr_pos =
scale->in_h_chr_pos;
416 scale->sws->src_v_chr_pos =
scale->in_v_chr_pos;
417 scale->sws->dst_h_chr_pos =
scale->out_h_chr_pos;
418 scale->sws->dst_v_chr_pos =
scale->out_v_chr_pos;
421 if (!
scale->sws->threads)
483 for (
int i = 0;
i <
formats->nb_formats;
i++) {
485 for (
int j =
i--; j + 1 <
formats->nb_formats; j++)
494 &cfg_in[0]->color_ranges)) < 0)
502 for (
int i = 0;
i <
formats->nb_formats;
i++) {
504 for (
int j =
i--; j + 1 <
formats->nb_formats; j++)
538 main_link =
ctx->inputs[0];
548 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
567 if (
scale->uses_ref) {
586 expr =
scale->h_expr;
594 expr =
scale->w_expr;
607 "Error when evaluating the expression '%s'.\n", expr);
619 uint8_t *flags_val =
NULL;
629 scale->force_original_aspect_ratio,
630 scale->force_divisible_by);
635 if (outlink->
w > INT_MAX ||
636 outlink->
h > INT_MAX ||
637 (outlink->
h *
inlink->w) > INT_MAX ||
638 (outlink->
w *
inlink->h) > INT_MAX)
649 av_log(
ctx,
AV_LOG_VERBOSE,
"w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d -> w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d flags:%s\n",
652 inlink->sample_aspect_ratio.num,
inlink->sample_aspect_ratio.den,
665 scale->fs.in[0].time_base =
ctx->inputs[0]->time_base;
666 scale->fs.in[0].sync = 1;
669 if (
scale->uses_ref) {
671 scale->fs.in[1].time_base =
ctx->inputs[1]->time_base;
672 scale->fs.in[1].sync = 0;
726 int ret, flags_orig, frame_changed;
816 if (
scale->in_color_matrix != -1)
822 flags_orig = in->
flags;
823 if (
scale->interlaced > 0)
825 else if (!
scale->interlaced)
829 out->width = outlink->
w;
830 out->height = outlink->
h;
834 out->chroma_location =
scale->out_chroma_loc;
836 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
843 in->
flags = flags_orig;
855 out->flags = flags_orig;
873 int ret = 0, frame_changed;
879 if (
scale->uses_ref) {
889 frame_changed =
ref->width != reflink->
w ||
890 ref->height != reflink->
h ||
899 reflink->
w =
ref->width;
900 reflink->
h =
ref->height;
990 char *res,
int res_len,
int flags)
997 w = !strcmp(cmd,
"width") || !strcmp(cmd,
"w");
998 h = !strcmp(cmd,
"height") || !strcmp(cmd,
"h");
1002 pexpr_ptr =
w ? &
scale->w_pexpr : &
scale->h_pexpr;
1022 switch ((uintptr_t) *iter) {
1024 *iter = (
void*)(uintptr_t) 1;
1027 *iter = (
void*)(uintptr_t) 2;
1044 #define OFFSET(x) offsetof(ScaleContext, x)
1045 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1046 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1087 {
"in_v_chr_pos",
"input vertical chroma position in luma grid/256" ,
OFFSET(in_v_chr_pos),
AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512,
FLAGS },
1088 {
"in_h_chr_pos",
"input horizontal chroma position in luma grid/256",
OFFSET(in_h_chr_pos),
AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512,
FLAGS },
1089 {
"out_v_chr_pos",
"output vertical chroma position in luma grid/256" ,
OFFSET(out_v_chr_pos),
AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512,
FLAGS },
1090 {
"out_h_chr_pos",
"output horizontal chroma position in luma grid/256",
OFFSET(out_h_chr_pos),
AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512,
FLAGS },
1091 {
"force_original_aspect_ratio",
"decrease or increase w/h if necessary to keep the original AR",
OFFSET(force_original_aspect_ratio),
AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2,
FLAGS, .unit =
"force_oar" },
1095 {
"force_divisible_by",
"enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used",
OFFSET(force_divisible_by),
AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256,
FLAGS },
1131 .description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format."),
1148 *iter = (
void*)(uintptr_t)
c;
1199 .
name =
"scale2ref",
1200 .description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format to the given reference."),
static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define FF_ENABLE_DEPRECATION_WARNINGS
static int config_props_ref(AVFilterLink *outlink)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
AVPixelFormat
Pixel format.
static int check_exprs(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 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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
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)
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
static const AVFilterPad avfilter_vf_scale2ref_outputs[]
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
enum AVColorSpace colorspace
YUV colorspace type.
#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).
@ AVCOL_RANGE_JPEG
Full range content.
static int request_frame_ref(AVFilterLink *outlink)
@ AVCOL_SPC_NB
Not part of ABI.
static int scale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr **pexpr_ptr, const char *var, const char *args)
static const AVClass scale2ref_class
static int request_frame(AVFilterLink *outlink)
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.
double var_values[VARS_NB]
#define AV_LOG_VERBOSE
Detailed information.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
const char * name
Filter name.
@ EXT_INFINITY
Extend the frame to infinity.
A link between two filters.
Link properties exposed to filter code, but not external callers.
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 AVChromaLocation chroma_location
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ EXT_STOP
Completely stop all streams with this one.
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
const char * av_color_space_name(enum AVColorSpace space)
static const AVFilterPad avfilter_vf_scale_inputs[]
int eval_mode
expression evaluation mode
@ EXT_NULL
Ignore this stream and continue processing the other ones.
const AVClass * sws_get_class(void)
Get the AVClass for SwsContext.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
static av_cold int preinit(AVFilterContext *ctx)
A filter pad used for either input or output.
static int activate(AVFilterContext *ctx)
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static void * scale2ref_child_next(void *obj, void *prev)
int slice_y
top of current output slice
static enum AVPixelFormat pix_fmt
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
int av_expr_count_vars(AVExpr *e, unsigned *counter, int size)
Track the presence of variables and their number of occurrences in a parsed expression.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static av_cold int init(AVFilterContext *ctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int sws_test_colorspace(enum AVColorSpace colorspace, int output)
Test if a given color space is supported.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define FILTER_OUTPUTS(array)
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
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
const char * av_color_range_name(enum AVColorRange range)
#define LIBAVUTIL_VERSION_INT
const AVClass ff_framesync_class
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define fs(width, name, subs,...)
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Rational number (pair of numerator and denominator).
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
int sws_is_noop(const AVFrame *dst, const AVFrame *src)
Check if a given conversion is a noop.
static const AVClass * scale2ref_child_class_iterate(void **iter)
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
int sws_test_format(enum AVPixelFormat format, int output)
Test if a given pixel format is supported.
const AVFilter ff_vf_scale2ref
@ AVCOL_RANGE_UNSPECIFIED
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static FilterLink * ff_filter_link(AVFilterLink *link)
@ AV_CLASS_CATEGORY_FILTER
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
int format
agreed upon media format
static const AVClass * child_class_iterate(void **iter)
AVRational time_base
Time base for the timestamps in this frame.
static int scale_frame(AVFilterLink *link, AVFrame **frame_in, AVFrame **frame_out)
@ AVCHROMA_LOC_UNSPECIFIED
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
static int filter_frame(AVFilterLink *link, AVFrame *in)
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
int vsub
chroma subsampling
static int config_props(AVFilterLink *outlink)
#define i(width, name, range_min, range_max)
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define FILTER_QUERY_FUNC2(func)
const char * name
Pad name.
char * h_expr
height expression string
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
static const AVFilterPad avfilter_vf_scale_outputs[]
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
#define FFSWAP(type, a, b)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static void * child_next(void *obj, void *prev)
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
static int scale_eval_dimensions(AVFilterContext *ctx)
static const char *const var_names[]
static const AVOption scale_options[]
int h
agreed upon image height
static int do_scale(FFFrameSync *fs)
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AV_OPT_TYPE_INT
Underlying C type is int.
static av_cold void uninit(AVFilterContext *ctx)
int force_original_aspect_ratio
static int ref[MAX_W *MAX_W]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static const AVFilterPad avfilter_vf_scale2ref_inputs[]
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
#define FF_DISABLE_DEPRECATION_WARNINGS
char * av_strdup(const char *s)
Duplicate a string.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static void scale(int *out, const int *in, const int w, const int h, const int shift)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
static const AVClass scale_class
char * w_expr
width expression string
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
#define flags(name, subs,...)
@ AVCHROMA_LOC_NB
Not part of ABI.
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Main external API structure.
enum AVColorRange color_range
agreed upon YUV color range
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
const AVFilter ff_vf_scale
@ AVCHROMA_LOC_BOTTOMLEFT
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void ff_framesync_preinit(FFFrameSync *fs)
Pre-initialize a frame sync structure.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.