quodlibet / mutagen

Python module for handling audio metadata

Home Page:https://mutagen.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MP4.save() makes phone videos unreadable (Invalid NAL unit size)

nahoj opened this issue · comments

If I use Mutagen to write tags to an MP4 video that I took with my phone (Samsung Galaxy S7 with LineageOS 14.1), I can't read the file with mplayer or VLC or any player I tried anymore.

This seems to be the case for any video taken with my phone and no other video I ever encountered.

Sample file: https://uno.nahoj.eu/nextcloud/s/CTffQgpw8qcqWnb

Steps to reproduce (last tried with Python 3.10 and Mutagen 1.46.0):

>>> f = mutagen.File("VID_20220226_151532a.mp4")
>>> type(f)
<class 'mutagen.mp4.MP4'>
>>> f["title"] = "Hi!"
>>> f.pprint()
'MPEG-4 audio (), 0.00 seconds, 0 bps (audio/mp4)\ntitle=Hi!'
>>> # Up to this point the file is fine
>>> f.save()
>>> # The file is now unreadable

After this, if I try to read the file with VLC, it outputs a bunch of errors of this type:

[h264 @ 0x7f0240c438c0] Invalid NAL unit size (961310570 > 279649).
[h264 @ 0x7f0240c438c0] Error splitting the input into NAL units.

Funnily this doesn't prevent Mutagen from reading and writing the tags multiple times. But undoing any changes doesn't make the video readable again.

I think this is a pretty bad bug. I noticed this when I added a tag on a personal video that I care a lot about and that got corrupted. Thankfully I had a backup; otherwise I would have had a very miserable day.