开发者

Python video thumbnails but with easily available libraries (no PyMedia!)

开发者 https://www.devze.com 2023-03-30 12:31 出处:网络
I want to include video thumbnails as part of my python app. However, I want to distribute it easily for use on Ubuntu mainly (plus other distros, of course, but Ubuntu is my main t开发者_如何学编程ar

I want to include video thumbnails as part of my python app. However, I want to distribute it easily for use on Ubuntu mainly (plus other distros, of course, but Ubuntu is my main t开发者_如何学编程arget).

However! PyMedia, which is often suggested, is not available as far as I'm aware in the default repositories. So, is there an alternative? I've noticed that nautilus makes screenshots so there has to be a way.


MoviePy can do thumbnail generation very easily:

from moviepy.editor import *
clip = VideoFileClip("example.mp4")
clip.save_frame("thumbnail.jpg",t=1.00)

http://zulko.github.io/moviepy/index.html


Nautilus uses GStreamer. Python bindings are available on Ubuntu in the package python-gst. Doc


I modified the script here and was able to get it to work on Natty:

import gnome.ui
import gnomevfs

#~ path = "jump.png"
#~ uri = gnomevfs.get_uri_from_local_path(path) # gives err
uri = 'file:///home/username/Desktop/jump.png'
mime = gnomevfs.get_mime_type(uri)

thumbFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_LARGE)
if thumbFactory.can_thumbnail(uri ,mime, 0):
    thumbnail = thumbFactory.generate_thumbnail(uri, mime)
    if thumbnail != None:
        print 'saving'
        thumbFactory.save_thumbnail(thumbnail, uri, 0)

Next at console:

cd ~/.thumbnails/normal
ls -lrt  # show last modified
gnome-open 055ff069f4a9f6521e4363cea6cd3cce.png  # use last file
0

精彩评论

暂无评论...
验证码 换一张
取 消