title: VideoReader in OpenCV is deprecated. Is there any update from OpenCV or any substitution?
body: <p>I am doing video decoding to grab frame for some post video processing. I am using opencv Cuda so I really need video reader from opencv cuda. However, I realized: </p>
  
  <p>In NVIDIA Video Codec SDK 8.2.15, it says that </p>
  
  <blockquote>
    <p>Support for CUvideosource and the associated APIs including cuvidCreateVideoSource,cuvidCreateVideoSourceW, cuvidDestroyVideoSource, cuvidSetVideoSourceState, cuvidGetVideoSourceState, cuvidGetSourceVideoFormat, cuvidGetSourceAudioFormat will be removed from the decoder API in future SDK versions. Please note that the new decode sample applications in the SDK do not use these APIs, but use FFmpeg instead.</p>
  </blockquote>
  
  <p>But to use "createVideoReader" in OpenCV Cuda, we need to link "dynlink_nvcuvid.h" that contains</p>
  
  <pre><code>tcuvidCreateVideoSource               *cuvidCreateVideoSource;
  tcuvidCreateVideoSourceW              *cuvidCreateVideoSourceW;
  tcuvidDestroyVideoSource              *cuvidDestroyVideoSource;
  tcuvidSetVideoSourceState             *cuvidSetVideoSourceState;
  tcuvidGetVideoSourceState             *cuvidGetVideoSourceState;
  tcuvidGetSourceVideoFormat            *cuvidGetSourceVideoFormat;
  tcuvidGetSourceAudioFormat            *cuvidGetSourceAudioFormat;
  </code></pre>
  
  <p>Is there any update from opencv for video decoding? How do we use FFmpeg in OpenCV to replace "dynlink_nvcuvid.h"? I am trying to use NVIDIA video decoding but I am stuck at converting the video frame to GpuMat. </p>
  
  <p>I am using
  Ubuntu 18
  Cuda 9.2
  OpenCV 3.4.2</p>
  
  <p>For Cuda part, to decode I have used the following code:</p>
  
  <pre><code>FFmpegDemuxer demuxer(szInFilePath);
  NvDecoder dec(cuContext, demuxer.GetWidth(), demuxer.GetHeight(), true, FFmpeg2NvCodecId(demuxer.GetVideoCodec()));
  FramePresenterGL presenter(cuContext, demuxer.GetWidth(), demuxer.GetHeight());
  uint8_t *dpFrame = 0;
  int nPitch = 0;
  int nVideoBytes = 0, nFrameReturned = 0, nFrame = 0;
  uint8_t *pVideo = NULL;
  uint8_t **ppFrame;
  do {
      demuxer.Demux(&amp;pVideo, &amp;nVideoBytes);
      dec.Decode(pVideo, nVideoBytes, &amp;ppFrame, &amp;nFrameReturned);
      if (!nFrame &amp;&amp; nFrameReturned)
          LOG(INFO) &lt;&lt; dec.GetVideoInfo();
  
      for (int i = 0; i &lt; nFrameReturned; i++) {
          presenter.GetDeviceFrameBuffer(&amp;dpFrame, &amp;nPitch);
          if (dec.GetBitDepth() == 8)
              Nv12ToBgra32((uint8_t *)ppFrame[i], dec.GetWidth(), (uint8_t *)dpFrame, nPitch, dec.GetWidth(), dec.GetHeight());
          else
              P016ToBgra32((uint8_t *)ppFrame[i], 2 * dec.GetWidth(), (uint8_t *)dpFrame, nPitch, dec.GetWidth(), dec.GetHeight());
  
          cv::Size sz(dec.GetWidth(),dec.GetHeight());
          cv::Mat mat1(sz,CV_8UC3, ppFrame);
          cv::imshow ("test", mat1);
          cv::waitKey(0);
      }
      nFrame += nFrameReturned;
  } while (nVideoBytes);
  </code></pre>
  
  <p>Anyone has experience on using opencv cuda with actual video codec api? How do I put the video frame into GpuMat? </p>
  
  <p>Update:</p>
  
  <p>I have tried to convert uint8_t but the image is displayed wrongly as shown below: 
  <a href="https://i.stack.imgur.com/4MQNY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4MQNY.png" alt="enter image description here"></a></p>
  
  <p>The code i used is updated above. What should I change to display the image correctly? I tried <a href="https://stackoverflow.com/a/51520728/7939409">https://stackoverflow.com/a/51520728/7939409</a> but the downloadedLeft is empty for the code below. </p>
  
  <pre><code>cv::Mat downloadedLeft;
  cv::cuda::GpuMat gpuLeft;
  
  cudaMalloc((void **)&amp;ppFrame, gpuLeft.rows*gpuLeft.step);
  cudaMemcpyAsync(ppFrame, gpuLeft.ptr&lt;uint8_t&gt;(), gpuLeft.rows*gpuLeft.step, cudaMemcpyDeviceToDevice);
  
  gpuLeft.download(downloadedLeft);
  cv::imshow ("test", downloadedLeft);
  cv::waitKey(1);
  </code></pre>