【问题标题】:Programmatically generate thumbnail CAP for small video以编程方式为小视频生成缩略图 CAP
【发布时间】:2011-06-15 21:19:39
【问题描述】:

python如何为视频制作一个简单的上限。

Ideia:拍摄 9 张快照,连续放置 9 次(在时间线上),然后在 JGP 中替换

我应该怎么做?

PIL 是唯一的方法吗? (做我想做的事并不容易,对吧?)

没有任何模块吗(python 看到有 GREAT 模型几乎可以做任何事情,还是我不走运)

例子:

Movie lenght = 10 min
T1= snapshot of 1 min
T2= snapshot of 2 min
......
T9= snapshot of 9 min
   |   |
 T1| T2| T3
---+---+---
 T4| T5| T6
---+---+---
 T7| T8| T9
   |   |

【问题讨论】:

    标签: python video thumbnails python-imaging-library


    【解决方案1】:

    这是我前一段时间所做的快速更改,使用 ffmpeg 进行帧提取和 PIL 创建完整的拇指图像。

    import os, sys
    from PIL import Image
    
    # Use "ffmpeg -i <videofile>" to get total length by parsing the error message
    chout, chin, cherr = os.popen3("ffmpeg -i %s" % sys.argv[1])
    out = cherr.read()
    dp = out.index("Duration: ")
    duration = out[dp+10:dp+out[dp:].index(",")]
    hh, mm, ss = map(float, duration.split(":"))
    total = (hh*60 + mm)*60 + ss
    
    # Use "ffmpeg -i <videofile> -ss <start> frame<nn>.png" to extract 9 frames
    for i in xrange(9):
        t = (i + 1) * total / 10
        os.system("ffmpeg -i %s -ss %0.3fs frame%i.png" % (sys.argv[1], t, i))
    
    # Make a full 3x3 image by pasting the snapshots
    full = None
    for y in xrange(3):
        for x in xrange(3):
            img = Image.open("frame%i.png" % (y*3+x))
            w, h = img.size
            if full is None:
                full = Image.new("RGB", (w*3, h*3))
            full.paste(img, (x*w, y*h))
    
    # Save result
    full.save("thumbs.png")
    

    【讨论】:

      猜你喜欢
      • 2011-02-19
      • 2018-08-18
      • 2012-01-26
      • 2017-10-14
      • 2012-09-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      相关资源
      最近更新 更多