软解码和软编码时都没问题,换成硬解码之后,程序一直卡在avcodec_receive_frame这里,一直返回-11
std::cout << output <<std::endl;
while (av_read_frame(fmt_ctx, &avpkt) >= 0) {
if (avpkt.stream_index == stream_index) {
// 8 发送等待解码帧
int re = avcodec_send_packet(codeCtx, &avpkt);
if (re < 0) {
continue;
}
std::cout << 1 << std::endl;
// 9 接收解码后frame数据
std::cout << avcodec_receive_frame(codeCtx, frame) << std::endl;
while (avcodec_receive_frame(codeCtx, frame) == 0) {
// 拼接图片路径、名称,测试输出用
snprintf(buf, sizeof(buf), "%s/Demo-%d.jpg", output, frame_count++);
std::cout << 2 << std::endl;
width = frame->width;
height = frame->height;
Encode2Jpg(frame); //保存为jpg图片
}
// 测试从内存读数据到文件里是否正常
FILE *fp = fopen(buf,"wb");
fwrite(bd_out.ptr, sizeof(char), bd_out.size, fp);
fclose(fp);
}
av_packet_unref(&avpkt);
}