-
-
Notifications
You must be signed in to change notification settings - Fork 9k
linux-v4l2: Fix H.264 decoding artifacts at high resolution #12864
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
base: master
Are you sure you want to change the base?
Conversation
|
I see you are trying to prevent This solution works. Another option would be to handle the error inside // v4l2_decoder.c
// remove #include <libavutil/error.h>
// v4l2_decode_frame()
r = avcodec_receive_frame(decoder->context, decoder->frame);
if (r < 0) {
blog(LOG_ERROR, "failed to receive frame from codec");
return r;
}
// don't return 1 at the end, just 0 as beforeAnd // v4l2-input.c
#include <libavutil/error.h>
// v4l2_thread()
if (data->pixfmt == V4L2_PIX_FMT_MJPEG || data->pixfmt == V4L2_PIX_FMT_H264) {
r = v4l2_decode_frame(&out, start, buf.bytesused, &data->decoder);
if (r == AVERROR(EAGAIN)) {
blog(DEBUG, "decoder encountered EAGAIN, so continue with next frame");
goto continue_queue_buffer;
} else if (r < 0) {
blog(LOG_ERROR, "failed to unpack jpeg or h264");
break;
}
} else {
for (uint_fast32_t i = 0; i < MAX_AV_PLANES; ++i)
out.data[i] = start + plane_offsets[i];
}
obs_source_output_video(data->source, &out);I have no preference! Well done on finding a fix 🎉 |
|
Thanks for the detailed feedback and the alternative approach! You're right — handling I don't have a strong preference either, and I'm happy to adjust the patch to the approach you outlined if you think it fits better with the existing design. |
|
Thanks for reading my feedback! I also don't have a strong preference; the solution you provided works, too. Will wait and see what the maintainers say. |
fdb45ec to
149ccac
Compare
149ccac to
4297519
Compare
Description
This PR addresses severe artifacts (mosaic/smearing) when capturing high-resolution (e.g., 4K) H.264 streams via V4L2 on Linux.
Motivation and Context
On Linux, capturing 4K H.264 via V4L2 was practically unusable due to single-threaded decoding bottlenecks, resulting in corrupted keyframes (mosaic artifacts). Standard tools like ffplay worked fine because they default to multi-threaded software decoding, whereas OBS was restricted to a single thread.
This PR aligns the V4L2 source performance with other platforms (Windows) and standard players (ffplay), making 4K H.264 capture viable on Linux.
How Has This Been Tested?
Types of changes
Checklist: