gpt4 book ai didi

python - 在Python中输入不同文件夹中的文件作为ffmpeg的参数

转载 作者:行者123 更新时间:2023-12-04 23:03:28 26 4
gpt4 key购买 nike

我正在开发一个在 Python 中使用 ffmpeg 的程序,我正在尝试将一堆 PNG 图像堆叠到一个视频中。我想将代码保留在我的 Dropbox 上,但使用本地硬盘驱动器来完成工作,所以当我输入文件作为参数时,我想包含目录。下面的代码使原始输入文件很好,但是当我尝试使用 ffmpeg 开始管道时,它告诉我找不到输入文件。如果输入文件位于不同的目录中,是否有一些特殊的方法来格式化它?我有类似的代码可以很好地处理所有位于同一文件夹中的文件。谢谢!

import subprocess as sp

import numpy as np
import matplotlib.pyplot as plt

import os
import shutil

import tkinter.filedialog as tkFileDialog

FFMPEG_BIN = 'ffmpeg.exe'

def readImages(pathToImages):
filenames = os.listdir(path=pathToImages)
f = open("C:\\Users\johnwstanford\Desktop\outputfile.raw", "wb")

for file in filenames:
print(file)
image = plt.imread(pathToImages + '/' + file)
image = np.delete(image, 3, 2)*255

f.write(image.tobytes())
f.close()

readImages(tkFileDialog.askdirectory())

command2 = [FFMPEG_BIN,
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-s', '1600x1200',
'-pix_fmt', 'rgb24',
'-r', '25',
'-i', "C:\\Users\johnwstanford\Desktop\outputfile.raw",
"C:\\Users\johnwstanford\Desktop\output.mp4"]

pipe2 = sp.Popen(command2, stdin = sp.PIPE, stderr=sp.PIPE)
print(pipe2.communicate()[1])
pipe2.kill()
os.remove("C:\\Users\johnwstanford\Desktop\outputfile.raw")

最佳答案

你需要写\在正确的路径中:

利用

"C:\\Users\\johnwstanford\\Desktop\\outputfile.raw"

或者
r"C:\Users\johnwstanford\Desktop\outputfile.raw"
output.mp4 也需要相同的更改。文件。

您也可以尝试使用斜杠而不是反斜杠。

关于python - 在Python中输入不同文件夹中的文件作为ffmpeg的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906038/

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