<p>For MP4/Mov files (not Mkv), you could use <a href="https://exiftool.org/" rel="nofollow noreferrer">exiftool</a> on the command line.  Your command would be along these lines<br />
<code>exiftool &quot;-Title&lt;Basename&quot; /path/to/files/</code></p>
<p>This command creates backup files.  Add <a href="https://exiftool.org/exiftool_pod.html#overwrite_original" rel="nofollow noreferrer"><code>-overwrite_original</code></a> to suppress the creation of backup files.  Add <a href="https://ExifTool.org/exiftool_pod.html#r-.--recurse" rel="nofollow noreferrer"><code>-r</code></a> to recurse into subdirectories.</p>

CC BY-SA 4.0
2022-08-15T14:35:40.143Z
2022-08-15T14:35:40.143Z
StarGeek
<p>Thanks @skylinekiller, you saved me a painful manual task.</p>
<p>I've updated your code a little so that I can just drop a .py file into a root directory and leave it to do it's work.</p>
<p>Here's the updated code if it helps anyone:</p>
<pre><code>import glob
import subprocess
import os
import sys

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

def mkv_string(title):
    name, name_extension = os.path.splitext(os.path.basename(title))
    return name

def exec_mp4(mp4name):
    mp4name_title = mp4_string(mp4name)
    subprocess.run([&quot;kid3-cli&quot;, &quot;-c&quot;, f&quot;set title '{mp4name_title}'&quot;, mp4name], shell=True)
    
def exec_mkv(mkvname):
    mkvname_title = mkv_string(mkvname)
    subprocess.run([&quot;mkvpropedit&quot;, &quot;-e&quot;, &quot;-q&quot;, &quot;info&quot;, &quot;-s&quot;, f&quot;title={mkvname_title}&quot;, mkvname], shell=True)

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

def mkv():
    for mkvname in glob.glob('**/*.mkv', recursive=True):
        exec_mkv(mkvname)
        print(f&quot;Title metadata of {mkvname} has been changed&quot;)
    
if __name__ == &quot;__main__&quot;:
        mp4()
        mkv()
        sys.exit(1)
</code></pre>

CC BY-SA 4.0
2024-11-05T16:46:12.833Z
2024-11-05T16:46:12.833Z
Craig Poole
<p>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  <a href="https://github.com/HarveyDevel/rmeta" rel="nofollow noreferrer">Harvey at Github</a></p>
<p>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 <code>cmd</code> in the address bar, then type the command below to run the script.</p>
<p><code>python remeta_mp4.py mp4</code> for the current directory only and <code>python remeta_mp4.py mp4 -r</code> to change all mp4 files in its subdirectories</p>
<p>Copy and save into notepad and ensure save as .py extension.</p>
<pre><code>import glob
import subprocess
import os
import sys

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

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

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

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

    action_type = sys.argv[1]
    recursive = False
    if len(sys.argv) &gt; 2 and sys.argv[2] == &quot;-r&quot;:
        recursive = True

    if action_type == &quot;mp4&quot;:
        mp4(recursive)
    else:
        print(&quot;Usage: python rmeta.py mp4 [-r] for recursive operations&quot;)
        sys.exit(1)
</code></pre>
<p>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</p>
<pre><code>import glob
import subprocess
import os
import sys

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

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

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

if __name__ == &quot;__main__&quot;:
mp4()
</code></pre>

CC BY-SA 4.0
2023-06-22T01:15:17.360Z
2023-06-22T04:31:10.673Z
2023-06-22T04:31:10.673Z
skylinekiller
<p>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 &amp; set it as the tile in the metadata.</p>
<p><a href="https://i.sstatic.net/CwoeN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CwoeN.png" alt="Here is an example video file" /></a></p>

CC BY-SA 4.0
2022-08-15T10:33:55.793Z
I know how to do it for mkv files on Mac, never tried mp4 - https://apple.stackexchange.com/questions/367737/batch-remove-mkv-titles-only-no-re-encode
Tetsujin
CC BY-SA 4.0
2022-08-15T14:37:21.473Z
You forgot to mention the OS.
StarGeek
<editing><mp4><metadata>
How to copy the file name to the video metadata title?
ThunderE75
# How to copy the file name to the video metadata title?

(Asked by: username_0 on 2022-08-15)

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](https://i.sstatic.net/CwoeN.png)](https://i.sstatic.net/CwoeN.png)

**Tags:** editing, mp4, metadata

> **Comments:**
> **username_1**: I know how to do it for mkv files on Mac, never tried mp4 - https://apple.stackexchange.com/questions/367737/batch-remove-mkv-titles-only-no-re-encode  
> **username_2**: You forgot to mention the OS.  

---

## 3 answers

### Answer by username_2 on 2022-08-15. Score: 1 | Accepted answer

For MP4/Mov files (not Mkv), you could use [exiftool](https://exiftool.org/) on the command line. Your command would be along these lines  
`exiftool "-Title`

This command creates backup files. Add [`-overwrite_original`](https://exiftool.org/exiftool_pod.html#overwrite_original) to suppress the creation of backup files. Add [`-r`](https://ExifTool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories.


---

### Answer by username_3 on 2024-11-05. Score: 1

Thanks @username_4, you saved me a painful manual task.
I've updated your code a little so that I can just drop a .py file into a root directory and leave it to do it's work.
Here's the updated code if it helps anyone:
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 mkv_string(title):
    name, name_extension = os.path.splitext(os.path.basename(title))
    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 exec_mkv(mkvname):
    mkvname_title = mkv_string(mkvname)
    subprocess.run(["mkvpropedit", "-e", "-q", "info", "-s", f"title={mkvname_title}", mkvname], shell=True)

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

def mkv():
    for mkvname in glob.glob('**/*.mkv', recursive=True):
        exec_mkv(mkvname)
        print(f"Title metadata of {mkvname} has been changed")
    
if __name__ == "__main__":
        mp4()
        mkv()
        sys.exit(1)


---

### Answer by username_4 on 2023-06-22. Score: 1

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


---

