python - 以编程方式为小视频生成缩略图 CAP

标签 python video thumbnails python-imaging-library

python如何为视频制作一个简单的帽子。

Ideia:为 9 个均匀放置(在时间轴上)时间拍摄 9 个快照,然后在 JGP 中置换

我应该怎么做?

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

没有任何模块吗(python 似乎对几乎所有东西都有很好的模型,或者我运气不好)

例子:

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
   |   |

最佳答案

这是对我前段时间所做的事情的快速更改,使用 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")

关于python - 以编程方式为小视频生成缩略图 CAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4805563/

相关文章:

python - Telethon 问题,需要从 channel 读取消息

python - 如何使用 Tensorflow 模型进行预测?

python - 在opencv + python中处理帧时实时流被延迟

python - 枕头返回错误 : "IOError: image file is truncated (6 bytes not processed)"

c# - Windows API 代码包 - ShellFile 不生成 PDF 位图

python - 在Python中的单词列表中搜索带有in运算符的子字符串

python - Django 代理模型返回父模型

ios - 在 SceneKit 中使用 MPMoviePlayerController 作为纹理

javascript - 从JS/JQUERY channel 获取最新的YouTube(和抽搐)视频URL

html - 缩略图画廊高度问题