FFmpeg - avcodec_receive_frame returns AVERROR(EAGAIN)Meaning of ffmpeg output (tbc, tbn, tbr)Rotating videos with FFmpegFFmpeg on AndroidFFmpeg: How to split video efficiently?How to concatenate two MP4 files using FFmpeg?What are the differences and similarities between ffmpeg, libav, and avconv?ffmpeg to extract audio from videoCutting the videos based on start and end time using ffmpegFFmpeg av_read_frame returns a size but no data?FFMPEG (libx264) “height not divisible by 2”

Zhora asks Deckard: "Are you for real?". Was this meant to be significant?

Everyone but three

How to interpret a promising preprint that was never published?

When can a polynomial be written as a polynomial function of another polynomial?

Should I use a resistor between the gate driver and MOSFET (gate pin)?

Is there a difference between PIO and GPIO pins?

How to find location on Cambridge-Mildenhall railway that still has tracks/rails?

What was the difference between a Games Console and a Home Computer?

When is the Circle of Dreams druid's Walker in Dreams feature used?

How can one convert an expression to a string while keeping the quotation marks of strings that are part of the expression?

Why isn't a binary file shown as 0s and 1s?

Is Error correction and detection can be done with out adding extra bits?

Grouping into more groups in one iteration

What are the basics of commands in Minecraft Java Edition?

How to not confuse readers with simultaneous events?

Why won't some unicode characters print to my terminal?

How do you give a date interval with diffuse dates?

ANOVA or Linear Mixed Model?

Strategy to pay off revolving debt while building reserve savings fund?

Why aren't there any women super GMs?

Wordplay addition paradox

What is this green alien supposed to be on the American covers of the "Hitchhiker's Guide to the Galaxy"?

Is straight-up writing someone's opinions telling?

Finding all possible pairs of square numbers in an array



FFmpeg - avcodec_receive_frame returns AVERROR(EAGAIN)


Meaning of ffmpeg output (tbc, tbn, tbr)Rotating videos with FFmpegFFmpeg on AndroidFFmpeg: How to split video efficiently?How to concatenate two MP4 files using FFmpeg?What are the differences and similarities between ffmpeg, libav, and avconv?ffmpeg to extract audio from videoCutting the videos based on start and end time using ffmpegFFmpeg av_read_frame returns a size but no data?FFMPEG (libx264) “height not divisible by 2”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm using an QOpenGL widget to draw frames. However, I'm struggling to get frames by using avcodec_receive_frame. It ended within the block else if (ret == AVERROR(EAGAIN)) and returned -11. I have no idea what made this happen. Also I checked that codecs were fine, so I guess the problem wasn't caused by codecs.



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();

;









share|improve this question






























    1















    I'm using an QOpenGL widget to draw frames. However, I'm struggling to get frames by using avcodec_receive_frame. It ended within the block else if (ret == AVERROR(EAGAIN)) and returned -11. I have no idea what made this happen. Also I checked that codecs were fine, so I guess the problem wasn't caused by codecs.



    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();

    ;









    share|improve this question


























      1












      1








      1


      1






      I'm using an QOpenGL widget to draw frames. However, I'm struggling to get frames by using avcodec_receive_frame. It ended within the block else if (ret == AVERROR(EAGAIN)) and returned -11. I have no idea what made this happen. Also I checked that codecs were fine, so I guess the problem wasn't caused by codecs.



      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();

      ;









      share|improve this question
















      I'm using an QOpenGL widget to draw frames. However, I'm struggling to get frames by using avcodec_receive_frame. It ended within the block else if (ret == AVERROR(EAGAIN)) and returned -11. I have no idea what made this happen. Also I checked that codecs were fine, so I guess the problem wasn't caused by codecs.



      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();

      ;






      ffmpeg decoding






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 10:03







      Jinx

















      asked Mar 26 at 9:51









      JinxJinx

      3119 bronze badges




      3119 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          There is a delay between sending and receiving a frame. When receive returns EAGAIN, you should call send with the next encoded frame, then call receive again.






          share|improve this answer

























          • Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

            – Jinx
            Mar 26 at 14:45












          • You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

            – szatmary
            Mar 26 at 14:51










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354120%2fffmpeg-avcodec-receive-frame-returns-averroreagain%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          There is a delay between sending and receiving a frame. When receive returns EAGAIN, you should call send with the next encoded frame, then call receive again.






          share|improve this answer

























          • Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

            – Jinx
            Mar 26 at 14:45












          • You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

            – szatmary
            Mar 26 at 14:51















          1














          There is a delay between sending and receiving a frame. When receive returns EAGAIN, you should call send with the next encoded frame, then call receive again.






          share|improve this answer

























          • Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

            – Jinx
            Mar 26 at 14:45












          • You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

            – szatmary
            Mar 26 at 14:51













          1












          1








          1







          There is a delay between sending and receiving a frame. When receive returns EAGAIN, you should call send with the next encoded frame, then call receive again.






          share|improve this answer















          There is a delay between sending and receiving a frame. When receive returns EAGAIN, you should call send with the next encoded frame, then call receive again.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 26 at 16:25

























          answered Mar 26 at 14:41









          szatmaryszatmary

          20.1k6 gold badges30 silver badges47 bronze badges




          20.1k6 gold badges30 silver badges47 bronze badges












          • Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

            – Jinx
            Mar 26 at 14:45












          • You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

            – szatmary
            Mar 26 at 14:51

















          • Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

            – Jinx
            Mar 26 at 14:45












          • You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

            – szatmary
            Mar 26 at 14:51
















          Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

          – Jinx
          Mar 26 at 14:45






          Sorry I’m not quite sure what u mean. The avcodec_send_packet comes before avcodec_receive_frame. And also they are implemented in a while loop in the main method

          – Jinx
          Mar 26 at 14:45














          You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

          – szatmary
          Mar 26 at 14:51





          You must keep calling avcodec_send_frame with new data until avcode_receive_frame returns a valid frame.

          – szatmary
          Mar 26 at 14:51








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354120%2fffmpeg-avcodec-receive-frame-returns-averroreagain%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript