qq_40812445 2019-01-18 10:36 采纳率: 0%
浏览 977

moviepy.editor VideoFileClip(vpath) 报找不到文件

  1. 安装好环境后,引用下视频文件,准备生成封面截图。
        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

图片说明
图片说明图片说明

  • 写回答

1条回答 默认 最新

  • 正一1215 2019-01-23 12:57
    关注

    应该是文件路径的问题,到文件目录下pwd检查路径。以下是我在截取封面的时候所用到的方法,因为我的项目是python3写的,在程序中调用的该文件。希望对你有所帮助。

    import os
    import sys
    import time
    from ffvideo import VideoStream
    import Image
    #ffmpeg -i WSWDA1768844088.mp4 -b 800k -strict -2 output.mp4
    BASE_DIR =os.path.dirname( os.path.dirname(os.path.abspath(__file__)))
    print sys.argv[1]
    path = BASE_DIR+sys.argv[1]
    pil_image = VideoStream( path).get_frame_at_sec(0.01).image()
    picturepath = path[:path.rindex('.')]
    pil_image.save(picturepath+'.jpeg')
    im = Image.open(picturepath+'.jpeg')
    (x,y) = im.size
    if x < 400 and y < 400:
        x_s=s
        y_s=y
    else:
        x_s = 400  # define standard widt
        y_s = y
        while x_s > 400 or y_s > 400:
            x_s = x_s - 1
            if x_s < 400:
                print
                x_s, y_s, x, y
                y_s = int(y * x_s * 1.0 / x)
                print
                y_s
            if x_s > 400:
                print
                x_s, y_s, x, y
                y_s = int(y * x * 1.0 / x_s)
    out = im.resize((x_s,y_s),Image.ANTIALIAS) #resize image with high-quality
    out.save(picturepath+'.jpeg')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题