- 安装好环境后,引用下视频文件,准备生成封面截图。
instance = Video.objects.get(pk=pk)
dirt = {'test':'test'}
vfile = instance.fileuri.url
vpath = settings.BASE_DIR + vfile
dirt['vfile'] = vfile
dirt['vpath'] = vpath
result = os.path.exists(vpath)
dirt['vpath_flag'] = result
if result:
realname = os.path.basename(vfile)
image_name = 'uploads/video_images/' + os.path.splitext(realname)[0] + '.jpg'
image_path = settings.BASE_DIR + '/' + image_name
dirt['image_name'] = image_name
dirt['image_path'] = image_path
dirt['realname'] = realname
result2 = os.path.exists(image_path)
dirt['result2'] = result2
if not result2:
clip = VideoFileClip(vpath)
dirt['duration'] = clip.duration
clip.save_frame(image_name, t=2)
size = os.path.getsize(vpath)
dirt['size'] = size
2.很确定视频文件是存在的。
在本地跑运行,生成截图也没有问题,但是放到测试服务器上就一直报错。
IndexError at /admin/gp/video/9/change/
list index out of range
Request Method: POST
Request URL: http://gp.test.com/admin/gp/video/9/change/
Django Version: 1.11.6
Exception Type: IndexError
Exception Value:
list index out of range
Exception Location: /www/video/env/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py in ffmpeg_parse_infos, line 269
Python Executable: /www/video/env/bin/python2.7
Python Version: 2.7.11
Python Path:
['/www/video/gpSource',
'/www/video/env/bin',
'/www/video/env/lib/python27.zip',
'/www/video/env/lib/python2.7',
'/www/video/env/lib/python2.7/plat-linux2',
'/www/video/env/lib/python2.7/lib-tk',
'/www/video/env/lib/python2.7/lib-old',
'/www/video/env/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/www/video/env/lib/python2.7/site-packages']
Server time: 星期五, 18 一月 2019 10:49:30 +0800