我正在尝试编写 FFmpeg 客户端流,但出现了一些错误
Error C4996 'av_register_all': was declared deprecated
Error C4996 'av_free_packet': was declared deprecated
Error C4996 'AVStream::codec': was declared deprecated
Error C4996 'avcodec_decode_video2': was declared deprecated
Error C4996 'avcodec_copy_context': was declared deprecated
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();
}
最佳答案
首先,这些应该是警告,而不是错误。如果它们是错误,则说明编译器设置太严格了
av_register_all
- 不再使用,删除这一行
av_free_packet
-> av_packet_unref
AVStream::codec
-> AVStream::codecpar
avcodec_decode_video2
-> 将其替换为 avcodec_send_packet
、avcodec_receive_frame
机制
最后:
avcodec_copy_context
-> 来自文档:
The semantics of this function are ill-defined and it should not be used. If you need to transfer the stream parameters from one codec context to another, use an intermediate AVCodecParameters instance and the avcodec_parameters_from_context() / avcodec_parameters_to_context() functions.
关于c++ - 如何修复这些错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57177855/