Note that there are some explanatory texts on larger screens.

plurals
  1. POFailing to read frames from stream after interrupt
    text
    copied!<p>I'm using FFmpeg to read and decode a network video stream. I have the read/decode stuff happening on a dedicated thread. Occasionally, I would like to join on that thread. To do this, I've tried specifying an interrupt callback and flags to indicate that reads should be non-blocking. I have most of the basics working, but I'm running into an issue with my <strong>av_read_frame</strong> after an interrupt. Here's the basic structure:</p> <pre><code>void read() { AVPacket pkt; while (shouldRead) { if (av_read_frame(formatCtx, &amp;pkt) { // succesfully read frame } else { // failed to read frame } } } int interrupt_cb(void* param) { return shouldInterrupt; } void initialize() { formatCtx = avformat_alloc_context(); formatCtx-&gt;flags |= AVFMT_FLAG_NONBLOCK; formatCtx-&gt;flags |= AVIO_FLAG_NONBLOCK; formatCtx-&gt;interrupt_callback.callback = interrupt_cb; // ...other initialization stuff (e.g. avformat_open_input, etc.) } </code></pre> <p>After initialization, everything looks fine - I happily chug along reading frames. However, if I ever try to interrupt by setting <strong>shouldInterrupt</strong> to <strong>true</strong>, all subsequent <strong>av_read_frame</strong> calls fail. Also, the interrupt callback never gets called again. Digging into the code a bit, I see that formatCtx->packet_buffer is empty. Given that, it makes sense that the reads fail. How do I resume reading after the interrupt then? I'd rather not have to tear down completely to resume reading and decoding. </p> <p>UPDATE: I recently discovered that there's an AVIO_FLAG_NONBLOCK flag as well. I tried that but it didn't seem to help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload