Write metadata to mkv files as well as mp4
Start by figuring out the command line tools to edit a video: https://mkvtoolnix.download/doc/mkvpropedit.html
You should test adding the video to a plex library to see if metadata is read - not sure if plex/jellyfin/emby support this or not. If they don't, not sure you should be doing this work, but carry on if you want.
Once you have the commands - maybe post them here if as a comment - incase you decide to give up.
Read some code, look at two files in namer: 1: https://github.com/ThePornDatabase/namer/blob/main/namer/ffmpeg.py To see how to properly call external commands.
2: https://github.com/ThePornDatabase/namer/blob/main/namer/mutagen.py To see what needs to be built for mkv's. The mutagen file supports mp4s.
Write your code with a test similar to mutagen: https://github.com/ThePornDatabase/namer/blob/main/test/namer_mutagen.py
Update namer.py to call your new file for mkvs (around here: https://github.com/ThePornDatabase/namer/blob/main/namer/namer.py#L121)
Profit.
Maybe doable with ffmpeg:
import ffmpeg
from pathlib import Path
def metadata(file: Path, res_file: Path):
data = {
'metadata:g:0': "title=My Title",
'metadata:g:1': "artist=Me",
'metadata:g:2': "album=X",
'metadata:g:3': "year=2019",
}
stream = ffmpeg.input(str(file))
stream = ffmpeg.output(stream, str(res_file), **data)
stream = ffmpeg.overwrite_output(stream)
ffmpeg.run(stream)
def main():
file = Path(r'D:\Documents\Desktop\blank.mp4')
metadata(file, Path(r'D:\Documents\Desktop\_blank.mp4'))
file = Path(r'D:\Documents\Desktop\blank.mkv')
metadata(file, Path(r'D:\Documents\Desktop\_blank.mkv'))
if __name__ == '__main__':
main()