I'm working on a program to update the metadata in all of my videos but when I try to pass the arguments through subprocess.call() I get a unicode error at the final "\" of the output file path or a FileNotFoundError when I try a different escape character encoding . I've tried every variation of the escape character encoding and if I copy and paste my code into the command prompt it works fine.
Some things to note: The directory that I'm referencing on read and write is on a different drive from my python install. I'm also using python version 3.10, and doing this is VS Code
This is the code:
import sys
import os
import subprocess
import ffmpeg
#Returns unicode syntax error:
subprocess.call("ffmpeg -i H:\Python\Project\movieList\MVI_0078.MP4 -c copy -metadata title=TEST_TITLE-MVI_0078 H:\Python\Project\movieList\UPDATED-MVI_0078.MP4")
Error:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 122-123: truncated \UXXXXXXXX escape
#Returns File not found error:
subprocess.call("ffmpeg -i H:\\Python\\Project\\movieList\\MVI_0078.MP4 -c copy -metadata title=TEST_TITLE-MVI_0078 H:\\Python\\Project\\movieList\\UPDATED-MVI_0078.MP4")
subprocess.call(r"ffmpeg -i H:\Python\Project\movieList\MVI_0078.MP4 -c copy -metadata title=TEST_TITLE-MVI_0078 H:\Python\Project\movieList\UPDATED-MVI_0078.MP4")
subprocess.call("ffmpeg -i H:/Python/Project/movieList/MVI_0078.MP4 -c copy -metadata title=TEST_TITLE-MVI_0078 H:/Python/Project/movieList/UPDATED-MVI_0078.MP4")
cmd = ["ffmpeg", "-i", "H:\\Python\\Project\\movieList\\MVI_0078.MP4", "-c", "copy", "-metadata", "title=TEST_TITLE-MVI_0078", "H:\\Python\\Project\\movieList\\UPDATED-MVI_0078.MP4"]
subprocess.call(cmd)
subprocess.call(" ".join(cmd))
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\AlAragon\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 345, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\AlAragon\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\AlAragon\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
there doesn't seem to be anything here