我正试图让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();
}
答案 0 :(得分:0)
首先,这些应该是警告,而不是错误。如果它们是错误的,则说明您对编译器的设置太严格了
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
->来自文档:
此函数的语义不明确,不应 使用。如果您需要从一个编解码器上下文传输流参数 到另一个,使用中间的AVCodecParameters实例和 avcodec_parameters_from_context()/ avcodec_parameters_to_context() 功能。