Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write metadata to mkv files as well as mp4 #2

Open
4c0d3r opened this issue Mar 25, 2022 · 1 comment
Open

Write metadata to mkv files as well as mp4 #2

4c0d3r opened this issue Mar 25, 2022 · 1 comment
Labels
up for grabs If a pr comes in with these features and tests, will accept.

Comments

@4c0d3r
Copy link
Collaborator

4c0d3r commented Mar 25, 2022

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.

@4c0d3r 4c0d3r added the up for grabs If a pr comes in with these features and tests, will accept. label Mar 25, 2022
@4c0d3r
Copy link
Collaborator Author

4c0d3r commented Jul 21, 2022

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
up for grabs If a pr comes in with these features and tests, will accept.
Projects
None yet
Development

No branches or pull requests

1 participant