History

avfilter/scale_cuda: frame crop support

The crop filter has no effect on scale_cuda: -vf crop=100:100,scale_cuda=100x100 Hardware frames (AV_PIX_FMT_FLAG_HWACCEL) are expected to use the crop_* properties, as seen in the implementation vf_crop.c.

Koushik Dutta committed 2 years ago

Commit 0cdcbab1 parent 18640253 files · +25 −14Browse files

Unified · Split

3 files
  1. libavfilter/version.h +1 −1
  2. libavfilter/vf_scale_cuda.c +10 −5
  3. libavfilter/vf_scale_cuda.cu +14 −8
libavfilter/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 #include "version_major.h"
3333
3434 #define LIBAVFILTER_VERSION_MINOR 6
35−#define LIBAVFILTER_VERSION_MICRO 100
35+#define LIBAVFILTER_VERSION_MICRO 101
3636
3737
3838 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
libavfilter/vf_scale_cuda.c+10−5
@@ -407,7 +407,7 @@ fail: · 406 unmodified lines
407407 }
408408
409409 static int call_resize_kernel(AVFilterContext *ctx, CUfunction func,
410− CUtexObject src_tex[4], int src_width, int src_height,
410+ CUtexObject src_tex[4], int src_left, int src_top, int src_width, int src_height,
411411 AVFrame *out_frame, int dst_width, int dst_height, int dst_pitch)
412412 {
413413 CUDAScaleContext *s = ctx->priv;
@@ -422,7 +422,7 @@ static int call_resize_kernel(AVFilterContext *ctx, CUfunction func, · 8 unmodified lines
422422 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],
423423 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
424424 &dst_width, &dst_height, &dst_pitch,
425− &src_width, &src_height, &s->param
425+ &src_left, &src_top, &src_width, &src_height, &s->param
426426 };
427427
428428 return CHECK_CU(cu->cuLaunchKernel(func,
@@ -440,6 +440,9 @@ static int scalecuda_resize(AVFilterContext *ctx, · 11 unmodified lines
440440
441441 CUtexObject tex[4] = { 0, 0, 0, 0 };
442442
443+ int crop_width = (in->width - in->crop_right) - in->crop_left;
444+ int crop_height = (in->height - in->crop_bottom) - in->crop_top;
445+
443446 ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
444447 if (ret < 0)
445448 return ret;
@@ -477,7 +480,7 @@ static int scalecuda_resize(AVFilterContext *ctx, · 31 unmodified lines
477480
478481 // scale primary plane(s). Usually Y (and A), or single plane of RGB frames.
479482 ret = call_resize_kernel(ctx, s->cu_func,
480− tex, in->width, in->height,
483+ tex, in->crop_left, in->crop_top, crop_width, crop_height,
481484 out, out->width, out->height, out->linesize[0]);
482485 if (ret < 0)
483486 goto exit;
@@ -485,8 +488,10 @@ static int scalecuda_resize(AVFilterContext *ctx, · 1 unmodified line
485488 if (s->out_planes > 1) {
486489 // scale UV plane. Scale function sets both U and V plane, or singular interleaved plane.
487490 ret = call_resize_kernel(ctx, s->cu_func_uv, tex,
488− AV_CEIL_RSHIFT(in->width, s->in_desc->log2_chroma_w),
489− AV_CEIL_RSHIFT(in->height, s->in_desc->log2_chroma_h),
491+ AV_CEIL_RSHIFT(in->crop_left, s->in_desc->log2_chroma_w),
492+ AV_CEIL_RSHIFT(in->crop_top, s->in_desc->log2_chroma_h),
493+ AV_CEIL_RSHIFT(crop_width, s->in_desc->log2_chroma_w),
494+ AV_CEIL_RSHIFT(crop_height, s->in_desc->log2_chroma_h),
490495 out,
491496 AV_CEIL_RSHIFT(out->width, s->out_desc->log2_chroma_w),
492497 AV_CEIL_RSHIFT(out->height, s->out_desc->log2_chroma_h),
libavfilter/vf_scale_cuda.cu+14−8
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 template<typename T>
2727 using subsample_function_t = T (*)(cudaTextureObject_t tex, int xo, int yo,
2828 int dst_width, int dst_height,
29+ int src_left, int src_top,
2930 int src_width, int src_height,
3031 int bit_depth, float param);
3132
@@ -64,11 +65,12 @@ static inline __device__ ushort conv_16to10(ushort in) · 32 unmodified lines
6465 subsample_function_t<in_T_uv> subsample_func_uv> \
6566 __device__ static inline void N(cudaTextureObject_t src_tex[4], T *dst[4], int xo, int yo, \
6667 int dst_width, int dst_height, int dst_pitch, \
67− int src_width, int src_height, float param)
68+ int src_left, int src_top, int src_width, int src_height, float param)
6869
6970 #define SUB_F(m, plane) \
7071 subsample_func_##m(src_tex[plane], xo, yo, \
7172 dst_width, dst_height, \
73+ src_left, src_top, \
7274 src_width, src_height, \
7375 in_bit_depth, param)
7476
@@ -1063,13 +1065,14 @@ template<typename T> · 988 unmodified lines
10631065 __device__ static inline T Subsample_Nearest(cudaTextureObject_t tex,
10641066 int xo, int yo,
10651067 int dst_width, int dst_height,
1068+ int src_left, int src_top,
10661069 int src_width, int src_height,
10671070 int bit_depth, float param)
10681071 {
10691072 float hscale = (float)src_width / (float)dst_width;
10701073 float vscale = (float)src_height / (float)dst_height;
1071− float xi = (xo + 0.5f) * hscale;
1072− float yi = (yo + 0.5f) * vscale;
1074+ float xi = (xo + 0.5f) * hscale + src_left;
1075+ float yi = (yo + 0.5f) * vscale + src_top;
10731076
10741077 return tex2D<T>(tex, xi, yi);
10751078 }
@@ -1078,13 +1081,14 @@ template<typename T> · 2 unmodified lines
10781081 __device__ static inline T Subsample_Bilinear(cudaTextureObject_t tex,
10791082 int xo, int yo,
10801083 int dst_width, int dst_height,
1084+ int src_left, int src_top,
10811085 int src_width, int src_height,
10821086 int bit_depth, float param)
10831087 {
10841088 float hscale = (float)src_width / (float)dst_width;
10851089 float vscale = (float)src_height / (float)dst_height;
1086− float xi = (xo + 0.5f) * hscale;
1087− float yi = (yo + 0.5f) * vscale;
1090+ float xi = (xo + 0.5f) * hscale + src_left;
1091+ float yi = (yo + 0.5f) * vscale + src_top;
10881092 // 3-tap filter weights are {wh,1.0,wh} and {wv,1.0,wv}
10891093 float wh = min(max(0.5f * (hscale - 1.0f), 0.0f), 1.0f);
10901094 float wv = min(max(0.5f * (vscale - 1.0f), 0.0f), 1.0f);
@@ -1109,13 +1113,14 @@ template<typename T, coeffs_function_t coeffs_function> · 18 unmodified lines
11091113 __device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex,
11101114 int xo, int yo,
11111115 int dst_width, int dst_height,
1116+ int src_left, int src_top,
11121117 int src_width, int src_height,
11131118 int bit_depth, float param)
11141119 {
11151120 float hscale = (float)src_width / (float)dst_width;
11161121 float vscale = (float)src_height / (float)dst_height;
1117− float xi = (xo + 0.5f) * hscale - 0.5f;
1118− float yi = (yo + 0.5f) * vscale - 0.5f;
1122+ float xi = (xo + 0.5f) * hscale - 0.5f + src_left;
1123+ float yi = (yo + 0.5f) * vscale - 0.5f + src_top;
11191124 float px = floor(xi);
11201125 float py = floor(yi);
11211126 float fx = xi - px;
@@ -1147,7 +1152,7 @@ __device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex, · 25 unmodified lines
11471152 cudaTextureObject_t src_tex_2, cudaTextureObject_t src_tex_3, \
11481153 T *dst_0, T *dst_1, T *dst_2, T *dst_3, \
11491154 int dst_width, int dst_height, int dst_pitch, \
1150− int src_width, int src_height, float param
1155+ int src_left, int src_top, int src_width, int src_height, float param
11511156
11521157 #define SUBSAMPLE(Convert, T) \
11531158 cudaTextureObject_t src_tex[4] = \
@@ -1159,6 +1164,7 @@ __device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex, · 5 unmodified lines
11591164 Convert( \
11601165 src_tex, dst, xo, yo, \
11611166 dst_width, dst_height, dst_pitch, \
1167+ src_left, src_top, \
11621168 src_width, src_height, param);
11631169
11641170 extern "C" {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t