44#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
166#define IS_SCALE2REF(ctx) ((ctx)->filter == &ff_vf_scale2ref_npp.p)
207 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with scale2ref_npp variables are not valid in scale_npp filter.\n");
216 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with frame variables 'n', 't', are not valid in init eval_mode.\n");
224 AVExpr** pexpr_ptr,
const char* var,
228 int ret, is_inited = 0;
229 char* old_str_expr =
NULL;
240 old_pexpr = *pexpr_ptr;
274 *pexpr_ptr = old_pexpr;
286 if (!strcmp(
scale->format_str,
"same")) {
298 "Size and width/height exprs cannot be set at the same time.\n");
305 if (
scale->size_str) {
324 if (!
scale->w_expr) {
330 if (!
scale->h_expr) {
346 if (!
scale->stages[
i].frame)
350 if (!
scale->tmp_frame)
392 expr =
scale->h_expr;
400 expr =
scale->w_expr;
430 s->w_pexpr =
s->h_pexpr =
NULL;
437 int in_sw, in_sh, out_sw, out_sh;
517 int out_width,
int out_height)
530 int i, ret, last_stage = -1;
559 if (in_width != out_width || in_height != out_height ||
560 in_deinterleaved_format != out_deinterleaved_format) {
563 if (
s->interp_algo == NPPI_INTER_SUPER &&
564 (out_width > in_width && out_height > in_height)) {
565 s->interp_algo = NPPI_INTER_LANCZOS;
568 if (
s->interp_algo == NPPI_INTER_SUPER &&
569 !(out_width < in_width && out_height < in_height)) {
570 s->interp_algo = NPPI_INTER_CUBIC;
575 if (!
s->stages[
STAGE_RESIZE].stage_needed && in_format == out_format)
578 if (!
s->passthrough) {
579 if (in_format != in_deinterleaved_format)
581 if (out_format != out_deinterleaved_format)
604 if (!
s->stages[
i].stage_needed)
644 s->force_original_aspect_ratio,
645 s->force_divisible_by, w_adj);
649 if (
s->w > INT_MAX ||
s->h > INT_MAX ||
650 (
s->h * inlink->
w) > INT_MAX ||
651 (
s->w * inlink->
h) > INT_MAX)
662 inlink->
w, inlink->
h, outlink->
w, outlink->
h);
668 outlink->
w*inlink->
h},
686 outlink->
w = inlink->
w;
687 outlink->
h = inlink->
h;
705 err = nppiYCbCr420_8u_P2P3R(in->
data[0], in->
linesize[0],
708 (NppiSize){ in->width, in->height });
713 if (err != NPP_SUCCESS) {
734 err = nppiResizeSqrPixel_8u_C1R(in->
data[
i], (NppiSize){ iw, ih },
735 in->
linesize[
i], (NppiRect){ 0, 0, iw, ih },
737 (NppiRect){ 0, 0, ow, oh },
738 (
double)ow / iw, (
double)oh / ih,
739 0.0, 0.0,
s->interp_algo);
740 if (err != NPP_SUCCESS) {
757 err = nppiYCbCr420_8u_P3P2R((
const uint8_t**)in->
data,
759 out->data[0],
out->linesize[0],
760 out->data[1],
out->linesize[1],
761 (NppiSize){ in->width, in->height });
766 if (err != NPP_SUCCESS) {
789 int i, ret, last_stage = -1;
792 frame_changed = in->
width != link->
w ||
810 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
w);
812 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
h);
845 if (!
s->stages[
i].stage_needed)
852 src =
s->stages[
i].frame;
862 s->tmp_frame->width =
src->width;
863 s->tmp_frame->height =
src->height;
912 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
932 frame_changed = in->
width != link->
w ||
966#define OFFSET(x) offsetof(NPPScaleContext, x)
967#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
974 {
"interp_algo",
"Interpolation algorithm used for resizing",
OFFSET(interp_algo),
AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX,
FLAGS, .unit =
"interp_algo" },
975 {
"nn",
"nearest neighbour", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0,
FLAGS, .unit =
"interp_algo" },
976 {
"linear",
"linear", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LINEAR }, 0, 0,
FLAGS, .unit =
"interp_algo" },
977 {
"cubic",
"cubic", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC }, 0, 0,
FLAGS, .unit =
"interp_algo" },
978 {
"cubic2p_bspline",
"2-parameter cubic (B=1, C=0)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE }, 0, 0,
FLAGS, .unit =
"interp_algo" },
979 {
"cubic2p_catmullrom",
"2-parameter cubic (B=0, C=1/2)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_CATMULLROM }, 0, 0,
FLAGS, .unit =
"interp_algo" },
980 {
"cubic2p_b05c03",
"2-parameter cubic (B=1/2, C=3/10)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_B05C03 }, 0, 0,
FLAGS, .unit =
"interp_algo" },
981 {
"super",
"supersampling", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0,
FLAGS, .unit =
"interp_algo" },
982 {
"lanczos",
"Lanczos", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0,
FLAGS, .unit =
"interp_algo" },
983 {
"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" },
987 {
"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 },
988 {
"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 },
996 .class_name =
"nppscale",
1020 .p.name =
"scale_npp",
1022 "scaling and format conversion"),
1067 .p.name =
"scale2ref_npp",
1069 "scaling and format conversion to the "
1070 "given reference."),
static int request_frame(AVFilterLink *outlink)
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 i(width, name, range_min, range_max)
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
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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...
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
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.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
#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.
#define LIBAVUTIL_VERSION_INT
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
FFmpeg internal API for CUDA.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const struct @257111027162314367033347246032313251342043035002 planes[]
@ AV_CLASS_CATEGORY_FILTER
#define FFSWAP(type, a, b)
Memory handling functions.
static const char *const var_names[]
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
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.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
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 int config_props(AVBitStreamFilterLink *link)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
AVCUDADeviceContextInternal * internal
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
AVFilterContext * dst
dest filter
int format
agreed upon media format
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).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
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 format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int width
The allocated dimensions of the frames in this pool.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
int force_original_aspect_ratio
double var_values[VARS_NB]
NPPScaleStageContext stages[STAGE_NB]
char * w_expr
width expression string
enum AVPixelFormat format
Output sw format.
char * h_expr
height expression string
enum AVPixelFormat in_fmt
enum AVPixelFormat out_fmt
struct NPPScaleStageContext::@344171316067121270005364033201134017260314124266 planes_out[4]
struct NPPScaleStageContext::@344171316067121270005364033201134017260314124266 planes_in[4]
static AVFormatContext * ctx
static enum AVPixelFormat supported_formats[]
static int request_frame_ref(AVFilterLink *outlink)
static int config_props_ref(AVFilterLink *outlink)
#define IS_SCALE2REF(ctx)
static const AVFilterPad nppscale2ref_inputs[]
static int config_props(AVFilterLink *outlink)
static int request_frame_ref(AVFilterLink *outlink)
static enum AVPixelFormat deinterleaved_formats[][2]
const FFFilter ff_vf_scale2ref_npp
static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
static int nppscale_scale(AVFilterLink *link, AVFrame *out, AVFrame *in)
static const AVFilterPad nppscale_inputs[]
static const AVClass nppscale_class
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vf_scale_npp
static int config_props_ref(AVFilterLink *outlink)
static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
static void nppscale_uninit(AVFilterContext *ctx)
static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
static const AVFilterPad nppscale2ref_outputs[]
static av_cold int nppscale_init(AVFilterContext *ctx)
static int format_is_supported(enum AVPixelFormat fmt)
static int nppscale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr **pexpr_ptr, const char *var, const char *args)
static const AVFilterPad nppscale_outputs[]
static int check_exprs(AVFilterContext *ctx)
#define IS_SCALE2REF(ctx)
static int nppscale_filter_frame_ref(AVFilterLink *link, AVFrame *in)
static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
static int nppscale_eval_dimensions(AVFilterContext *ctx)
static int(*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)