你能直接从db中使用ffmpeg拆分文件吗?

时间:2014-03-31 20:16:30

标签: python ffmpeg subprocess

我正在使用ffmpeg和python拆分文件。如果我输入文件路径,我可以分割文件,但如果我从我的mongodb发送文件本身,则会出错。有没有办法让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)

但我不希望用户输入输入,我想管道变量。

1 个答案:

答案 0 :(得分:0)

我建议您使用django-multimedia来分割视频。

https://github.com/jbittel/django-multimedia