C++ 如何修复这些错误?

C++ 如何修复这些错误?,c++,ffmpeg,C++,Ffmpeg,我正在尝试创建FFmpeg客户端流媒体,但出现了一些错误 错误C4996“av_寄存器_all”:已声明不推荐使用 错误C4996“av_免费_数据包”:已声明不推荐使用 错误C4996“AVStream::codec”:已声明不推荐使用 错误C4996“avcodec\u decode\u video2”:已声明已弃用 错误C4996“avcodec_copy_context”:已声明已弃用 int size=avpicture\u get\u size(AV\u PIX\u FMT\u YU

我正在尝试创建FFmpeg客户端流媒体,但出现了一些错误

错误C4996“av_寄存器_all”:已声明不推荐使用
错误C4996“av_免费_数据包”:已声明不推荐使用
错误C4996“AVStream::codec”:已声明不推荐使用
错误C4996“avcodec\u decode\u video2”:已声明已弃用
错误C4996“avcodec_copy_context”:已声明已弃用

int size=avpicture\u get\u size(AV\u PIX\u FMT\u YUV420P,
ccontext>宽度,ccontext>高度);
图片大小=(图片大小);
AVFrame*pic=avcodec_alloc_frame();
AVFrame*picrgb=avcodec_alloc_frame();
int size=avpicture\u get\u size(AV\u PIX\u FMT\u RGB24,ccontext->width,
c上下文->高度);
uint8_t*图片_buf2=(uint8_t*)(av_malloc(尺寸2));
avpicture_fill((avpicture*)pic,picture_buf,AV_PIX_FMT_YUV420P,
ccontext->宽度,ccontext->高度);
avpicture_fill((avpicture*)picrgb、picture_buf2、AV_PIX_FMT_RGB24、,
ccontext->宽度,ccontext->高度);
而(av_读取_帧(上下文和数据包)>=0&&cnt<1000)
{//读取100帧
std::cout sample\u aspect\u ratio=上下文-
>流[视频流索引]->编解码器->采样宽高比;
}
整数检查=0;
packet.stream_index=stream->id;

首先,这些应该是警告,而不是错误。如果它们是错误,则编译器设置设置太严格

av\u register\u all
-不再使用,只需删除此行即可

av\u免费包
->
av\u免费包

AVStream::codec
->
AVStream::codepar

avcodec\u decode\u video2
->将其替换为
avcodec\u发送\u数据包
avcodec\u接收\u帧

最后:
avcodec\u copy\u上下文
->来自文档:

此函数的语义定义不正确,不应 被使用。如果需要从一个编解码器上下文传输流参数 对于另一个实例,请使用中间AVCodecParameters实例和 avcodec_参数_from_context()/avcodec_参数_to_context() 功能


你试过查那些错误的意思吗?您是否阅读了正在使用的ffmpeg版本的文档?GNOSE应该是警告,而不是错误。编译时禁用警告作为错误标志。
  int size = avpicture_get_size(AV_PIX_FMT_YUV420P, 
  ccontext>width,ccontext->height);
  uint8_t* picture_buf = (uint8_t*)(av_malloc(size));
  AVFrame* pic = avcodec_alloc_frame();
  AVFrame* picrgb = avcodec_alloc_frame();
  int size2 = avpicture_get_size(AV_PIX_FMT_RGB24, ccontext->width, 
  ccontext->height);
  uint8_t* picture_buf2 = (uint8_t*)(av_malloc(size2));
  avpicture_fill((AVPicture *)pic, picture_buf, AV_PIX_FMT_YUV420P, 
  ccontext->width, ccontext->height);
  avpicture_fill((AVPicture *)picrgb, picture_buf2,AV_PIX_FMT_RGB24, 
  ccontext->width, ccontext->height);

  while (av_read_frame(context, &packet) >= 0 && cnt < 1000)
 {//read 100 frames

    std::cout << "1 Frame: " << cnt << std::endl;
    if (packet.stream_index == video_stream_index) 
    {//packet is video
        std::cout << "2 Is Video" << std::endl;
        if (stream == NULL)
        {//create stream in file
            std::cout << "3 create stream" << std::endl;
            stream = avformat_new_stream(oc, context- 
            >streams[video_stream_index]->codec->codec);
            avcodec_copy_context(stream->codec, context- 
            >streams[video_stream_index]->codec);
            stream->sample_aspect_ratio = context- 
            >streams[video_stream_index]->codec->sample_aspect_ratio;
        }
        int check = 0;
        packet.stream_index = stream->id;
        std::cout << "4 decoding" << std::endl;
        int result = avcodec_decode_video2(ccontext, pic,          
        &check,&packet);
        std::cout << "Bytes decoded " << result << " check " << check << 
        std::endl;
        if (cnt > 100)//cnt < 0)
        {
            sws_scale(img_convert_ctx, pic->data, pic->linesize, 0, 
            ccontext->height, picrgb->data, picrgb->linesize);
            std::stringstream name;
            name << "test" << cnt << ".ppm";
            myfile.open(name.str());
            myfile << "P3 " << ccontext->width << " " << ccontext->height 
                  << " 255\n";
            for (int y = 0; y < ccontext->height; y++)
            {
                for (int x = 0; x < ccontext->width * 3; x++)
                    myfile << (int)(picrgb-> 
                data[0] + y * picrgb->linesize[0])[x] << " ";
            }
            myfile.close();
        }