avcodec_receive_packet错误(gdi 屏幕截图 + ffmpeg)
Error in avcodec_receive_packet (gdi screenshot + ffmpeg)
我尝试用ffmpeg捕获Windows屏幕。 一切正常,但avcodec_receive_packet返回错误AVERROR(EAGAIN( 我无法理解为什么会发生这种情况。 有人可以给出建议吗?
SwsContext* convertContext = sws_getContext(c->width, c->height, AV_PIX_FMT_BGRA, c->width, c->height, c->pix_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
for (int i = 0; i < fps*seconds; i++)
{
fflush(stdout);
/* make sure the frame data is writable */
ret = av_frame_make_writable(frame);
if (ret < 0)
exit(1);
gdi->MakeScreenshoot();
OutFrame->pts = i;
int ret = av_image_fill_arrays(GDIFrame->data, GDIFrame->linesize, gdi->m_bufferGDIBits, AV_PIX_FMT_BGRA, c->width, c->height, 1);
ret = av_image_fill_arrays(OutFrame->data, OutFrame->linesize, outbuffer, c->pix_fmt, c->width, c->height, 1);
GDIFrame->data[0] += GDIFrame->linesize[0] * (c->height - 1); // flipping frame
GDIFrame->linesize[0] *= -1;
int hslice = sws_scale(convertContext, GDIFrame->data, GDIFrame->linesize, 0, c->height,OutFrame->data, OutFrame->linesize);
/* encode the image */
encode(c, OutFrame, pkt, f);
}
static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile)
{
int ret = -1;
/* send the frame to the encoder */
/*if (frame)
printf("Send frame %3"PRId64"n", frame->pts);*/
ret = avcodec_send_frame(enc_ctx, frame);
if (ret < 0)
{
fprintf(stderr, "Error sending a frame for encodingn");
exit(1);
}
while (ret >= 0)
{
ret = avcodec_receive_packet(enc_ctx, pkt);
if (ret == AVERROR_EOF)
return;
if (ret == AVERROR(EAGAIN))
return;
else
if (ret < 0)
{
fprintf(stderr, "Error during encodingn");
exit(1);
}
//printf("Write packet %3"PRId64" (size=%5d)n", pkt->pts, pkt->size);
fwrite(pkt->data, 1, pkt->size, outfile);
av_packet_unref(pkt);
}
}
如果我发表评论
if (ret == AVERROR_EOF)
return;
if (ret == AVERROR(EAGAIN))
return;
else
if (ret < 0)
{
fprintf(stderr, "Error during encodingn");
exit(1);
}
在编码函数中 - 一切都很好,文件将被写入并且是正确的,但我想解决问题。
派对有点晚了。 我也在用encode_video.c尝试这个
似乎当编码器没有准备好完整的数据包时,avcodec_receive_packet(( 会返回这些"错误"......可能下次调用 avcodec_send_frame(( 将导致一个完整的数据包。
所以继续前进。 使用 NULL 帧对 avcodec_send_frame(( 的最终调用将刷新最终数据包。
相关文章:
- Winapi:屏幕截图未显示在窗口中
- 截取屏幕截图后程序卡住
- C++鼠标单击时的屏幕截图不起作用
- GTKMM:拍摄绘图区域的屏幕截图?
- 有没有办法使用 ofstream 保存屏幕截图?
- 如何使用 DX11 截取屏幕截图?
- avcodec_receive_packet错误(gdi 屏幕截图 + ffmpeg)
- C++屏幕截图 - 如何读取位图?
- 使用QT C 屏幕截图
- 如何将屏幕截图位图转换为 cv::Mat
- QT自动保存使用命名模板的屏幕截图
- C 屏幕截图
- BMP的完整屏幕截图.与块状和保存有关的问题
- 使用OpenCV和C++在按键上截取网络摄像头源的屏幕截图
- DirectX 部分屏幕截图
- 截取屏幕截图,分析它,然后删除它
- WXWIDGETS应用于WXStaticBitMap时,屏幕截图将大部分图像留为空白
- 屏幕截图桌面DirectX C /QT
- Gdi+Take屏幕截图多个显示器
- 可以闪存检测正在拍摄的屏幕截图(或GDI位副本)