[Libav-user] Hardware accell encoding

Charles linux2 at orion15.org
Sat Sep 10 00:56:03 EEST 2016


On 09/09/2016 04:17 PM, Leandro Raffo wrote:
> 2016-09-09 15:59 GMT-03:00 Charles <linux2 at orion15.org>:
>>>
>>> I'm trying to encode AVFrames using the GPU from C code, so I was
>>> trying to see how ffmpeg's source code was doing it and asking for a
>>> pointer on it (or its location lol). I've already encoded directly
>>> with ffmpeg (to see its working) but I need to encode random AVFrames
>>> not an entire video. Also giving a yuv420 video to the Nvidia ENC
>>> samples produces a corrupted video.
>>
>>
>> nvenc is going to encode yuv video into h264 stream, I am not sure the
>> output format is what you want.
>> To get "random" frames encoded, you will have to do something like GOP=1 and
>> mark all frames key frames somehow.
>> Sounds like you are trying to create a slide show from random frames in a
>> video stream?
>>
>> Pure theory YMMV...
>>
>> If you want to use nvenc directly you need to transform AVFrame to
>> EncodeFrameConfig
>> See
>> NVENCSTATUS CNvEncoder::EncodeFrame(EncodeFrameConfig *pEncodeFrame, bool
>> bFlush, uint32_t width, uint32_t height)
>>
>> Should be able to create your own convertAvFrametoEncoded
>> REF: convertYUVpitchtoNV12 convertYUVpitchtoYUV444
>>
>> Setting ecoded->yuv[0], encoded->yuv[1], encoded->yuv[2], dstwidth,
>> dstheight from
>> av_frame->data[0] av_frame->data[1] av_frame->data[2], av_frame->width,
>> av_frame->height, av_frame->linesize
>>
>> but I think the output will not be a "VIDEO FRAME"
>>
>> Thanks
>> cco
>
> I have RGB images of a video that I was converting to AVFrames and I
> wanted to encode in real time without incurring in heavy CPU usage.
> Basically offload the hard part to the GPU. I thought ffmpeg api would
> expose some kind of  functionality for this (I've seen code doing
> decoding with VDPAU). I'll keep checking the nvidia examples( I was
> avoiding them mainly because of the amount of boilerplate that I don't
> have a clue what is doing and because it encoded garbage.) and see If
> I can do it with your pointers. Thanks!


If you use ffmpeg and specify the h264_nvenc it will use almost no cpu
Here is a mostly working example, it runs as a pthread just push frames (RGB)
https://gist.github.com/LinuxwitChdoCtOr/1fbfc44443de8f0fcf6a742f5562376d
You will need to specify which h264 enoder to use if you have more than one

Just FYI it is still a lot of code

Thanks
cco







More information about the Libav-user mailing list