小编moh*_*ohM的帖子

使用FFMPEG将屏幕截图编码为视频

我正试图从屏幕上获取像素,并使用ffmpeg将屏幕截图编码为视频.我见过几个例子,但他们要么假设你已经有像素数据,要么使用图像文件输入.好像我是否使用sws_scale()(包含在我见过的示例中),或者我是否对HBITMAP或RGBQUAD*进行类型转换,它告诉我图像src数据不好并且编码为空白图像而不是截图.这里有什么我想念的吗?

AVCodec* codec;
AVCodecContext* c = NULL;
AVFrame* inpic;
uint8_t* outbuf, *picture_buf;
int i, out_size, size, outbuf_size;
HBITMAP hBmp;
//int x,y;

avcodec_register_all();

printf("Video encoding\n");

// Find the mpeg1 video encoder
codec = avcodec_find_encoder(CODEC_ID_H264);
if (!codec) {
    fprintf(stderr, "Codec not found\n");
    exit(1);
}
else printf("H264 codec found\n");

c = avcodec_alloc_context3(codec);
inpic = avcodec_alloc_frame();

c->bit_rate = 400000;
c->width = screenWidth;                                     // resolution must be a multiple of two
c->height = screenHeight;
c->time_base.num = 1;
c->time_base.den = 25;
c->gop_size = 10;                                           // emit …
Run Code Online (Sandbox Code Playgroud)

c++ encoding ffmpeg video-streaming

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

encoding ×1

ffmpeg ×1

video-streaming ×1