Der*_*den 10 c++ buffer ffmpeg
我正在使用ffmpeg从RTSP流处理一堆帧.我最终对这些帧进行了大量处理,这意味着我并不总是实时提取.如果缓冲区已满,则进程挂起.我想知道以下解决方案之一是否可行/解决问题,如果是,我将如何使用ffmpeg库实现它:
1)如果我到达悬挂点,有没有办法清除缓冲区?(我可以确定它何时挂起,我只是不知道该怎么做).
2)有没有办法让缓冲区覆盖旧数据,只是总是读取最新的数据?如果我丢帧,对我来说无关紧要.
3)我已经发现,我可以让缓冲区arbtrarily大:av_dict_set(&avd, "buffer_size", "655360", 0);.这可能是一个解决方案,但我不知道它需要多大/多小,因为我不知道流将发布视频的时间有多长?
4)这只是我需要提出的ffmpeg人员的错误吗?
5)我没有考虑过的其他事情?
while(av_read_frame(context, &(packet)) >= 0 && fcount < fps*SECONDS) {
clock_t start, end;
int ret = avcodec_send_packet(codec_context, packet);
if(!(packet->stream_index == video_stream_index)) {
continue;
}
if (ret == AVERROR(EAGAIN) || ret == AVERROR(EINVAL)) {
continue;
} else if (ret < 0) {
cerr << "Error while decoding frame " << fcount << endl;
exit(1);
}
ret = avcodec_receive_frame(codec_context, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR(EINVAL)) {
continue;
} else if (ret < 0) {
cerr << "Error while decoding frame " << fcount << endl;
exit(1);
}
sws_scale(img_convert_ctx, frame->data, frame->linesize, 0,
codec_context->height, picture_rgb->data, picture_rgb->linesize);
if(!frame) {
cerr << "Could not allocate video frame" << endl;
exit(1);
}
if(codec_context == NULL) {
cerr << "Cannot initialize the conversion context!" << endl;
exit(1);
}
// Do something with the frame here
fcount++;
av_packet_unref(&(packet));
}
Run Code Online (Sandbox Code Playgroud)
我添加了导致程序挂起的代码.