如何修复 FFMpeg 已声明弃用的问题?

问题描述 投票:0回答:1

我正在尝试编写 FFmpeg 客户端流,这些是发生一些错误

错误 C4996 'av_register_all':已声明已弃用
错误 C4996“av_free_packet”:已声明已弃用
错误 C4996 'AVStream::codec': 已声明已弃用
错误 C4996“avcodec_decode_video2”:已声明已弃用
错误 C4996“avcodec_copy_context”:已声明已弃用

  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();
        }
c++ ffmpeg libav
1个回答
4
投票

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

av_register_all()
- 自 2018 年起不再使用,只需删除此行

av_free_packet()

 -> 
av_packet_unref()
 
自 2015 年起

AVStream::codec

 -> 
AVStream::codecpar

avcodec_decode_video2

 -> 将其替换为 
avcodec_send_packet
avcodec_receive_frame
 机制

最后:

avcodec_copy_context

 -> 来自文档:

这个函数的语义定义不明确,不应该 使用。如果您需要从一个编解码器上下文传输流参数 对于另一个,使用中间 AVCodecParameters 实例和 avcodec_parameters_from_context() / avcodec_parameters_to_context() 功能。

© www.soinside.com 2019 - 2024. All rights reserved.