forked from puzzlet/pytranscode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
splash.py
65 lines (46 loc) · 1.81 KB
/
splash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Snapshot Grabber
================
Uses ffmpeg to grab a series of snapshots of a video file for thumbnail
and/or splash use
Outputs a series of images with the filenames set using:
input filename + snapshot location (seconds) + jpg
The filenames are appended to the opject 'images' list
Usage:
------
>>> this = SplashImages(input_file='video.avi', count=5)
>>> this.get_images()
>>> print this.images
"""
from video_info import *
import re
class SplashImages:
def __init__(self, input_file=None, count=None):
self.input_file = input_file
self.count = count
self.images = []
def get_images(self):
if self.input_file:
if self.count:
split = self.get_info()
split2 = split
for a in xrange(self.count):
self.run_command(split2)
split2 += split
def get_info(self):
info = VideoObject(self.input_file)
length = info.length
# we increment the count + 1 in order to never hit the EOF
split = info.length / (self.count + 1)
return split
def run_command(self, loc):
output_file = self.input_file
output_file = output_file + '.' + str(int(loc)) + '.jpg'
commandline = 'ffmpeg -y -i %s -f mjpeg -ss %s -vframes 1 -an %s' % (self.input_file, loc, output_file)
outcode = Popen(commandline, stdout=PIPE, stderr=PIPE)
self.output = outcode.stderr.read()
self.images.append(output_file)
#Uncomment to test
#this = SplashImages(input_file='video.avi', count=5)
#this.get_images()
#print this.images