gpt4 book ai didi

python - 我如何将字符串解析为 subprocess.Popen 的输入?

转载 作者:行者123 更新时间:2023-11-28 19:24:06 24 4
gpt4 key购买 nike

在这里,我尝试将第一个和第二个 30 秒长的视频文件从“path/connect.flv”剪切为文件 output1.flv 和 output2.flv。有用。我能够将这两个文件连接起来形成一个 60 秒长的新文件“final.flv”。所以这有效,我得到输出 output1.flv [30sec]、output2.flv[30sec] 和 final.flv[1min]。

这是python代码:

import subprocess

ffmpeg_command1 = ["ffmpeg", "-i", "/home/xincoz/test/connect.flv", "-acodec", "copy", "-ss", "00:00:00", "-t", "00:00:30", "/home/xincoz/test/output1.flv"]

ffmpeg_command2 = ["ffmpeg", "-i", "/home/xincoz/test/connect.flv", "-acodec", "copy", "-ss", "00:00:30", "-t", "00:00:30", "/home/xincoz/test/output2.flv"]

ffmpeg_command3 = ["mencoder", "-forceidx", "-ovc", "copy", "-oac", "pcm", "-o", "/home/xincoz/test/final.flv", "/home/xincoz/test/output1.flv", "/home/xincoz/test/output2.flv"]

subprocess.call(ffmpeg_command1)

subprocess.call(ffmpeg_command2)

subprocess.Popen(ffmpeg_command3)

但我真正想要的是连接两个字符串 out1 和 out2,并将这两个字符串连接到一个文件中,而不是连接“/home/xincoz/test/output1.flv”和“/home/xincoz/test/output2.flv” ”。那么我如何将字符串 out1 和 out2 解析为 mencoder 的输入呢?请编辑我的代码以获得结果。

import subprocess,os

ffmpeg_command = ["ffmpeg", "-i", "/home/xincoz/test/connect.flv", "-acodec", "copy", "-ss", "00:00:00", "-t", "00:00:30","-f", "flv", "pipe:1"]

p = subprocess.Popen(ffmpeg_command,stdout=subprocess.PIPE)

out1, err = p.communicate()

ffmpeg_command1 = ["ffmpeg", "-i", "/home/xincoz/test/connect.flv", "-acodec", "copy", "-ss", "00:00:30", "-t", "00:00:30","-f", "flv", "pipe:1"]

p1 = subprocess.Popen(ffmpeg_command1,stdout=subprocess.PIPE)

out2, err1 = p1.communicate()

ffmpeg_command2 = ["mencoder", "-forceidx", "-ovc", "copy", "-oac", "pcm", "-o", "/home/xincoz/test/final.flv", out1, out2 ]

p2=subprocess.Popen(ffmpeg_command2)

请帮帮我。非常感谢。

最佳答案

你没有说你的代码是如何失败的,但看起来你正在尝试将 MEncoder 二进制字符串作为命令行参数。 http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-selecting-input.html说你可以在命令行中给出文件名,而不是文件的内容。

所以回答你的问题:

with open('merged.flv', 'wb') as f:
f.write(out1 + out2)

ffmpeg_command2 = ["mencoder", "your", "other", "args", "merged.flv"]

关于python - 我如何将字符串解析为 subprocess.Popen 的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17317595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com