<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You first need to create hardware device context, this example will get you started <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c" target="_blank">https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c</a> . After this you need to create hardware frames context which you will use to pass frames inside of the GPU. For decoder get_hw_format should look something like this</blockquote><div><br></div><div>Thank you! This was extremely helpful. I have two follow-up clarifications, if you wouldn't mind: </div><div><br></div><div>1. Would you mind elaborating on how to create a hardware frames context? I found this example on how to do it with VAAPI. Should I just copy the set_hwframe_ctx() function? What should I change the pix_fmt to for nvenc? 2. </div><div><br></div><div>I noticed in the <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c">example you sent me</a> they call av_hwdevice_find_type_by_name(argv[1]). Do I need to do this as well/should I replace argv[1] by "cuda" since I want to do nvenc? </div><div><br></div><div>Thank you very much!!</div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Philippe </div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 18, 2020 at 5:30 AM Strahinja Radman <<a href="mailto:dr.strashni@gmail.com">dr.strashni@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">> Thanks! I read through the nvidia docs. It seems that I need to pass in the "hwaccel: cuvid" option in order to keep the raw frame in GPU memory. Do you have any idea how to do this in Libav (C)? I tried following <a href="https://stackoverflow.com/questions/5985273/using-ffmpeg-hwaccel-from-c?fbclid=IwAR0bI8NuMoc29Kw_tCwGQVogXAsG4liAqYSw6hftOZ2n8H5jn-JIV6RVdko" target="_blank">this Stackoverflow post,</a> but av_hwaccel_next() kept > returning NULL for a pixel format of AV_PIX_FMT_YUV420P and a codec of "h264_nvenc." I also see that av_hwaccel_next is deprecated. Do you have any suggestions? <br></div></div><div><br></div><div>You first need to create hardware device context, this example will get you started <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c" target="_blank">https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c</a> . After this you need to create hardware frames context which you will use to pass frames inside of the GPU. For decoder get_hw_format should look something like this</div><div><br></div><div>enum AVPixelFormat get_hw_format(AVCodecContext* ctx, const enum AVPixelFormat* pix_fmts)<br>{<br> const enum AVPixelFormat* p;<br> for (p = pix_fmts; *p != -1; p++) {<br> if (*p == this->hw_pix_fmt)<br> break;<br> }<br><br></div><div> ctx->hw_frames_ctx = av_buffer_ref(this->hw_frames_ctx); //This is the important line</div><div> if (!p) return AV_PIX_FMT_NONE;<br> return *p;<br>}<br></div><div><br></div><div>While opening the encoder you simply reference the same hw_frames_ctx</div><div><br></div><div> enc_ctx->hw_frames_ctx = av_buffer_ref(hw_frames_ctx);<br></div><div><br></div><div>And that should be it.</div>-- <br><div dir="ltr"><br>Regards<br>Strahinja Radman</div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote></div>