0

I have a bunch of video files, They have the correct file name but the title in the metadata is gibberish, I want to copy the file name & set it as the tile in the metadata.

Here is an example video file

2

2 Answers 2

1

For MP4/Mov files (not Mkv), you could use exiftool on the command line. Your command would be along these lines
exiftool "-Title<Basename" /path/to/files/

This command creates backup files. Add -overwrite_original to suppress the creation of backup files. Add -r to recurse into subdirectories.

0

You will need python, MKVtoolnix and Kid3-cli for this. Exif actually rewrites the file; this method just writes the metadata. Leaps and bounds quicker. Huge thank you to Harvey at Github

Run this script from Python. I copy this file into the parent directory where I want the files to be edited. Then within that parent directory, I go to the address bar and type cmd in the address bar, then type the command below to run the script.

python remeta_mp4.py mp4 for the current directory only and python remeta_mp4.py mp4 -r to change all mp4 files in its subdirectories

Copy and save into notepad and ensure save as .py extension.

import glob
import subprocess
import os
import sys

def mp4_string(title):
    name, name_extension = os.path.splitext(os.path.basename(title).replace("'", "\\'"))
    return name

def exec_mp4(mp4name):
    mp4name_title = mp4_string(mp4name)
    subprocess.run(["kid3-cli", "-c", f"set title '{mp4name_title}'", mp4name], shell=True)

def mp4(recursive=False):
    if recursive:
        for mp4name in glob.glob('**/*.mp4', recursive=True):
            exec_mp4(mp4name)
            print(f"Title metadata of {mp4name} has been changed")
    else:
        for mp4name in glob.glob("*.mp4"):
            exec_mp4(mp4name)
            print(f"Title metadata of {mp4name} has been changed")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python rmeta.py mp4 [-r] for recursive operations")
        sys.exit(1)

    action_type = sys.argv[1]
    recursive = False
    if len(sys.argv) > 2 and sys.argv[2] == "-r":
        recursive = True

    if action_type == "mp4":
        mp4(recursive)
    else:
        print("Usage: python rmeta.py mp4 [-r] for recursive operations")
        sys.exit(1)

If you want to be able to double-click the .py file instead of using cmd prompt, you can use the below code. The code below will write ALL .mp4 files in the current AND subdirectories. Just make sure you save it as .py file

import glob
import subprocess
import os
import sys

def mp4_string(title):
    name, name_extension = os.path.splitext(os.path.basename(title).replace("'", "\\'"))
    return name

def exec_mp4(mp4name):
    mp4name_title = mp4_string(mp4name)
    subprocess.run(["kid3-cli", "-c", f"set title '{mp4name_title}'", mp4name], shell=True)

def mp4(recursive=True):
    if recursive:
        for mp4name in glob.glob('**/*.mp4', recursive=True):
            exec_mp4(mp4name)
            print(f"Title metadata of {mp4name} has been changed")
    else:
        for mp4name in glob.glob("*.mp4"):
            exec_mp4(mp4name)
            print(f"Title metadata of {mp4name} has been changed")

if __name__ == "__main__":
mp4()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.