phoboslab / pl_mpeg

Single file C library for decoding MPEG1 Video and MP2 Audio
799 stars 58 forks source link

Decode slice macroblock loop condition may be incorrect #30

Closed matsondawson closed 2 years ago

matsondawson commented 2 years ago

When looping to decode macroblocks you call plm_buffer_no_start_code, which is an aligned check for no start code. I think this can lose undecoded bits in the stream. In the spec it seems they do an unaligned bitcheck for 23 0's. I believe if there were no more macroblocks and the stream wasn't aligned it would be padded with 0's. What do you think?

image

image

matsondawson commented 2 years ago

I've confirmed this now. You're missing a few macroblocks every few seconds. I can see the last few bits in the buffer being skipped. It doesn't cause decoding issues as the file from that point on is still valid. But it is probably causing minor rendering corruption.

matsondawson commented 2 years ago

This seems to fix it, but I don't really understand the code enough to say it's correct. image

matsondawson commented 2 years ago

Lol. It appears you've already fixed this. Closing