128 "Size and width/height expressions cannot be set at the same time.\n");
139 "Invalid size '%s'\n", s->
size_str);
142 snprintf(buf,
sizeof(buf)-1,
"%d", s->
w);
144 snprintf(buf,
sizeof(buf)-1,
"%d", s->
h);
194 double var_values[
VARS_NB], res;
197 int factor_w, factor_h;
203 var_values[
VAR_A] = (double) inlink->
w / inlink->
h;
255 w =
av_rescale(h, inlink->
w, inlink->
h * factor_w) * factor_w;
257 h =
av_rescale(w, inlink->
h, inlink->
w * factor_h) * factor_h;
274 if (w > INT_MAX || h > INT_MAX ||
275 (h * inlink->
w) > INT_MAX ||
276 (w * inlink->
h) > INT_MAX)
282 if (inlink->
w == outlink->
w &&
283 inlink->
h == outlink->
h &&
303 "Error when evaluating the expression '%s'.\n"
304 "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
312 int err_code = zimg_get_last_error(err_msg,
sizeof(err_msg));
321 switch (colorspace) {
323 return ZIMG_MATRIX_RGB;
325 return ZIMG_MATRIX_709;
327 return ZIMG_MATRIX_UNSPECIFIED;
329 return ZIMG_MATRIX_470BG;
331 return ZIMG_MATRIX_170M;
333 return ZIMG_MATRIX_YCGCO;
335 return ZIMG_MATRIX_2020_NCL;
337 return ZIMG_MATRIX_2020_CL;
339 return ZIMG_MATRIX_UNSPECIFIED;
346 return ZIMG_TRANSFER_UNSPECIFIED;
348 return ZIMG_TRANSFER_709;
350 return ZIMG_TRANSFER_601;
352 return ZIMG_TRANSFER_LINEAR;
354 return ZIMG_TRANSFER_2020_10;
356 return ZIMG_TRANSFER_2020_12;
358 return ZIMG_TRANSFER_UNSPECIFIED;
363 switch (color_primaries) {
365 return ZIMG_PRIMARIES_UNSPECIFIED;
367 return ZIMG_PRIMARIES_709;
369 return ZIMG_PRIMARIES_170M;
371 return ZIMG_PRIMARIES_240M;
373 return ZIMG_PRIMARIES_2020;
375 return ZIMG_PRIMARIES_UNSPECIFIED;
380 switch (color_range) {
383 return ZIMG_RANGE_LIMITED;
385 return ZIMG_RANGE_FULL;
387 return ZIMG_RANGE_LIMITED;
396 zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
397 zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
424 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
w);
426 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
h);
439 zimg_image_format_default(&s->
src_format, ZIMG_API_VERSION);
440 zimg_image_format_default(&s->
dst_format, ZIMG_API_VERSION);
441 zimg_graph_builder_params_default(&s->
params, ZIMG_API_VERSION);
444 s->
params.cpu_type = ZIMG_CPU_AUTO;
484 zimg_filter_graph_free(s->
graph);
491 if ((ret = zimg_filter_graph_get_tmp_size(s->
graph, &tmp_size))) {
518 zimg_graph_builder_params_default(&s->
alpha_params, ZIMG_API_VERSION);
566 src_buf.plane[
plane].mask = -1;
569 dst_buf.plane[
plane].data = out->
data[p];
571 dst_buf.plane[
plane].mask = -1;
574 ret = zimg_filter_graph_process(s->
graph, &src_buf, &dst_buf, s->
tmp, 0, 0, 0, 0);
581 src_buf.plane[0].data = in->
data[3];
582 src_buf.plane[0].stride = in->
linesize[3];
583 src_buf.plane[0].mask = -1;
585 dst_buf.plane[0].data = out->
data[3];
586 dst_buf.plane[0].stride = out->
linesize[3];
587 dst_buf.plane[0].mask = -1;
589 ret = zimg_filter_graph_process(s->
alpha_graph, &src_buf, &dst_buf, s->
tmp, 0, 0, 0, 0);
597 for (y = 0; y < outlink->
h; y++)
598 memset(out->
data[3] + y * out->
linesize[3], 0xff, outlink->
w);
615 zimg_filter_graph_free(s->
graph);
621 char *res,
int res_len,
int flags)
626 if ( !strcmp(cmd,
"width") || !strcmp(cmd,
"w")
627 || !strcmp(cmd,
"height") || !strcmp(cmd,
"h")) {
644 #define OFFSET(x) offsetof(ZScaleContext, x)
645 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
659 {
"error_diffusion", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0,
FLAGS,
"dither" },
673 {
"primaries",
"set color primaries",
OFFSET(primaries),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020,
FLAGS,
"primaries" },
677 {
"unspecified", 0, 0,
AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0,
FLAGS,
"primaries" },
681 {
"transfer",
"set transfer characteristic",
OFFSET(trc),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12,
FLAGS,
"transfer" },
682 {
"t",
"set transfer characteristic",
OFFSET(trc),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12,
FLAGS,
"transfer" },
690 {
"matrix",
"set colorspace matrix",
OFFSET(colorspace),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL,
FLAGS,
"matrix" },
702 {
"primariesin",
"set input color primaries",
OFFSET(primaries_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020,
FLAGS,
"primaries" },
703 {
"pin",
"set input color primaries",
OFFSET(primaries_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020,
FLAGS,
"primaries" },
704 {
"transferin",
"set input transfer characteristic",
OFFSET(trc_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12,
FLAGS,
"transfer" },
705 {
"tin",
"set input transfer characteristic",
OFFSET(trc_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12,
FLAGS,
"transfer" },
706 {
"matrixin",
"set input colorspace matrix",
OFFSET(colorspace_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL,
FLAGS,
"matrix" },
707 {
"min",
"set input colorspace matrix",
OFFSET(colorspace_in),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL,
FLAGS,
"matrix" },
743 .priv_class = &zscale_class,
745 .
inputs = avfilter_vf_zscale_inputs,
746 .
outputs = avfilter_vf_zscale_outputs,
ITU-R BT2020 for 12 bit system.
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
static const AVFilterPad avfilter_vf_zscale_outputs[]
int plane
Which of the 4 planes contains the component.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P9
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
"Linear transfer characteristics"
#define AV_PIX_FMT_YUVA420P10
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 AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA422P10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
int h
agreed upon image height
#define AV_PIX_FMT_GBRP10
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above ...
zimg_image_format dst_format
#define AV_PIX_FMT_YUV420P12
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
zimg_graph_builder_params alpha_params
enum AVColorSpace in_colorspace out_colorspace
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
AVColorTransferCharacteristic
Color Transfer Characteristic.
char * w_expr
width expression string
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
zimg_filter_graph * alpha_graph
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int print_zimg_error(AVFilterContext *ctx)
enum AVColorPrimaries in_primaries out_primaries
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
zimg_image_format alpha_dst_format
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
AVColorSpace
YUV colorspace type.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
#define AV_PIX_FMT_YUVA420P9
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_LOG_VERBOSE
Detailed information.
static const AVFilterPad avfilter_vf_zscale_inputs[]
static int convert_range(enum AVColorRange color_range)
#define AV_PIX_FMT_YUV444P16
AVColorRange
MPEG vs JPEG YUV range.
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUVA420P16
AVColorPrimaries
Chromaticity coordinates of the source primaries.
static int convert_matrix(enum AVColorSpace colorspace)
static int query_formats(AVFilterContext *ctx)
A filter pad used for either input or output.
enum AVColorRange in_range out_range
A link between two filters.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
static int filter_frame(AVFilterLink *link, AVFrame *in)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const uint8_t dither[8][8]
void * priv
private data for use by the filter
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_PIX_FMT_YUVA444P16
enum AVColorSpace colorspace
YUV colorspace type.
zimg_image_format alpha_src_format
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
simple assert() macros that are a bit more flexible than ISO C assert().
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
#define AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_GBRAP16
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
common internal API header
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_GBRP16
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
zimg_filter_graph * graph
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static void uninit(AVFilterContext *ctx)
ITU-R BT2020 non-constant luminance system.
AVFilterContext * src
source filter
#define AV_PIX_FMT_YUVA444P10
static const AVFilterPad outputs[]
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
int format
agreed upon media format
the normal 2^n-1 "JPEG" YUV ranges
#define AV_PIX_FMT_YUV420P16
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static const AVFilterPad inputs[]
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
#define AV_PIX_FMT_YUV420P14
zimg_graph_builder_params params
functionally identical to above
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int convert_trc(enum AVColorTransferCharacteristic color_trc)
static const char *const var_names[]
char * h_expr
height expression string
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
zimg_image_format src_format
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define AV_PIX_FMT_YUV420P10
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
static int convert_primaries(enum AVColorPrimaries color_primaries)
rational number numerator/denominator
const char * name
Filter name.
#define AV_PIX_FMT_YUV420P9
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterLink ** outputs
array of pointers to output links
static const AVClass zscale_class
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
static int config_props(AVFilterLink *outlink)
ITU-R BT2020 constant luminance system.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_YUVA444P9
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static const AVOption zscale_options[]
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int force_original_aspect_ratio
AVFilterContext * dst
dest filter
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
enum AVColorPrimaries color_primaries
ITU-R BT2020 for 10 bit system.
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
enum AVColorTransferCharacteristic color_trc
#define FFSWAP(type, a, b)
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.
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
enum AVColorTransferCharacteristic in_trc out_trc
#define AV_PIX_FMT_YUV422P16
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFilterFormats * out_formats
simple arithmetic expression evaluator