I'm trying to implement a function which can get the next frame, but when i call this function at the 3rd time
int ret = decoder.get_next_frame(mat);
ret = decoder.get_next_frame(mat);
ret = decoder.get_next_frame(mat); // error
ffmpeg avcodec_send_packet return err, and the msg is [h264 @ 0x8bd2780] Invalid NAL unit size (10848 > 766). [h264 @ 0x8bd2780] Error splitting the input into NAL units. the var with prefix '_' are all member var
int VideoDecoder::get_next_frame(cv::Mat& mat) {
int ret = 0;
bool got_frame = false;
while (!got_frame && av_read_frame(_p_fmt_ctx, _p_packet) >= 0) {
if (_p_packet->stream_index == _video_stream_index) {
ret = avcodec_send_packet(_p_dec_ctx, _p_packet);
if (ret < 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
break;
}
while (ret >= 0) {
ret = avcodec_receive_frame(_p_dec_ctx, _p_frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
break;
}
sws_scale(_p_img_convert_ctx, _p_frame->data, _p_frame->linesize,
0, _p_dec_ctx->height, _p_frame_rgb->data, _p_frame_rgb->linesize);
mat = cv::Mat(_p_frame->height, _p_frame->width, CV_8UC3, _p_frame_rgb->data[0]);
got_frame = true;
}
}
av_packet_unref(_p_packet);
}
if (got_frame) {
return _p_dec_ctx->frame_number;
}
return 0;
}
so what's the problem?