213 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with frame variables 'n', 't', 'pos' are not valid in init eval_mode.\n");
223 int ret, is_inited = 0;
224 char *old_str_expr =
NULL;
235 old_pexpr = *pexpr_ptr;
268 *pexpr_ptr = old_pexpr;
280 "Size and width/height expressions cannot be set at the same time.\n");
291 "Invalid size '%s'\n", scale->
size_str);
294 snprintf(buf,
sizeof(buf)-1,
"%d", scale->
w);
296 snprintf(buf,
sizeof(buf)-1,
"%d", scale->
h);
350 if (
ctx->inputs[0]) {
364 if (
ctx->outputs[0]) {
387 if (
s && strstr(
s,
"bt709")) {
389 }
else if (
s && strstr(
s,
"fcc")) {
391 }
else if (
s && strstr(
s,
"smpte240m")) {
393 }
else if (
s && (strstr(
s,
"bt601") || strstr(
s,
"bt470") || strstr(
s,
"smpte170m"))) {
395 }
else if (
s && strstr(
s,
"bt2020")) {
399 if (colorspace < 1 || colorspace > 10 || colorspace == 8) {
422 main_link =
ctx->inputs[0];
477 "Error when evaluating the expression '%s'.\n", expr);
500 if (scale->
w > INT_MAX ||
501 scale->
h > INT_MAX ||
502 (scale->
h * inlink->
w) > INT_MAX ||
503 (scale->
w * inlink->
h) > INT_MAX)
506 outlink->
w = scale->
w;
507 outlink->
h = scale->
h;
523 if (inlink0->
w == outlink->
w &&
524 inlink0->
h == outlink->
h &&
533 for (
i = 0;
i < 3;
i++) {
567 in_v_chr_pos = (
i == 0) ? 128 : (
i == 1) ? 64 : 192;
571 out_v_chr_pos = (
i == 0) ? 128 : (
i == 1) ? 64 : 192;
607 outlink->
w = inlink->
w;
608 outlink->
h = inlink->
h;
631 int in_stride[4],out_stride[4];
634 for (
i=0;
i<4;
i++) {
635 int vsub= ((
i+1)&2) ? scale->
vsub : 0;
665 frame_changed =
in->width != link->
w ||
666 in->height != link->
h ||
683 scale->
w && scale->
h)
687 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
w);
689 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
h);
739 out->width = outlink->
w;
740 out->height = outlink->
h;
745 in_range =
in->color_range;
753 const int *inv_table, *
table;
756 (
int **)&
table, &out_full,
788 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
789 (int64_t)
in->sample_aspect_ratio.num * outlink->
h * link->
w,
790 (int64_t)
in->sample_aspect_ratio.den * outlink->
w * link->
h,
799 for (
i = 0;
i < nb_slices;
i++) {
833 frame_changed =
in->width != link->
w ||
834 in->height != link->
h ||
842 link->
h =
in->height;
859 char *res,
int res_len,
int flags)
866 w = !strcmp(cmd,
"width") || !strcmp(cmd,
"w");
867 h = !strcmp(cmd,
"height") || !strcmp(cmd,
"h");
883 #if FF_API_CHILD_CLASS_NEXT
893 *iter = (
void*)(uintptr_t)
c;
897 #define OFFSET(x) offsetof(ScaleContext, x)
898 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
899 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
930 {
"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 },
931 {
"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 },
932 {
"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 },
933 {
"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 },
934 {
"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" },
938 {
"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 },
941 {
"nb_slices",
"set the number of slices (debug purpose only)",
OFFSET(nb_slices),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
FLAGS },
954 #if FF_API_CHILD_CLASS_NEXT
955 .child_class_next = child_class_next,
980 .description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format."),
997 #if FF_API_CHILD_CLASS_NEXT
998 .child_class_next = child_class_next,
1034 .
name =
"scale2ref",
1035 .description =
NULL_IF_CONFIG_SMALL(
"Scale the input video size and/or convert the image format to the given reference."),
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Main libavfilter public API header.
#define flags(name, subs,...)
#define sws_isSupportedOutput(x)
#define sws_isSupportedInput(x)
#define FFSWAP(type, a, b)
static enum AVPixelFormat pix_fmt
static float mul(float src0, float src1)
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
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
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.
#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.
char * av_strdup(const char *s)
Duplicate a string.
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_getColorspaceDetails(struct SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
av_warn_unused_result int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
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)
int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
struct SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
#define SWS_PARAM_DEFAULT
int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
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)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_PTR_ADD(ptr, off)
@ AV_CLASS_CATEGORY_FILTER
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
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_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ 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
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 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_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
functionally identical to above
@ AVCOL_SPC_YCGCO
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
static const uint16_t table[]
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 ...
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Rational number (pair of numerator and denominator).
int eval_mode
expression evaluation mode
struct SwsContext * sws
software scaler context
int slice_y
top of current output slice
int force_original_aspect_ratio
int output_is_pal
set to 1 if the output format is paletted
int input_is_pal
set to 1 if the input format is paletted
struct SwsContext * isws[2]
software scaler context for interlaced material
char * w_expr
width expression string
char * h_expr
height expression string
int vsub
chroma subsampling
double var_values[VARS_NB]
double param[2]
Input parameters for scaling algorithms that need them.
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 scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
static const AVFilterPad avfilter_vf_scale_outputs[]
static const AVClass * child_class_iterate(void **iter)
static int filter_frame(AVFilterLink *link, AVFrame *in)
static int query_formats(AVFilterContext *ctx)
static const AVClass scale2ref_class
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 int scale_slice(AVFilterLink *link, AVFrame *out_buf, AVFrame *cur_pic, struct SwsContext *sws, int y, int h, int mul, int field)
static const AVFilterPad avfilter_vf_scale2ref_inputs[]
static const char *const var_names[]
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 av_cold void uninit(AVFilterContext *ctx)
static const int * parse_yuv_type(const char *s, enum AVColorSpace colorspace)
static const AVFilterPad avfilter_vf_scale_inputs[]
static const AVOption scale_options[]
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
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.