Go to the documentation of this file.
44 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
221 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with scale2ref_npp variables are not valid in scale_npp filter.\n");
237 av_log(
ctx,
AV_LOG_ERROR,
"Expressions with frame variables 'n', 't', are not valid in init eval_mode.\n");
245 AVExpr** pexpr_ptr,
const char* var,
249 int ret, is_inited = 0;
250 char* old_str_expr =
NULL;
261 old_pexpr = *pexpr_ptr;
295 *pexpr_ptr = old_pexpr;
305 if (!strcmp(
scale->format_str,
"same")) {
317 "Size and width/height exprs cannot be set at the same time.\n");
324 if (
scale->size_str) {
343 if (!
scale->w_expr) {
349 if (!
scale->h_expr) {
365 if (!
scale->stages[
i].frame)
369 if (!
scale->tmp_frame)
391 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
411 expr =
scale->h_expr;
419 expr =
scale->w_expr;
449 s->w_pexpr =
s->h_pexpr =
NULL;
456 int in_sw, in_sh, out_sw, out_sh;
536 int out_width,
int out_height)
549 int i,
ret, last_stage = -1;
578 if (in_width != out_width || in_height != out_height ||
579 in_deinterleaved_format != out_deinterleaved_format) {
582 if (
s->interp_algo == NPPI_INTER_SUPER &&
583 (out_width > in_width && out_height > in_height)) {
584 s->interp_algo = NPPI_INTER_LANCZOS;
587 if (
s->interp_algo == NPPI_INTER_SUPER &&
588 !(out_width < in_width && out_height < in_height)) {
589 s->interp_algo = NPPI_INTER_CUBIC;
594 if (!
s->stages[
STAGE_RESIZE].stage_needed && in_format == out_format)
597 if (!
s->passthrough) {
598 if (in_format != in_deinterleaved_format)
600 if (out_format != out_deinterleaved_format)
623 if (!
s->stages[
i].stage_needed)
658 s->force_original_aspect_ratio,
659 s->force_divisible_by);
661 if (
s->w > INT_MAX ||
s->h > INT_MAX ||
662 (
s->h *
inlink->w) > INT_MAX ||
676 if (
inlink->sample_aspect_ratio.num)
679 inlink->sample_aspect_ratio);
715 err = nppiYCbCr420_8u_P2P3R(in->
data[0], in->
linesize[0],
718 (NppiSize){ in->width, in->height });
723 if (err != NPP_SUCCESS) {
744 err = nppiResizeSqrPixel_8u_C1R(in->
data[
i], (NppiSize){ iw, ih },
745 in->
linesize[
i], (NppiRect){ 0, 0, iw, ih },
747 (NppiRect){ 0, 0, ow, oh },
748 (
double)ow / iw, (
double)oh / ih,
749 0.0, 0.0,
s->interp_algo);
750 if (err != NPP_SUCCESS) {
767 err = nppiYCbCr420_8u_P3P2R((
const uint8_t**)in->
data,
769 out->data[0],
out->linesize[0],
770 out->data[1],
out->linesize[1],
771 (NppiSize){ in->width, in->height });
776 if (err != NPP_SUCCESS) {
799 int i,
ret, last_stage = -1;
828 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
w);
830 snprintf(buf,
sizeof(buf)-1,
"%d", outlink->
h);
873 if (!
s->stages[
i].stage_needed)
880 src =
s->stages[
i].frame;
890 s->tmp_frame->width =
src->width;
891 s->tmp_frame->height =
src->height;
925 ret =
CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx));
931 CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&
dummy));
935 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
994 #define OFFSET(x) offsetof(NPPScaleContext, x)
995 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
1002 {
"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" },
1003 {
"nn",
"nearest neighbour", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0,
FLAGS, .unit =
"interp_algo" },
1004 {
"linear",
"linear", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LINEAR }, 0, 0,
FLAGS, .unit =
"interp_algo" },
1005 {
"cubic",
"cubic", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC }, 0, 0,
FLAGS, .unit =
"interp_algo" },
1006 {
"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" },
1007 {
"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" },
1008 {
"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" },
1009 {
"super",
"supersampling", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0,
FLAGS, .unit =
"interp_algo" },
1010 {
"lanczos",
"Lanczos", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0,
FLAGS, .unit =
"interp_algo" },
1011 {
"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, .unit =
"force_oar" },
1015 {
"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 },
1047 .
name =
"scale_npp",
1049 "scaling and format conversion"),
1094 .
name =
"scale2ref_npp",
1096 "scaling and format conversion to the "
1097 "given reference."),
static int format_is_supported(enum AVPixelFormat fmt)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
#define FF_ENABLE_DEPRECATION_WARNINGS
#define AV_LOG_WARNING
Something somehow does not look correct.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
static const AVFilterPad nppscale_inputs[]
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
static const AVFilterPad nppscale2ref_inputs[]
struct NPPScaleStageContext::@353 planes_out[4]
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)
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
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
static const AVClass nppscale_class
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
#define FILTER_INPUTS(array)
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).
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static enum AVPixelFormat supported_formats[]
#define AV_LOG_VERBOSE
Detailed information.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Link properties exposed to filter code, but not external callers.
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat 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.
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().
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static void nppscale_uninit(AVFilterContext *ctx)
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
NPPScaleStageContext stages[STAGE_NB]
static int config_props(AVFilterLink *outlink)
static int nppscale_eval_dimensions(AVFilterContext *ctx)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int force_original_aspect_ratio
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(array)
static int check_exprs(AVFilterContext *ctx)
static const AVFilterPad nppscale2ref_outputs[]
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 nppscale_scale(AVFilterLink *link, AVFrame *out, AVFrame *in)
static int request_frame_ref(AVFilterLink *outlink)
static const char *const var_names[]
static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
const AVFilter ff_vf_scale2ref_npp
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
static int request_frame(AVFilterLink *outlink)
char * h_expr
height expression string
static FilterLink * ff_filter_link(AVFilterLink *link)
@ AV_CLASS_CATEGORY_FILTER
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static int nppscale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr **pexpr_ptr, const char *var, const char *args)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum AVPixelFormat out_fmt
AVRational time_base
Time base for the timestamps in this frame.
static int nppscale_filter_frame_ref(AVFilterLink *link, AVFrame *in)
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
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.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
const AVFilter ff_vf_scale_npp
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
static int config_props_ref(AVFilterLink *outlink)
enum AVPixelFormat format
Output sw format.
struct NPPScaleStageContext::@353 planes_in[4]
@ 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...
#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...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
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 ...
char * w_expr
width expression string
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
enum AVPixelFormat in_fmt
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
static av_cold int nppscale_init(AVFilterContext *ctx)
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int(*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
static const AVFilterPad nppscale_outputs[]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
char * av_strdup(const char *s)
Duplicate a string.
A reference to a data buffer.
static const AVOption options[]
static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static enum AVPixelFormat deinterleaved_formats[][2]
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
double var_values[VARS_NB]
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
@ 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...
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static const struct @458 planes[]
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.