断言desc在src / libswscale / swscale_internal.h中失败:668

时间:2018-03-01 13:20:24

标签: c++ ffmpeg

我遇到了一个非常奇怪的问题。我使用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个文件

请告诉我是否需要提供其他信息以获取帮助。

1 个答案:

答案 0 :(得分:0)

FFmpeg的最新版本中,断言告知outCodecContext->pix_fmt未正确设置。而且avpicture_fill也已弃用,请改用av_image_fill_arrays。如果您使用旧版本的FFmpeg,则可以忽略弃用。但我建议使用最新的FFmpeg。希望有所帮助。