Can';在使用ffmpeg库读取视频文件时,无法检测坏/损坏的视频帧

Can';在使用ffmpeg库读取视频文件时,无法检测坏/损坏的视频帧,c,video,ffmpeg,libavcodec,libavformat,C,Video,Ffmpeg,Libavcodec,Libavformat,我最近开始使用ffmpeg C库来分析文件中视频帧的完整性。我(像很多人一样)开始研究,然后我用他们做了我自己的研究。但我有一个问题:在读取带有损坏数据的视频文件时,我无法检测到损坏的数据包或帧。例如,下面有一段代码(它确实有效,但我并不太担心释放资源): 但是我无法从我的代码中检测到所有失败的帧:无论是av\u read\u frame还是avcodec\u decode\u video2函数都不会返回错误代码!我做错了什么?是不是在调用这些函数之前就得到了这些输出?@EugeneSh。不,我

我最近开始使用ffmpeg C库来分析文件中视频帧的完整性。我(像很多人一样)开始研究,然后我用他们做了我自己的研究。但我有一个问题:在读取带有损坏数据的视频文件时,我无法检测到损坏的数据包或帧。例如,下面有一段代码(它确实有效,但我并不太担心释放资源):


但是我无法从我的代码中检测到所有失败的帧:无论是av\u read\u frame还是avcodec\u decode\u video2函数都不会返回错误代码!我做错了什么?

是不是在调用这些函数之前就得到了这些输出?@EugeneSh。不,我已经跟踪了代码,在调用这些函数时,错误被输出到错误标准流中,特别是avcodec\U decode\U video2,偶尔还有av\U read\U frame。但它们都不会返回负值,这表明错误。。。
extern "C" {
#include <libavformat\avformat.h>
#include <libavcodec\avcodec.h>
#include <libavutil\frame.h>
}
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avutil.lib")

int main(int argc, char *argv[]) {

av_register_all();

AVFormatContext* pFormatContext = 0;

if (avformat_open_input(&pFormatContext, "errorVideo.mpg", NULL, NULL) < 0) {
    //Error opening file
    exit(1);
    }

if (avformat_find_stream_info(pFormatContext, NULL) < 0) {
    //Error finding stream...
    exit(1);
    }

//Finding first video stream:
unsigned int iStream;
for (iStream = 0; iStream < pFormatContext->nb_streams && pFormatContext->streams[iStream]->codec->codec_type != AVMEDIA_TYPE_VIDEO;    iStream++);
if (iStream >= pFormatContext->nb_streams) {
    //Error finding video stream.
    exit(1);
    }

AVCodecContext* pOrigCodecCtx = pFormatContext->streams[iStream]->codec;
AVCodec* pCodec = avcodec_find_decoder(pOrigCodecCtx->codec_id);
if (!pCodec) {
    //Codec no supported
    exit(1);
    }

AVCodecContext* pNewCodecCtx = avcodec_alloc_context3(pCodec);
if (!pNewCodecCtx || avcodec_copy_context(pNewCodecCtx, pOrigCodecCtx) != 0) {
    //Error allocating or copying context
    exit(1);
    }

if (avcodec_open2(pNewCodecCtx, pCodec, NULL) < 0) {
    //Error initializing codec
    exit(1);
    }

AVPacket packet;
int gotFrame;
while (av_read_frame(pFormatContext, &packet) >= 0) {

    if (packet.stream_index == iStream) {
        AVFrame* pFrame = av_frame_alloc();

        if (avcodec_decode_video2(pNewCodecCtx, pFrame, &gotFrame, &packet) < 0) {
            //Error decoding frame.
            exit(1);
            }

        if (gotFrame) {
            //do something with frame...
            }

        av_frame_unref(pFrame);
        }

    av_free_packet(&packet);
    }
if (pFormatContext->pb->error != 0) {
    //Error reading packet
    exit(1);
    }
}
[mpeg2video @ 0000000000B68A40] invalid cbp -1 at 19 6
[mpeg2video @ 0000000000B68A40] Warning MVs not available
[mpeg2video @ 0000000000B68A40] concealing 45 DC, 45 AC, 45 MV errors in P frame
[mpeg2video @ 0000000000B68A40] invalid mb type in P Frame at 21 16
[mpeg2video @ 0000000000B68A40] Warning MVs not available
[mpeg2video @ 0000000000B68A40] concealing 45 DC, 45 AC, 45 MV errors in P frame
[mpeg2video @ 0000000000B68A40] slice mismatch
[mpeg2video @ 0000000000B68A40] 00 motion_type at 25 8
[mpeg2video @ 0000000000B68A40] Warning MVs not available
[mpeg2video @ 0000000000B68A40] concealing 90 DC, 90 AC, 90 MV errors in B frame