-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ffmpeg: Fix short segments flushing without using NULL packets #189
Conversation
Earlier we relied on getting a sentinel (pts -1) packet back to know when the decoder is flushed. This does not work for short segments as the decoder buffers packets internally. Now we maintain the difference between packets sent - frames received and mark decoder as flushed when this becomes 0 (usually). Sometimes the decoder might not return all frames (see #155), so we give up after sending SENTINEL_MAX packets and not getting any valid frame back.
135d352
to
30b566f
Compare
if err != nil { | ||
t.Error(err) | ||
} | ||
if res.Encoded[0].Frames == 0 || res.Encoded[1].Frames != 0 || res.Encoded[2].Frames != fc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for res.Encoded[0].Frames == 0
makes me sweat a bit, because we don't really know what might be a reasonably correct value. But I understand it's pretty hard to get predictable results across different runs, probably OK for now.
- Use expected output pkt pts in flush packet to ensure fps filter returns a frame even for 1-frame segments getting downsampled to low fps. FFmpeg CLI drops such frames unless using eof_action=pass, but we cannot use it as it closes the decoder. - Add parameterized unit tests to reproduce #168 Fixes #168
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚢
In #187 I tried to fix the short segment flushing using NULL packets, but it had heavy performance impact. So I've created this fresh PR because that got very messy.
I tried my best to benchmark this against master and it seems to perform equally well. I noob though, pls verify :)