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
32#include "version_major.h"32#include "version_major.h"
33 33
34#define LIBAVFILTER_VERSION_MINOR 634#define LIBAVFILTER_VERSION_MINOR 6
35#define LIBAVFILTER_VERSION_MICRO 10035#define LIBAVFILTER_VERSION_MICRO 101
36 36
37 37
38#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \38#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
407}407}
408 408
409static int call_resize_kernel(AVFilterContext *ctx, CUfunction func,409static 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,
411 AVFrame *out_frame, int dst_width, int dst_height, int dst_pitch)411 AVFrame *out_frame, int dst_width, int dst_height, int dst_pitch)
412{412{
413 CUDAScaleContext *s = ctx->priv;413 CUDAScaleContext *s = ctx->priv;
@@ -422,7 +422,7 @@ static int call_resize_kernel(AVFilterContext *ctx, CUfunction func, · 8 unmodified lines
422 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],422 &src_tex[0], &src_tex[1], &src_tex[2], &src_tex[3],
423 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],423 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
424 &dst_width, &dst_height, &dst_pitch,424 &dst_width, &dst_height, &dst_pitch,
425 &src_width, &src_height, &s->param425 &src_left, &src_top, &src_width, &src_height, &s->param
426 };426 };
427 427
428 return CHECK_CU(cu->cuLaunchKernel(func,428 return CHECK_CU(cu->cuLaunchKernel(func,
@@ -440,6 +440,9 @@ static int scalecuda_resize(AVFilterContext *ctx, · 11 unmodified lines
440 440
441 CUtexObject tex[4] = { 0, 0, 0, 0 };441 CUtexObject tex[4] = { 0, 0, 0, 0 };
442 442
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
443 ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));446 ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
444 if (ret < 0)447 if (ret < 0)
445 return ret;448 return ret;
@@ -477,7 +480,7 @@ static int scalecuda_resize(AVFilterContext *ctx, · 31 unmodified lines
477 480
478 // scale primary plane(s). Usually Y (and A), or single plane of RGB frames.481 // scale primary plane(s). Usually Y (and A), or single plane of RGB frames.
479 ret = call_resize_kernel(ctx, s->cu_func,482 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,
481 out, out->width, out->height, out->linesize[0]);484 out, out->width, out->height, out->linesize[0]);
482 if (ret < 0)485 if (ret < 0)
483 goto exit;486 goto exit;
@@ -485,8 +488,10 @@ static int scalecuda_resize(AVFilterContext *ctx, · 1 unmodified line
485 if (s->out_planes > 1) {488 if (s->out_planes > 1) {
486 // scale UV plane. Scale function sets both U and V plane, or singular interleaved plane.489 // scale UV plane. Scale function sets both U and V plane, or singular interleaved plane.
487 ret = call_resize_kernel(ctx, s->cu_func_uv, tex,490 ret = call_resize_kernel(ctx, s->cu_func_uv, tex,
488 AV_CEIL_RSHIFT(in->width, s->in_desc->log2_chroma_w),491 AV_CEIL_RSHIFT(in->crop_left, s->in_desc->log2_chroma_w),
489 AV_CEIL_RSHIFT(in->height, s->in_desc->log2_chroma_h),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),
490 out,495 out,
491 AV_CEIL_RSHIFT(out->width, s->out_desc->log2_chroma_w),496 AV_CEIL_RSHIFT(out->width, s->out_desc->log2_chroma_w),
492 AV_CEIL_RSHIFT(out->height, s->out_desc->log2_chroma_h),497 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
26template<typename T>26template<typename T>
27using subsample_function_t = T (*)(cudaTextureObject_t tex, int xo, int yo,27using subsample_function_t = T (*)(cudaTextureObject_t tex, int xo, int yo,
28 int dst_width, int dst_height,28 int dst_width, int dst_height,
29 int src_left, int src_top,
29 int src_width, int src_height,30 int src_width, int src_height,
30 int bit_depth, float param);31 int bit_depth, float param);
31 32
@@ -64,11 +65,12 @@ static inline __device__ ushort conv_16to10(ushort in) · 32 unmodified lines
64 subsample_function_t<in_T_uv> subsample_func_uv> \65 subsample_function_t<in_T_uv> subsample_func_uv> \
65 __device__ static inline void N(cudaTextureObject_t src_tex[4], T *dst[4], int xo, int yo, \66 __device__ static inline void N(cudaTextureObject_t src_tex[4], T *dst[4], int xo, int yo, \
66 int dst_width, int dst_height, int dst_pitch, \67 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)
68 69
69#define SUB_F(m, plane) \70#define SUB_F(m, plane) \
70 subsample_func_##m(src_tex[plane], xo, yo, \71 subsample_func_##m(src_tex[plane], xo, yo, \
71 dst_width, dst_height, \72 dst_width, dst_height, \
73 src_left, src_top, \
72 src_width, src_height, \74 src_width, src_height, \
73 in_bit_depth, param)75 in_bit_depth, param)
74 76
@@ -1063,13 +1065,14 @@ template<typename T> · 988 unmodified lines
1063__device__ static inline T Subsample_Nearest(cudaTextureObject_t tex,1065__device__ static inline T Subsample_Nearest(cudaTextureObject_t tex,
1064 int xo, int yo,1066 int xo, int yo,
1065 int dst_width, int dst_height,1067 int dst_width, int dst_height,
1068 int src_left, int src_top,
1066 int src_width, int src_height,1069 int src_width, int src_height,
1067 int bit_depth, float param)1070 int bit_depth, float param)
1068{1071{
1069 float hscale = (float)src_width / (float)dst_width;1072 float hscale = (float)src_width / (float)dst_width;
1070 float vscale = (float)src_height / (float)dst_height;1073 float vscale = (float)src_height / (float)dst_height;
1071 float xi = (xo + 0.5f) * hscale;1074 float xi = (xo + 0.5f) * hscale + src_left;
1072 float yi = (yo + 0.5f) * vscale;1075 float yi = (yo + 0.5f) * vscale + src_top;
1073 1076
1074 return tex2D<T>(tex, xi, yi);1077 return tex2D<T>(tex, xi, yi);
1075}1078}
@@ -1078,13 +1081,14 @@ template<typename T> · 2 unmodified lines
1078__device__ static inline T Subsample_Bilinear(cudaTextureObject_t tex,1081__device__ static inline T Subsample_Bilinear(cudaTextureObject_t tex,
1079 int xo, int yo,1082 int xo, int yo,
1080 int dst_width, int dst_height,1083 int dst_width, int dst_height,
1084 int src_left, int src_top,
1081 int src_width, int src_height,1085 int src_width, int src_height,
1082 int bit_depth, float param)1086 int bit_depth, float param)
1083{1087{
1084 float hscale = (float)src_width / (float)dst_width;1088 float hscale = (float)src_width / (float)dst_width;
1085 float vscale = (float)src_height / (float)dst_height;1089 float vscale = (float)src_height / (float)dst_height;
1086 float xi = (xo + 0.5f) * hscale;1090 float xi = (xo + 0.5f) * hscale + src_left;
1087 float yi = (yo + 0.5f) * vscale;1091 float yi = (yo + 0.5f) * vscale + src_top;
1088 // 3-tap filter weights are {wh,1.0,wh} and {wv,1.0,wv}1092 // 3-tap filter weights are {wh,1.0,wh} and {wv,1.0,wv}
1089 float wh = min(max(0.5f * (hscale - 1.0f), 0.0f), 1.0f);1093 float wh = min(max(0.5f * (hscale - 1.0f), 0.0f), 1.0f);
1090 float wv = min(max(0.5f * (vscale - 1.0f), 0.0f), 1.0f);1094 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
1109__device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex,1113__device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex,
1110 int xo, int yo,1114 int xo, int yo,
1111 int dst_width, int dst_height,1115 int dst_width, int dst_height,
1116 int src_left, int src_top,
1112 int src_width, int src_height,1117 int src_width, int src_height,
1113 int bit_depth, float param)1118 int bit_depth, float param)
1114{1119{
1115 float hscale = (float)src_width / (float)dst_width;1120 float hscale = (float)src_width / (float)dst_width;
1116 float vscale = (float)src_height / (float)dst_height;1121 float vscale = (float)src_height / (float)dst_height;
1117 float xi = (xo + 0.5f) * hscale - 0.5f;1122 float xi = (xo + 0.5f) * hscale - 0.5f + src_left;
1118 float yi = (yo + 0.5f) * vscale - 0.5f;1123 float yi = (yo + 0.5f) * vscale - 0.5f + src_top;
1119 float px = floor(xi);1124 float px = floor(xi);
1120 float py = floor(yi);1125 float py = floor(yi);
1121 float fx = xi - px;1126 float fx = xi - px;
@@ -1147,7 +1152,7 @@ __device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex, · 25 unmodified lines
1147 cudaTextureObject_t src_tex_2, cudaTextureObject_t src_tex_3, \1152 cudaTextureObject_t src_tex_2, cudaTextureObject_t src_tex_3, \
1148 T *dst_0, T *dst_1, T *dst_2, T *dst_3, \1153 T *dst_0, T *dst_1, T *dst_2, T *dst_3, \
1149 int dst_width, int dst_height, int dst_pitch, \1154 int dst_width, int dst_height, int dst_pitch, \
1150 int src_width, int src_height, float param1155 int src_left, int src_top, int src_width, int src_height, float param
1151 1156
1152#define SUBSAMPLE(Convert, T) \1157#define SUBSAMPLE(Convert, T) \
1153 cudaTextureObject_t src_tex[4] = \1158 cudaTextureObject_t src_tex[4] = \
@@ -1159,6 +1164,7 @@ __device__ static inline T Subsample_Bicubic(cudaTextureObject_t tex, · 5 unmodified lines
1159 Convert( \1164 Convert( \
1160 src_tex, dst, xo, yo, \1165 src_tex, dst, xo, yo, \
1161 dst_width, dst_height, dst_pitch, \1166 dst_width, dst_height, dst_pitch, \
1167 src_left, src_top, \
1162 src_width, src_height, param);1168 src_width, src_height, param);
1163 1169
1164extern "C" {1170extern "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