Added MPEG accept function by radarhere · Pull Request #7999 · python-pillow/Pillow

Investigating MpegImagePlugin's _open function,

def _open(self) -> None:
assert self.fp is not None
s = BitStream(self.fp)
if s.read(32) != 0x1B3:
msg = "not an MPEG file"
raise SyntaxError(msg)

this is saying that MPEG images must start with b"\x00\x00\x01\xb3".

This is what https://en.wikipedia.org/wiki/List_of_file_signatures describes as the magic number for "MPEG-1 video and MPEG-2 video (MPEG-1 Part 2 and MPEG-2 Part 2)"

So I have added an _accept function to check the magic number. This is a minor performance improvement, allowing non-MPEG images to be rejected without further file reading.

I have also added tests for the MPEG format, as those were not present. These are based on the first few tests of test_file_bufrstub.py.