简体   繁体   中英

How can I write a ffmpeg log file with Python on macOS?

I want to write ffmpeg log files for several video input files with a Python script on macOS. Here is my try:

def create_error_logfile(videoinput):
    cmds = [
        "/applications/ffmpeg",
        "-v", 
        "error",
        "-i",
        videoinput, 
        "-f", 
        "null", 
        "-",
        "2>",
        videoinput + ".log"
    ]
    subprocess.Popen(cmds).wait()

for root, directories, files in os.walk(input_path):
    for video in files:
        videoinput = os.path.join(root, video)
        create_error_logfile(videoinput)

But I get the following ffmpeg error:

Unable to find a suitable output format for '2>'
2>: Invalid argument

What am I doing wrong? Thanks in advance!

Something like this should work:

def create_error_logfile(videoinput):
    cmds = [
        "/applications/ffmpeg",
        "-v", 
        "error",
        "-i",
        videoinput, 
        "-f", 
        "null", 
        "-"
    ]
    with open(f'{videoinput}.log','wt') as f:
        subprocess.run(cmds,stderr=f,universal_newlines=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM