简体   繁体   English

如何在 macOS 上使用 Python 编写 ffmpeg 日志文件?

[英]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.我想在 macOS 上使用 Python 脚本为多个视频输入文件编写 ffmpeg 日志文件。 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:但我收到以下 ffmpeg 错误:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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