<div dir="auto">Not sure if this is the right place, but Nvidia Video SDK page contains wonderful examples with runnable source code which shows you how to decode and encode. That's not FFMPEG, but from what you're trying to do it sounds like you can do most of it with Nvidia NVENC and NVDEC and just use AV lib to muxe encoded data into final output.  </div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 23, 2018, 22:23 joep <<a href="mailto:joep@groovytunes.nl">joep@groovytunes.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>

  
  
  

<div>

<div class="m_-3710555433424293372bodyclass">
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">Hello,</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><br></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">I am trying to create a program that does the following:<br></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">1. decode frames with cuvid</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">2. run CUDA kernels on the decoded frames</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">3. encode result with nvenc</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><br></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">In order to do step 2, I need the CUDA kernels to access the decoded frame which should be stored in the GPU memory.</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">For this I think I need to provide the CUDA CUcontext to ffmpeg and give the pointer to the decoded frame to the kernel.</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">I could not find any documentation about this topic.<br></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">In the ffmpeg docs I see the AVCodecContext has hw_device_ctx which is a </span><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif">AVHWDeviceContext.</span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">AVHWDeviceContext has a hwctx field which can be a AVCUDADeviceContext.</span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">AVCUDADeviceContext has a cuda_ctx field which is a CUcontext.</span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px"><br></span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">So I think I need to create a AVHWDeviceContext and set it on the </span></span><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">AVCodecContext before calling avcodec_open2.</span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">Are my assumptions right?</span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">And how can I create a AVHWDeviceContext with the correct hwctx?</span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px"><br></span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">Thanks,</span></span></p>
<p style="padding:0;margin:0"><span style="font-size:10pt;font-family:tahoma,arial,helvetica,sans-serif"><span style="font-family:tahoma,arial,helvetica,sans-serif;font-size:13.3333px">Joep</span></span></p>
</div>

</div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank" rel="noreferrer">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer noreferrer" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</blockquote></div>