在这里,我尝试将第一个和第二个 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)
请帮我。提前非常感谢。