microsoft / microsoft/FFmpegInterop

End of stream situations not handled correctly (last frames are dropped)

Open
#217 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.4k
Forks
319
PR merge metrics
No merged PRs in 30d

Description

We currently do not handle end of stream correctly for uncompressed sample providers. The decoders might contain buffered data at end of stream, which gets discarded right now.

Please check the following from ffmpeg docs:

End of stream situations. These require "flushing" (aka draining) the codec, as the codec might buffer multiple frames or packets internally for performance or out of necessity (consider B-frames). This is handled as follows:

Instead of valid input, send NULL to the avcodec_send_packet() (decoding) or avcodec_send_frame() (encoding) functions. This will enter draining mode.

Call avcodec_receive_frame() (decoding) or avcodec_receive_packet() (encoding) in a loop until AVERROR_EOF is returned. The functions will not return AVERROR(EAGAIN), unless you forgot to enter draining mode.

Before decoding can be resumed again, the codec has to be reset with avcodec_flush_buffers().

https://www.ffmpeg.org/doxygen/3.4/group__lavc__encdec.html

Currently, we just stop decoding when we do not get a packet anymore. But instead, we have to send NULL packet to the decoder and then drain the decoder. Only then we are really at end of stream.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the uncompressed sample provider and the code that stops decoding when no packet is available. Read the linked FFmpeg end-of-stream documentation, then trace how buffered decoder frames are handled. Done means the decoder is drained at end of stream so buffered frames are not dropped, with existing decoding checks still passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.