0
我正在使用ffmpeg和python分割一個文件。如果我輸入文件路徑,我可以拆分文件,但是如果我從我的mongodb發送文件本身,則會出錯。有沒有辦法讓ffmpeg運行使用文件而不是文件的路徑?你可以直接從數據庫使用ffmpeg分割文件嗎?
Python代碼:
args = [ffmpeg_binary,
"-v", "quiet",
"-y", "-i", video_file, "-vcodec", "copy", "-acodec", "copy",
"-ss", "00:00:00", "-t", "00:00:10", "-sn",
output_file_name ]
pipe = sp.Popen(args)
如果video_file是gridfs.grid_file.GridOut
對象或(gridfs.grid_file.GridOut object).read()
,我得到:
Traceback (most recent call last):
File "C:/dev/youniversity/test.py", line 21, in <module>
split_vid_from_file(vid_file)
File "C:\dev\youniversity\src\lib\ffmpeg_lib.py", line 107, in split_vid_from_file
pipe = sp.Popen(args)
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
TypeError: must be string without null bytes or None, not str
如何直接從數據庫拆分視頻?
編輯:我發現,你可以這樣做:在變量
... "-y", "-", ...
pipe = sp.Popen(args, stdin=sp.PIPE)
,但我不希望用戶鍵入信息,我想管。
爲什麼我應該使用他們的包裝而不是我一直在做的?有沒有好處? – Jeff