[Libav-user] Fwd: 971108 - ffmpeg doesn't use GPU

hamidi hamidi at gmail.com
Wed Jan 30 15:58:18 EET 2019

I got the latest version binaries of ffmpeg from here
<https://ffmpeg.zeranoe.com/builds/>. When I examine CPU and GPU usages
when I play a video by its ffplay, I see that GPU is used during play. Not
much using of CPU also indicates it. But when I get the latest version
sources from the original site, I can't use GPU. To clarify, I include a
player test program I wrote until now. When I uncomment the line which
includes avcodec_find_decoder_by_name("h264_cuvid"), I get error -1. The
error happens in avcodec_open2 with the description of Operation not

CString format(const char *fmt, ...)
    va_list ap;
    va_start(ap, fmt);
    char buf[512];
    vsnprintf(buf, sizeof(buf), fmt, ap);
    return buf;

int CplayerDlg::play()
    FILE *fp = fopen("video_files/1010.brf", "rb");
    if (!fp)
        AfxMessageBox("can't open video file");
        return -1;
    RecordFrame frame;
    RecordHeader hdr;
    fread(&frame, sizeof(frame), 1, fp);
    if (frame.frameType != FRAME_TYPE_HEADER)
        AfxMessageBox("record file doesn't begin with header");
        return -1;
    fread(&hdr, sizeof(hdr), 1, fp);
    GetDlgItem(IDC_DIM)->SetWindowText(format("%dx%d", hdr.width,
    GetDlgItem(IDC_CODEC_ID)->SetWindowText(format("%d", hdr.codecId));
hdr.timebaseNum, hdr.timebaseDen));
    AVCodec *pCodec;

#if 0
#define CHECK(decoder)\
    pCodec = avcodec_find_decoder_by_name(#decoder);\
    AfxMessageBox(pCodec ? #decoder " found" : "can't find " #decoder);


#undef CHECK

    pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
    //pCodec = avcodec_find_decoder_by_name("h264_cuvid");
    if (!pCodec)
        AfxMessageBox("can't find h264 decoder");
        return -1;

    AVCodecContext *pCodecContext = avcodec_alloc_context3(pCodec);
    if (!pCodecContext)
        AfxMessageBox("can't allocate codec context");
        return -1;

#if 0
// enumerating available codecs

    AVCodec *current_codec = av_codec_next(NULL);
    while (current_codec != NULL)
        TRACE("%s\n", current_codec->name);
        current_codec = av_codec_next(current_codec);

    int err = avcodec_open2(pCodecContext, pCodec, NULL);
    if (err != 0)
        char buf[AV_ERROR_MAX_STRING_SIZE];
        av_make_error_string(buf, AV_ERROR_MAX_STRING_SIZE, err);
        char buf2[AV_ERROR_MAX_STRING_SIZE];
        sprintf(buf2, "%d (%x): %s\n", err, err, buf);
        return -1;
    AfxMessageBox("operation completed successfully");
    return 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190130/f37e9277/attachment.html>

More information about the Libav-user mailing list