我遇到了一个非常奇怪的问题。我正在使用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文件
如果我需要提供其他信息以获得帮助,请告诉我。
发布于 2018-03-05 15:11:31
在FFmpeg最新版本中,断言提示outCodecContext->pix_fmt未正确设置。而且也不推荐使用avpicture_fill,请改用av_image_fill_arrays。如果您使用的是旧版本的FFmpeg,则可以忽略弃用。但我建议使用最新的FFmpeg。希望这能有所帮助。
https://stackoverflow.com/questions/49050600
复制相似问题