在 Visual Studio C++ 上使用 ffmpeg 库对视频进行编码时出现断言错误

Assertion error when encoding video using ffmpeg library on visual studio c++

本文关键字:编码 错误 断言 视频 C++ Studio Visual ffmpeg      更新时间:2023-10-16

我有一个项目,我需要从rtsp链接接收数据,解码,调整视频大小,对其进行编码并保存到.mp4文件中。

  • I 使用 ffmpeg 来自 http://ffmpeg.zeranoe.com/builds/
  • 我正在使用Visual Studio 2010,在Windows 7和Windows 8上运行。
  • 这是我正在使用的rtsp链接:rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov
  • 我解码并保存到 ppm 文件还可以。但编码不是。
  • 我按照那里的教程:http://dranger.com/ffmpeg/tutorial01.html

这是我的代码:

AVPacket destPacket;
av_init_packet(&destPacket);
destPacket.data = NULL;
destPacket.size = 0;
while(av_read_frame(i_format_context, &packet)>=0) {
    if(packet.stream_index==video_stream_index) {
        int rest = avcodec_decode_video2(copyInputCodec, pFrame, &frameFinished, &packet);
        if(frameFinished) {
            av_init_packet(&destPacket);
            destPacket.data = NULL;
            destPacket.size = 0;
            av_free_packet(&destPacket);
            //deocde here
            int ret_scale = sws_scale(sws_ctx,pFrame->data,pFrame->linesize,0,copyInputCodec->height,encodeFrame->data,encodeFrame->linesize);
            encodeFrame->pts=i;
            int ret_enc = avcodec_encode_video2(copyOutputCodec,&destPacket,encodeFrame,&encodeFinishsed);//<--- Problem here.
            getchar();
        }
    }
}

这是输出错误

[swscaler @ 00607880] 警告:数据未对齐!这可能导致 Speedlo SS Assertion avctx->codec->encode2 failed at/home/kyle/software/ffmpeg/source/ffmp eg-git/libavcodec/utils.c:2134

我尝试运行许多示例代码来编码视频,结果是一样的。

感谢您的帮助。

PS:对不起我的英语水平。

这里实际上有两个问题:

  • 警告:根据 https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/swscale.c(第 413-424 行),您的图片尺寸应可除以 16
  • 断言:https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/utils.c 行 2134 - 看起来您尚未配置编码器