jamerst/AutoTag

Error: Failed to write tags to file (InvalidOperationException: File not writeable.)

livinggreener opened this issue · 6 comments

Running on a Windows machine with admin privileges. I'm getting this error on mkv files in TV tagging mode. I am able to write tags to these files with other manual applications such as tageditor (https://github.com/Martchus/tageditor) and Mp3tag. Everything else is working as far as pulling the metadata from TMDB and renaming the files per the tvRenamePattern in the config file.

This is a bug with the tagging library, taglib-sharp. It's been encountered before, it used to happen much more frequently but newer versions reduced the frequency.

It appears to detect certain files as being corrupted when they aren't, the reason for this is unknown.

The best solution I've found is to re-write the container with ffmpeg using ffmepg -i file.mkv -c copy -o outfile.mkv. In my experience the file will usually tag fine after this.

Remuxing all the streams as a copy with ffmpeg did indeed allow AutoTag to complete its tagging. My input mkv files were created with MakeMKV. The only difference I can tell is MakeMKV places the tags at the end of the file, uses simple single digit Track UIDs that equal the track number, and leaves an EBML void of after the chapters, whereas ffmpeg - after remuxing - places the tags at the beginning of the file, rewrites the Track UIDs to a more conventional long number, and doesn't leave a EBML void after the chapters. After AutoTag runs, it removes the front-loaded tags and places them along with the new tags at the end of the file, moves segment information after chapters, and leaves a larger EBML void after segment information.

That's useful information to know. I've already remuxed all my own files, so I don't have any broken ones left to test with unfortunately.

I can't change this behaviour in AutoTag, so it's probably best to report this issue to the maintainers of taglib-sharp.

v3.1.2 may help to shed some light on this - I noticed that the TagLib File object has a property called CorruptionReasons. These reasons will now be displayed in verbose mode if they are populated.

Here's the error now from v3.1.2 with CorruptionReasons running it on one of the error-throwing .mkv files created by MakeMKV:

"Error: Failed to write tags to file (InvalidOperationException: File not writeable.; CorruptionReasons: Invalid Meta Seek)"

Every .mkv from MakeMKV I've tried with AutoTag results in this error.

I was able to track down the likely issue using the CorruptionReasons result. Taglib-sharp must be using a fast parse mode that requires the .mkv file's seek head (meta data indicating where main sections of the file can be located) rather than fully parsing the file. When I compared the files created by MakeMKV vs those remuxed by ffmpeg I found a small EBML void in the MakeMKV-created files' seek head separating the tag seek metadata from the rest of the seek head. If this is indeed the root-cause, taglib-sharp must be sensitive enough to this void making it unable to find and read the seek location for the tags.
If taglib-sharp has a full parse mode option, perhaps AutoTag could fall back to that when 'CorruptionReasons: Invalid Meta Seek' is encountered. If successful that would make having to remux files with ffmpeg unnecessary.