我遇到了一个非常奇怪的问题。我使用FFMPEG
gdigrab
设备捕获桌面。这就是我的工作
...
options = NULL;
av_dict_set(&options, "framerate", "30", NULL);
av_dict_set(&options, "offset_x", QString::number(geometry.x() + 10).toLatin1().data(), NULL);
av_dict_set(&options, "offset_y", QString::number(geometry.y() + 10).toLatin1().data(), NULL);
av_dict_set(&options, "video_size", QString(QString::number(geometry.width() - 20) + "x" + QString::number(geometry.height() - 20)).toLatin1().data(), NULL);
av_dict_set(&options, "show_region", "1", NULL);
AVInputFormat* inputFormat = av_find_input_format("gdigrab");
avformat_open_input(&inputFormatContext, "desktop", inputFormat, &options);
...
AVPacket* packet = (AVPacket*)av_malloc(sizeof(AVPacket));
av_init_packet(packet);
AVFrame* frame = av_frame_alloc();
AVFrame* outFrame = av_frame_alloc();
int nbytes = av_image_get_buffer_size(outCodecContext->pix_fmt,
outCodecContext->width,
outCodecContext->height,
32);
uint8_t* outBuffer = (uint8_t*)av_malloc(nbytes);
avpicture_fill((AVPicture*)outFrame, outBuffer,
AV_PIX_FMT_YUV420P,
outCodecContext->width, outCodecContext->height);
SwsContext* swsContext = sws_getContext(inputCodecContext->width,
inputCodecContext->height,
inputCodecContext->pix_fmt,
outCodecContext->width,
outCodecContext->height,
outCodecContext->pix_fmt,
SWS_BICUBIC, NULL, NULL, NULL);
...
就我所知,应用程序在sws_getContext(...
它与Windows错误消息崩溃
this application has requested the runtime to terminate it in an unusual way
所以我甚至无法调试问题所在。
控制台中还有一条消息
Assertion desc failed at src/libswscale/swscale_internal.h:668
奇怪的是 - 我甚至没有swscale_internal.h
个文件
请告诉我是否需要提供其他信息以获取帮助。
答案 0 :(得分:0)
在FFmpeg
的最新版本中,断言告知outCodecContext->pix_fmt
未正确设置。而且avpicture_fill
也已弃用,请改用av_image_fill_arrays
。如果您使用旧版本的FFmpeg,则可以忽略弃用。但我建议使用最新的FFmpeg。希望有所帮助。