pythonffmpeg

Python-ffmpeg video metadata editing script - Error splitting the argument list: Option not found


I have been updating a simple script that allows me to mass edit video files metadata (in a specific folder) and save them with a new filename (inside the same folder). I have been bouncing around different forums and decided to try python-ffmpeg. For some reason right now I am getting the below FFmpegInvalidCommand exception

Error splitting the argument list: Option not found

I am not quite sure what I am doing wrong here, so I am wondering if someone can give me a fresh set of eyes to determine what the problem is. Apologies in advance, there may be some leftover code that I have not cut out yet. Thanks in advance!

import os
import re
import sys
from pathlib import Path
from ffmpeg import FFmpeg, FFmpegFileNotFound, FFmpegInvalidCommand
#Project looks through a folder, checks all the files in there, then edits metadata (and filename)
#and returns a new file for each file inside the folder

video = 'Anime' #Movie/TVSeries/Anime/etc...
name = 'Sword Art Online (2012)'
extension = '.mkv'
season = '01'
episode = 1

try:
    folder = r'D:\ServerTransfer\Update Server\%s\%s\S%s\\' % (video, name, season)

    #Check current file names
    print('Current names are: ')
    res = os.listdir(folder)
    print(res)
    
    # episode increase by 1 in each iteration
    # iterate all files from a directory
    for file_name in os.listdir(folder):
        # Construct old file name
        source = folder + file_name
        try:
            title = ''
            if episode < 100:
                # Adding the season & episode #'s
                destination = folder + name + '.S' + season + 'E0' + str(episode) + extension
                title = name + '.S' + season + 'E0' + str(episode)
##            elif episode < 100:
##                # Adding the season & episode #'s
##                destination = folder + name + '.S' + season + '.E0' + str(episode) + extension
            else:
                # Adding the season & episode #'s
                destination = folder + name + '.S' + season + 'E' + str(episode) + extension
                title = name + '.S' + season + 'E' + str(episode)
            # Renaming the file
            if file_name.endswith(extension):
                ffmpeg = FFmpeg(executable=r'c:\FFmpeg\bin\ffmpeg.exe').option("y").input(source).output(destination,codec="copy",title=title)
                ffmpeg.execute()
        except FFmpegFileNotFound as exception:
            print("An FFmpegFileNotFound exception has been occurred!")
            print("- Message from ffmpeg:", exception.message)
            print("- Arguments to execute ffmpeg:", exception.arguments)
        except FFmpegInvalidCommand as exception:
            print("An FFmpegInvalidCommand exception has been occurred!")
            print("- Message from ffmpeg:", exception.message)
            print("- Arguments to execute ffmpeg:", exception.arguments)
        except Exception as err:
            print(f'Unexptected {err=}, {type(err)=}')
            raise
        episode += 1
    print('All Files Renamed')
    print('New Names are')
    # verify the result
    res = os.listdir(folder)
    print(res)
except OSError as err:
    print('OS error:', err)
except Exception as err:
    print(f'Unexptected {err=}, {type(err)=}')
    raise

Here is what one of my print statements in the exception says is being executed

- Arguments to execute ffmpeg: ['c:\\FFmpeg\\bin\\ffmpeg.exe', '-y', '-i', 'D:\\ServerTransfer\\Update Server\\Anime\\Sword Art Online (2012)\\S01\\\\[Kosaka] Sword Art Online - 01 - The World of Swords (1080p AV1 10Bit BluRay OPUS) [73066623].mkv', '-codec', 'copy', '-title', 'Sword Art Online (2012).S01E01', 'D:\\ServerTransfer\\Update Server\\Anime\\Sword Art Online (2012)\\S01\\\\Sword Art Online (2012).S01E01.mkv']

I have tried different variations of trying to run ffmpeg via python including using subprocess and shlex libraries. I also tried moviepy, however no one has answered me back on their page.


Solution

  • -title is not a valid FFmpeg option, looking at matroska muxer options, what you probably want to do is along what @moken commented. Try

    .output(destination,codec="copy",metadata=f"title '{title}'")
    

    Note that your title has spaces, you need to put the title in single quotes.