2016-01-20 65 views
1

我正在使用Python中的ffmpeg編寫程序,我試圖將一堆PNG圖像堆疊到視頻中。我想保留我的Dropbox上的代碼,但使用本地硬盤來完成這項工作,所以當我輸入文件作爲參數時,我想包括該目錄。下面的代碼使得原始輸入文件很好,但是當我嘗試用ffmpeg開始一個管道時,它告訴我它找不到輸入文件。如果輸入文件位於不同的目錄中,是否有一些特殊的方法來格式化?我有類似的代碼工作正常與所有位於同一文件夾中的文件。謝謝!在不同的文件夾中輸入文件作爲Python中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") 

回答

0

你需要寫在正確的路徑\

使用

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

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

需要爲output.mp4文件相同的更改。

您也可以嘗試使用斜槓而不是反斜槓。

0

我搞砸了一些,最後發現它說的是無法找到二進制文件。我添加了二進制文件的路徑,它現在似乎工作。