[FFmpeg-devel] Hardware Encode H264

ALEXANDRE MORO web at vola.fr
Tue Feb 28 10:44:05 EET 2017

Hello everyone,
I'm trying both encode/decode h264 stream for live streaming.
I really don't know how to use the hardware encoder cuda nor nvenc nor dxva2 and i do not find any documentation on that.

1) I already compiled ffmpeg '2017-02-28 snapshot) with
--enable-cuda \
--enable-cuvid \
--enable-nvenc \
--enable-dxva2 \

2) How to use it in the code
My code (i removed every check) :
AnsiString url = "rtmp://srv-streaming.tv:1935/streaming/";
avformat_alloc_output_context2(&oc, NULL, "flv", url.c_str());

fmt = oc->oformat;
fmt->video_codec = AV_CODEC_ID_H264;
video_codec = avcodec_find_encoder(fmt->video_codec);
st = avformat_new_stream(oc, video_codec);
st->codec = avcodec_alloc_context3(video_codec);

c->hwaccel = ff_find_hwaccel(c->codec_id, c->pix_fmt); // < Here, i set the hwaccel but it do not change anything.

ret = avcodec_open2(c, video_codec, &opts);
ret = avio_open2(&oc->pb, url.c_str(), AVIO_FLAG_WRITE, NULL, NULL);

// And here the funciton :
AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
    AVHWAccel *hwaccel=NULL;
    while((hwaccel = av_hwaccel_next(hwaccel))){
        if (   hwaccel->id      == codec_id
            && hwaccel->pix_fmt == AV_PIX_FMT_CUDA)
            return hwaccel;
        if (   hwaccel->id      == codec_id
            && hwaccel->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
            return hwaccel;
    return NULL;
But with or without the c->hwaccel the GPU is not used anymore !

Thank you very much for your help,
Best regards,

More information about the ffmpeg-devel mailing list