FFmpeg4.0笔记:采集桌面

Github

https://github.com/gongluck/FFmpeg4.0-study/tree/master/Cff

// 采集桌面
void test_desktop()
{
    bool ret = false;
    std::string err;
    CDemux demux;
    CDecode decode;
    
    ret = demux.device_register_all(err);
    TESTCHECKRET(ret);
    ret = demux.set_input_format("gdigrab", err); //采集桌面
    TESTCHECKRET(ret);
    ret = demux.set_dic_opt("framerate", "15", err);
    TESTCHECKRET(ret);
    ret = demux.set_demux_callback(DemuxDesktopCB, &decode, err);
    TESTCHECKRET(ret);
    ret = demux.set_demux_status_callback(DemuxStatusCB, &demux, err);
    TESTCHECKRET(ret);
    ret = demux.set_input("desktop", err);
    TESTCHECKRET(ret);
    ret = demux.openinput(err);
    TESTCHECKRET(ret);

    g_vindex = demux.get_steam_index(AVMEDIA_TYPE_VIDEO, err);
    std::cout << err << std::endl;
    g_aindex = demux.get_steam_index(AVMEDIA_TYPE_AUDIO, err);
    std::cout << err << std::endl;

    ret = decode.set_dec_callback(DecVideoFrameCB, &decode, err);
    TESTCHECKRET(ret);
    ret = decode.copy_param(demux.get_steam_par(g_vindex, err), err);
    TESTCHECKRET(ret);
    ret = decode.codec_open(err);
    TESTCHECKRET(ret);

    ret = demux.begindemux(err);
    TESTCHECKRET(ret);

    std::cout << "input to stop demuxing." << std::endl;
    std::cin.get();

    ret = demux.stopdemux(err);
    TESTCHECKRET(ret);
}

你可能感兴趣的:(FFmpeg4.0笔记:采集桌面)