I need to implement screen recording in my software but I have a problem with getting gdigrab in windows 10. This code return
"can't find input device." (av_find_input_format("gdigrab") return NULL).
If I try to record desktop by ffmpeg.exe using ffmpeg -f gdigrab -i desktop out.avi
, the desktop is recording correctly.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
extern "C"
{
#include "ffmpeg-x86-4.4/include/libavcodec/avcodec.h"
#include "ffmpeg-x86-4.4/include/libavformat/avformat.h"
#include "ffmpeg-x86-4.4/include/libswscale/swscale.h"
#include "ffmpeg-x86-4.4/include/libavdevice/avdevice.h"
#include "ffmpeg-x86-4.4/include/libavutil/imgutils.h"
#include "ffmpeg-x86-4.4/include/libavutil/dict.h"
#include "SDL2/include/SDL.h"
}
#define OUTPUT_YUV420P 1
#define OUTPUT_H264 1
int main(int argc, char* argv[])
{
AVFormatContext* pFormatCtx;
AVStream* videoStream;
AVCodecContext* pCodecCtx;
AVCodec* pCodec;
AVFrame* pFrame, * pFrameYUV;
AVPacket* pPacket;
SwsContext* pImgConvertCtx;
int videoIndex = -1;
unsigned int i = 0;
SDL_Window* screen;
SDL_Renderer* sdlRenderer;
SDL_Texture* sdlTexture;
SDL_Rect sdlRect;
int screen_w = 0;
int screen_h = 0;
printf("Starting...\n");
//AVInputFormat* p = NULL;
//register device
avdevice_register_all();
//use gdigrab
AVInputFormat* ifmt = av_find_input_format("gdigrab");
if (!ifmt)
{
printf("can't find input device.\n");
return -1;
}
AVDictionary* options = NULL;
if (avformat_open_input(&pFormatCtx, "desktop", ifmt, &options) != 0)
{
printf("can't open input stream.\n");
return -1;
}
if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
{
printf("can't find stream information.\n");
return -1;
}