h4tr3d / avcpp

C++ wrapper for FFmpeg
Other
448 stars 81 forks source link

Support for gpu-accelerated decoding? #99

Open morphogencc opened 2 years ago

morphogencc commented 2 years ago

Does avcpp support gpu-accelerated decoding/encoding via nvenc?

teodly commented 2 years ago

I've tested hardware decoding with h264_cuvid. It works. You need to create codec context using something like this:

av::VideoDecoderContext vdec(stream, av::findDecodingCodec("h264_cuvid"))

tehkillerbee commented 2 years ago

It works with Nvidia GPU decoding, if you build ffmpeg with support for it. I have not tested with encoding, however. https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/ https://trac.ffmpeg.org/wiki/HWAccelIntro

teodly commented 11 months ago

Hardware-accelerated encoding also works (tested with nvenc). You may need to set low-level libavcodec's fields: hw_device_ctx and hw_frames_ctx using av::VideoDecoderContext::raw() accessor.

Transcoding without raw frames leaving GPU's internal RAM (VRAM) is also possible if hw_frames_ctx->format is set to appropriate hardware "pixel format", e.g. AV_PIX_FMT_CUDA. It makes transcoding less PCIe-bandwidth-intensive. I can provide more details if anyone is interested in it.

h4tr3d commented 11 months ago

@teowoz , thanks for answer! I am so happy if you send a PR with minimal sample for nvenc usage. And will thinking about proper wrapping with high level code...