[Libav-user] Nvenc_H264 very slow compared to Libx264
Philippe Noël
philippe_noel at college.harvard.edu
Sat Jan 18 21:41:07 EET 2020
>
> You first need to create hardware device context, this example will get
> you started
> https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c .
> 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
Thank you! This was extremely helpful. I have two follow-up clarifications,
if you wouldn't mind:
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.
I noticed in the example you sent me
<https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c>
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?
Thank you very much!!
Philippe
On Sat, Jan 18, 2020 at 5:30 AM Strahinja Radman <dr.strashni at gmail.com>
wrote:
>
>
> > 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 this
> Stackoverflow post,
> <https://stackoverflow.com/questions/5985273/using-ffmpeg-hwaccel-from-c?fbclid=IwAR0bI8NuMoc29Kw_tCwGQVogXAsG4liAqYSw6hftOZ2n8H5jn-JIV6RVdko>
> 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?
>
> You first need to create hardware device context, this example will get
> you started
> https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c .
> 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
>
> enum AVPixelFormat get_hw_format(AVCodecContext* ctx, const enum
> AVPixelFormat* pix_fmts)
> {
> const enum AVPixelFormat* p;
> for (p = pix_fmts; *p != -1; p++) {
> if (*p == this->hw_pix_fmt)
> break;
> }
>
> ctx->hw_frames_ctx = av_buffer_ref(this->hw_frames_ctx); //This is
> the important line
> if (!p) return AV_PIX_FMT_NONE;
> return *p;
> }
>
> While opening the encoder you simply reference the same hw_frames_ctx
>
> enc_ctx->hw_frames_ctx = av_buffer_ref(hw_frames_ctx);
>
> And that should be it.
> --
>
> Regards
> Strahinja Radman
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200118/45becf05/attachment.html>
More information about the Libav-user
mailing list