gpt4 book ai didi

FFmpeg - avcodec_receive_frame 返回 AVERROR(EAGAIN)

转载 作者:行者123 更新时间:2023-12-04 22:46:06 25 4
gpt4 key购买 nike

我正在使用 QOpenGL 小部件绘制框架。但是,我正在努力使用 avcodec_receive_frame 获取帧。它在 else if (ret == AVERROR(EAGAIN)) block 内结束并返回 -11。我不知道是什么导致了这一切。我还检查了编解码器是否正常,所以我猜问题不是由编解码器引起的。

MyDemux.cpp

AVPacket* MyDemux::allocatePacket()
{
AVPacket* packet = av_packet_alloc();
return packet;
}

AVFrame* MyDemux::allocateFrame()
{
AVFrame* frame = av_frame_alloc();
return frame;
}

int MyDemux::readFrame(AVPacket* packet)
{
mux.lock();
if (!formatCtx) {
std::cout << "formaetCtx is null" << std::endl;
mux.unlock();
return -1;
}
int ret = av_read_frame(formatCtx, packet);
if (ret == AVERROR_EOF) {
return -2;
}
if (ret != 0) {
mux.unlock();
av_packet_free(&packet);
return -1;
}
media_type = packet->stream_index;
mux.unlock();
return 0;
}

MyDecode.cpp

void MyDecode::decode(AVFrame* frame, AVPacket* packet)
{
int ret;
ret = avcodec_send_packet(codecCtx, packet); // this returned 0
while (ret == 0) {
ret = avcodec_receive_frame(codecCtx, frame); // this returned -11
if (ret == AVERROR(EINVAL)) {
std::cout << "codec issue" << std::endl;
av_frame_free(&frame);
return;
}
else if (ret == AVERROR(EAGAIN)) { // program ends here
std::cout << "output is not available this state" << std::endl;
av_frame_free(&frame);
return;
}
else if (ret == AVERROR(EINVAL)) {
std::cout << "no more frames" << std::endl;
av_frame_free(&frame);
return;
}
}
}

main.cpp

class MyThread : public QThread
{
public:

MyDemux demux;
MyDecode video_decode;
myDecode audio_decode;
MyVideoWidget* videoWidget;
AVPacket* packet;
AVFrame* frame;

void initThread()
{
char* url = "demo.mp4";
demux.openFile(url);
video_decode.openCodec(demux.copy_video_codec_par());
audio_decode.openCodec(demux.copy_audio_codec_par());
packet = demux.allocatePacket();
frame = demux.allocateFrame();
}
void run()
{
while (demux.readFrame(packet) != -2) {
if (demux.get_media_type() == 0) {
video_decode.decode(frame, packet);
videoWidget->paintFrame(frame);
}
else if (demux.get_media_type() == 1) {
}
}
video_decode.decode(frame, nullptr);
demux.clear();
demux.close();
}
};

最佳答案

当您调用 avcodec_receive_frame 并收到 EAGAIN 错误时,这意味着您的解码器没有获得足够的数据来解码(例如,您在视频中发送了一个 B 帧)。所以每次你得到那个错误你应该忽略它并转到下一个 avcodec_send_packet

关于FFmpeg - avcodec_receive_frame 返回 AVERROR(EAGAIN),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55354120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com