Go to the documentation of this file.
218 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with frame variables 'n', 't', 'pos' are not valid in init eval_mode.\n");
228 int ret, is_inited = 0;
229 char *old_str_expr =
NULL;
240 old_pexpr = *pexpr_ptr;
273 *pexpr_ptr = old_pexpr;
284 if (!
scale->sws_opts)
303 "Size and width/height expressions cannot be set at the same time.\n");
310 if (
scale->size_str) {
314 "Invalid size '%s'\n",
scale->size_str);
345 if (
scale->param[
i] != DBL_MAX) {
418 if (
s && strstr(
s,
"bt709")) {
420 }
else if (
s && strstr(
s,
"fcc")) {
422 }
else if (
s && strstr(
s,
"smpte240m")) {
424 }
else if (
s && (strstr(
s,
"bt601") || strstr(
s,
"bt470") || strstr(
s,
"smpte170m"))) {
426 }
else if (
s && strstr(
s,
"bt2020")) {
430 if (colorspace < 1 || colorspace > 10 || colorspace == 8) {
453 main_link =
ctx->inputs[0];
463 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
487 expr =
scale->h_expr;
495 expr =
scale->w_expr;
508 "Error when evaluating the expression '%s'.\n", expr);
523 uint8_t *flags_val =
NULL;
533 scale->force_original_aspect_ratio,
534 scale->force_divisible_by);
536 if (outlink->
w > INT_MAX ||
537 outlink->
h > INT_MAX ||
538 (outlink->
h *
inlink->w) > INT_MAX ||
539 (outlink->
w *
inlink->h) > INT_MAX)
555 if (inlink0->
w == outlink->
w &&
556 inlink0->
h == outlink->
h &&
557 !
scale->out_color_matrix &&
565 for (
i = 0;
i < 3;
i++) {
566 int in_v_chr_pos =
scale->in_v_chr_pos, out_v_chr_pos =
scale->out_v_chr_pos;
596 if (
desc->log2_chroma_h == 1 &&
scale->in_v_chr_pos == -513) {
597 in_v_chr_pos = (
i == 0) ? 128 : (
i == 1) ? 64 : 192;
601 out_v_chr_pos = (
i == 0) ? 128 : (
i == 1) ? 64 : 192;
611 if (!
scale->interlaced)
626 inlink->sample_aspect_ratio.num,
inlink->sample_aspect_ratio.den,
664 if (
i == 1 && is_pal)
673 int orig_h_src =
src->height;
674 int orig_h_dst = dst->
height;
684 for (
int i = 0;
i < 4;
i++) {
685 src->linesize[
i] *= 2;
696 for (
int i = 0;
i < 4;
i++) {
697 src->linesize[
i] /= 2;
700 src->height = orig_h_src;
823 out->width = outlink->
w;
824 out->height = outlink->
h;
838 if (
scale->output_is_pal)
843 if (
scale->in_color_matrix
844 ||
scale->out_color_matrix
849 const int *inv_table, *
table;
852 (
int **)&
table, &out_full,
855 if (
scale->in_color_matrix)
857 if (
scale->out_color_matrix)
859 else if (
scale->in_color_matrix)
884 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
889 if (
scale->interlaced>0 || (
scale->interlaced<0 &&
954 char *res,
int res_len,
int flags)
961 w = !strcmp(cmd,
"width") || !strcmp(cmd,
"w");
962 h = !strcmp(cmd,
"height") || !strcmp(cmd,
"h");
981 *iter = (
void*)(uintptr_t)
c;
993 #define OFFSET(x) offsetof(ScaleContext, x)
994 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
995 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1026 {
"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 },
1027 {
"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 },
1028 {
"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 },
1029 {
"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 },
1030 {
"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,
"force_oar" },
1034 {
"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 },
1071 .description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format."),
1112 .
name =
"scale2ref",
1113 .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)
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
AVPixelFormat
Pixel format.
struct SwsContext * sws_opts
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
int input_is_pal
set to 1 if the input format is paletted
#define sws_isSupportedOutput(x)
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)
static int query_formats(AVFilterContext *ctx)
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.
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)
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
static int scale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr **pexpr_ptr, const char *var, const char *args)
#define FILTER_QUERY_FUNC(func)
static const uint16_t table[]
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.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
const char * name
Filter name.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
static const AVFilterPad avfilter_vf_scale_inputs[]
static void frame_offset(AVFrame *frame, int dir, int is_pal)
struct SwsContext * isws[2]
software scaler context for interlaced material
int eval_mode
expression evaluation mode
static av_always_inline float scale(float x, float s)
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)
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.
@ 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)
struct SwsContext * sws
software scaler context
static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
int slice_y
top of current output slice
static enum AVPixelFormat pix_fmt
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.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static av_cold int init(AVFilterContext *ctx)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
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.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
#define FILTER_INPUTS(array)
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 scale_field(ScaleContext *scale, AVFrame *dst, AVFrame *src, int field)
#define LIBAVUTIL_VERSION_INT
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.
Rational number (pair of numerator and denominator).
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
struct SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
@ AVCOL_SPC_YCGCO
used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
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
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
@ AV_CLASS_CATEGORY_FILTER
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
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.
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.
#define sws_isSupportedInput(x)
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
int vsub
chroma subsampling
int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
static int config_props(AVFilterLink *outlink)
int output_is_pal
set to 1 if the output format is paletted
int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
#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
AVColorSpace
YUV colorspace type.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
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 const int * parse_yuv_type(const char *s, enum AVColorSpace colorspace)
static void * child_next(void *obj, void *prev)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
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 ...
av_warn_unused_result int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
static int scale_eval_dimensions(AVFilterContext *ctx)
static const char *const var_names[]
static const AVOption scale_options[]
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
int h
agreed upon image height
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
static av_cold void uninit(AVFilterContext *ctx)
int force_original_aspect_ratio
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.
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
#define FILTER_OUTPUTS(array)
static const AVClass scale_class
char * w_expr
width expression string
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
const AVFilter ff_vf_scale
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
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.
double param[2]
Input parameters for scaling algorithms that need them.