[FFmpeg-trac] #5822(avfilter:new): filter "scale_npp" fails to select correct algorithm (Nvidia CUDA/NPP scaler)

FFmpeg trac at avcodec.org
Mon Sep 5 17:04:57 EEST 2016


#5822: filter "scale_npp" fails to select correct algorithm (Nvidia CUDA/NPP
scaler)
-------------------------------------+-------------------------------------
             Reporter:  sdack        |                    Owner:
                 Type:  defect       |                   Status:  new
             Priority:  normal       |                Component:  avfilter
              Version:  git-master   |               Resolution:
             Keywords:  scale_npp,   |               Blocked By:
  interp_algo, Nvidia, CUDA, NPP     |  Reproduced by developer:  0
             Blocking:               |
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------

Comment (by sdack):

 I may have found something. It appears to lie with the parameters to the
 function call at line 474 of vf_scale_npp.c:

         err = nppiResizeSqrPixel_8u_C1R(in->data[i], (NppiSize){ iw, ih },
                                         in->linesize[i], (NppiRect){ 0, 0,
 iw, ih },
                                         out->data[i], out->linesize[i],
                                         (NppiRect){ 0, 0, ow, oh },
                                         (double)ow / iw, (double)oh / ih,
                                         0.0, 0.0, s->interp_algo);

 The 2nd-last and 3rd-last parameter are specified as 0.0. However by
 looking at one of Nvidia's programming samples do they use 0.5 for both.

 According to their documentation:

 --- NPP_Library_Image_Geometry.pdf ---
 7.5.3.28
 NppStatus nppiResizeSqrPixel_8u_C1R (const Npp8u ∗ pSrc, NppiSize
 oSrcSize, int
 nSrcStep, NppiRect oSrcROI, Npp8u ∗ pDst, int nDstStep, NppiRect oDstROI,
 double
 nXFactor, double nYFactor, double nXShift, double nYShift, int
 eInterpolation)
 1 channel 8-bit unsigned image resize.
 Parameters:
 pSrc Source-Image Pointer.
 nSrcStep Source-Image Line Step.
 oSrcSize Size in pixels of the source image.
 oSrcROI Region of interest in the source image.
 pDst Destination-Image Pointer.
 nDstStep Destination-Image Line Step.
 oDstROI Region of interest in the destination image.
 nXFactor Factor by which x dimension is changed.
 nYFactor Factor by which y dimension is changed.
 nXShift Source pixel shift in x-direction.
 nYShift Source pixel shift in y-direction.
 eInterpolation The type of eInterpolation to perform resampling.
 ---

 These two values describe a pixel shift. Further does it say:

 ---
 ResizeSqrPixel attempts to choose source pixels that would approximately
 represent the center of the des-
 tination pixels. It does so by using the following scaling formula to
 select source pixels for interpolation:
 nAdjustedXFactor = 1.0 / nXFactor;
 nAdjustedYFactor = 1.0 / nYFactor;
 nAdjustedXShift = nXShift * nAdjustedXFactor + ((1.0 - nAdjustedXFactor) *
 0.5);
 nAdjustedYShift = nYShift * nAdjustedYFactor + ((1.0 - nAdjustedYFactor) *
 0.5);
 nSrcX = nAdjustedXFactor * nDstX - nAdjustedXShift;
 nSrcY = nAdjustedYFactor * nDstY - nAdjustedYShift;
 ---

 For a destination coordinate of 10,10 and at a 33% size reduction would it
 pick 31,31 as source for a shift of 0.0.
 If the shift is 0.5 for both x and y then 10,10 of the destination falls
 onto source position 29.5,29.5 or rounded 30,30.
 And if the shift was 1.0 for both then 10,10 of the destination would fall
 onto 28,28.

 My guess here is that it should be 0.5 for both shift values just as it is
 done in the example and that the two values describe center of the square
 pixel in a range of 0.0 and 1.0.

 I don't know yet how this affects the algorithms, but a first test with
 the shifts changed to 0.5 looks promising. There are no more identical
 outputs. I'll do some more tests with real footage and see how this
 affects the output.

--
Ticket URL: <https://trac.ffmpeg.org/ticket/5822#comment:3>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list