python - python中子进程命令行中没有反斜杠的引号

标签 python ffmpeg subprocess

我正在尝试使用python中的ffmpeg。我需要执行的命令是:

ffmpeg -i test_file-1kB.mp4 -i test_file.mp4 -filter_complex psnr="stats_file=test_file.mp4-1kB.psnr" -f null -

但是,传递给子进程的输出看起来像是用反斜杠转义双引号,如下所示:
In[1]: print(subprocess.list2cmdline(psnr_args))
ffmpeg -i test_file-1kB.mp4 -i test_file.mp4 -filter_complex psnr=\"stats_file=test_file.mp4-1kB.psnr\" -f null -

要使用子进程,我一次将一个命令行参数构建到一个列表中,然后将该列表传递给子进程。
    psnr_args = []
    psnr_args.append("ffmpeg")

    #add first input, the encoded video
    psnr_args.append("-i")
    psnr_args.append(full_output_file_name)

    #add second input, the original video
    psnr_args.append("-i")
    psnr_args.append(video_file)

    #Setup the psnr log file
    psnr_args.append("-filter_complex")
    psnr_args.append('psnr="stats_file=%s.psnr"' % vstats_abs_filename )

    #Output the video to null
    psnr_args.append("-f")
    psnr_args.append("null")
    psnr_args.append("-")
    print(subprocess.list2cmdline(psnr_args))
    run_info_psnr = subprocess.run(psnr_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

最佳答案

经过更多的摆弄,我找到了一个适用于这种情况但可能不适用于所有情况的解决方案。如果我使用双引号作为外引号,单引号作为内引号,子进程的输出在同一位置使用单引号,没有反斜杠。这对于 ffmpeg 是可以接受的。但是,对于双引号是唯一解决方案的其他人,它不会是一个修复。

psnr_args.append("psnr='stats_file=%s.psnr'" % vstats_abs_filename )

子进程的输出如下所示:
In[1]: print(subprocess.list2cmdline(psnr_args))
ffmpeg -i test_file-1kB.mp4 -i test_file.mp4 -filter_complex psnr='stats_file=test_file.mp4-1kB.psnr' -f null -

关于python - python中子进程命令行中没有反斜杠的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46854568/

相关文章:

python - 如何将tab键发送到python子进程stdin

python - 如何立即停止正在运行单元测试的 python 子进程?终止并杀死不起作用

Python pandas,我可以倒序显示 value_counts() 吗?

python - 尝试 - 除了 python

windows - FFMPEG - 批量转换子文件夹

Python - youtube-dl.utils.DownloadError : ERROR: audio conversion failed: file: mp3 invalid argument

node.js - Fluent ffmpeg如何用户保存回调

python - 计算numpy中两个向量之间的成对差异?

python - 使用 .Replace 时创建新行

python - FileNotFoundError:[WinError 2]尝试使用pysndfx时,系统找不到指定的文件