180#define IS_SCALE2REF(ctx) ((ctx)->filter == &ff_vf_scale2ref.p)
250 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with frame variables 'n', 't', 'pos' are not valid in init eval_mode.\n");
260 int ret, is_inited = 0;
261 char *old_str_expr =
NULL;
272 old_pexpr = *pexpr_ptr;
305 *pexpr_ptr = old_pexpr;
319 scale->sws->threads = 0;
338 "Size and width/height expressions cannot be set at the same time.\n");
345 if (
scale->size_str) {
349 "Invalid size '%s'\n",
scale->size_str);
416 if (
scale->param[
i] != DBL_MAX)
419 scale->sws->src_h_chr_pos =
scale->in_h_chr_pos;
420 scale->sws->src_v_chr_pos =
scale->in_v_chr_pos;
421 scale->sws->dst_h_chr_pos =
scale->out_h_chr_pos;
422 scale->sws->dst_v_chr_pos =
scale->out_v_chr_pos;
425 if (!
scale->sws->threads)
487 for (
int i = 0;
i <
formats->nb_formats;
i++) {
489 for (
int j =
i--; j + 1 <
formats->nb_formats; j++)
498 &cfg_in[0]->color_ranges)) < 0)
506 for (
int i = 0;
i <
formats->nb_formats;
i++) {
508 for (
int j =
i--; j + 1 <
formats->nb_formats; j++)
523 if (
scale->sws->alpha_blend) {
525 &cfg_in[0]->alpha_modes)) < 0)
548 main_link =
ctx->inputs[0];
577 if (
scale->uses_ref) {
596 expr =
scale->h_expr;
604 expr =
scale->w_expr;
617 "Error when evaluating the expression '%s'.\n", expr);
629 uint8_t *flags_val =
NULL;
639 if (
scale->reset_sar)
644 scale->force_original_aspect_ratio,
645 scale->force_divisible_by, w_adj);
650 if (outlink->
w > INT_MAX ||
651 outlink->
h > INT_MAX ||
652 (outlink->
h * (uint64_t)inlink->
w) > INT_MAX ||
653 (outlink->
w * (uint64_t)inlink->
h) > INT_MAX)
658 if (
scale->reset_sar)
667 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",
677 if (inlink->
w != outlink->
w || inlink->
h != outlink->
h) {
693 scale->fs.in[0].time_base =
ctx->inputs[0]->time_base;
694 scale->fs.in[0].sync = 1;
697 if (
scale->uses_ref) {
699 scale->fs.in[1].time_base =
ctx->inputs[1]->time_base;
700 scale->fs.in[1].sync = 0;
722 outlink->
w = inlink->
w;
723 outlink->
h = inlink->
h;
754 int ret, flags_orig, frame_changed;
758 frame_changed = in->
width != link->
w ||
824 if (
scale->in_color_matrix != -1)
826 if (
scale->in_primaries != -1)
828 if (
scale->in_transfer != -1)
834 flags_orig = in->
flags;
835 if (
scale->interlaced > 0)
837 else if (!
scale->interlaced)
841 out->width = outlink->
w;
842 out->height = outlink->
h;
847 out->chroma_location =
scale->out_chroma_loc;
848 if (
scale->out_primaries != -1)
849 out->color_primaries =
scale->out_primaries;
850 if (
scale->out_transfer != -1)
851 out->color_trc =
scale->out_transfer;
863 if (
scale->reset_sar) {
866 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
874 in->
flags = flags_orig;
886 out->flags = flags_orig;
904 int ret = 0, frame_changed;
910 if (
scale->uses_ref) {
920 frame_changed =
ref->width != reflink->
w ||
921 ref->height != reflink->
h ||
930 reflink->
w =
ref->width;
931 reflink->
h =
ref->height;
982 frame_changed = in->
width != link->
w ||
1011 char *res,
int res_len,
int flags)
1018 w = !strcmp(cmd,
"width") || !strcmp(cmd,
"w");
1019 h = !strcmp(cmd,
"height") || !strcmp(cmd,
"h");
1023 pexpr_ptr =
w ? &
scale->w_pexpr : &
scale->h_pexpr;
1043 switch ((uintptr_t) *iter) {
1045 *iter = (
void*)(uintptr_t) 1;
1048 *iter = (
void*)(uintptr_t) 2;
1065#define OFFSET(x) offsetof(ScaleContext, x)
1066#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1067#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1146 {
"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 },
1147 {
"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 },
1148 {
"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 },
1149 {
"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 },
1150 {
"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,
SCALE_FORCE_OAR_NB-1,
FLAGS, .unit =
"force_oar" },
1154 {
"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 },
1155 {
"reset_sar",
"reset SAR to 1 and scale to square pixels if scaling proportionally",
OFFSET(reset_sar),
AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1,
FLAGS },
1165 .class_name =
"scale",
1191 .p.description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format."),
1208 *iter = (
void*)(uintptr_t)
c;
1221 .class_name =
"scale(2ref)",
1259 .p.name =
"scale2ref",
1260 .p.description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format to the given reference."),
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vf_scale
const FFFilter ff_vf_scale2ref
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
static enum AVPixelFormat pix_fmt
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
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.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
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.
simple arithmetic expression evaluator
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
const AVClass ff_framesync_class
void ff_framesync_preinit(FFFrameSync *fs)
Pre-initialize a frame sync structure.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
@ EXT_INFINITY
Extend the frame to infinity.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
@ AV_SIDE_DATA_PROP_COLOR_DEPENDENT
Side data depends on the video color space.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
#define LIBAVUTIL_VERSION_INT
int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output)
Test if a given color transfer function is supported.
int sws_test_colorspace(enum AVColorSpace csp, int output)
Test if a given color space is supported.
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
int sws_test_primaries(enum AVColorPrimaries prim, int output)
Test if a given set of color primaries is supported.
int sws_is_noop(const AVFrame *dst, const AVFrame *src)
Check if a given conversion is a noop.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
const AVClass * sws_get_class(void)
Get the AVClass for SwsContext.
int sws_test_format(enum AVPixelFormat format, int output)
Test if a given (software) pixel format is supported by any backend, excluding unstable backends.
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_QUERY_FUNC2(func)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_CLASS_CATEGORY_FILTER
#define FFSWAP(type, a, b)
Memory handling functions.
static const char *const var_names[]
@ EXT_STOP
Completely stop all streams with this one.
@ EXT_NULL
Ignore this stream and continue processing the other ones.
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.
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_range_name(enum AVColorRange range)
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.
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_NB
Not part of ABI.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCHROMA_LOC_UNSPECIFIED
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_NB
Not part of ABI.
@ AVCOL_PRI_FILM
colour filters using Illuminant C
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
@ AVCOL_PRI_EBU3213
EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors.
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
@ AVCOL_TRC_BT709
also ITU-R BT1361
@ AVCOL_TRC_NB
Not part of ABI.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_SPC_NB
Not part of ABI.
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
@ SCALE_FORCE_OAR_DISABLE
@ SCALE_FORCE_OAR_INCREASE
@ SCALE_FORCE_OAR_DECREASE
#define FF_ARRAY_ELEMS(a)
static av_cold int preinit(AVBitStreamFilterContext *ctx)
static int config_props(AVBitStreamFilterLink *link)
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
enum AVAlphaMode alpha_mode
alpha mode (for videos with an alpha channel)
AVFilterContext * dst
dest filter
int format
agreed upon media format
enum AVColorRange color_range
agreed upon YUV color range
AVFrameSideData ** side_data
A filter pad used for either input or output.
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).
enum AVChromaLocation chroma_location
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
enum AVColorPrimaries color_primaries
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
int eval_mode
expression evaluation mode
int slice_y
top of current output slice
int force_original_aspect_ratio
char * w_expr
width expression string
char * h_expr
height expression string
int vsub
chroma subsampling
double var_values[VARS_NB]
Main external API structure.
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
static int do_scale(FFFrameSync *fs)
static void * child_next(void *obj, void *prev)
static int config_props(AVFilterLink *outlink)
static int request_frame_ref(AVFilterLink *outlink)
static int scale_eval_dimensions(AVFilterContext *ctx)
static const AVClass scale_class
static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
static const AVFilterPad avfilter_vf_scale_outputs[]
static void * scale2ref_child_next(void *obj, void *prev)
static int filter_frame(AVFilterLink *link, AVFrame *in)
static const AVClass * child_class_iterate(void **iter)
static const AVClass scale2ref_class
static int scale_frame(AVFilterLink *link, AVFrame **frame_in, AVFrame **frame_out)
static int request_frame(AVFilterLink *outlink)
static int config_props_ref(AVFilterLink *outlink)
static int scale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr **pexpr_ptr, const char *var, const char *args)
static const AVFilterPad avfilter_vf_scale2ref_inputs[]
static const AVClass * scale2ref_child_class_iterate(void **iter)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int check_exprs(AVFilterContext *ctx)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static av_cold int preinit(AVFilterContext *ctx)
#define IS_SCALE2REF(ctx)
static const AVFilterPad avfilter_vf_scale_inputs[]
static const AVOption scale_options[]
static const AVFilterPad avfilter_vf_scale2ref_outputs[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.