-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_class.py
142 lines (120 loc) · 4.98 KB
/
video_class.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# ---------------------
# GUI-related libraries
from Tkinter import *
# -----------------------
# python image library
from PIL import Image, ImageTk, ImageDraw, ExifTags
# -----------------------
# all command line stuff
import os, sys, subprocess, tempfile
# -----------------------
# ===================
# video class
# ===================
class video_class(Frame):
def __init__(self, id, name, files, parent, root, active, rate=200):
self.id = id
self.name = name
self.parent = parent
self.files = files
self.root = root
self.active = active
self.rate = rate
self.draw()
def draw(self):
self.bg = 'black'
if self.active:
self.bg = '#035'
print 'video class files', len(self.files)
img = Image.open(self.files[len(self.files)/2].filename)
self.image = ImageTk.PhotoImage(img.resize((100, img.height * (100) / img.width), Image.ANTIALIAS))
self.label = Label(self.parent, image=self.image,
borderwidth=0,
compound="center",
highlightthickness = 0,
width=100+10,
height=10 + (img.height * (100) / img.width),
bg=self.bg)
self.label.bind('<ButtonPress-1>', self.click)
self.label.bind('<Enter>', self.enter)
self.label.bind('<Leave>', self.leave)
self.label.pack(fill=X)
self.name_var = StringVar()
self.name_var.set(self.name)
self.name_var.trace("w", self.name_call)
self.name_entry = Entry(self.parent, textvariable=self.name_var, bg=self.bg, fg='white', borderwidth=0, justify=CENTER)
self.name_entry.pack()
self.name_entry.focus_force()
self.scale = Scale(self.parent, from_=1, to=500, orient=HORIZONTAL, bg=self.bg, fg='white', highlightthickness=0, borderwidth=0, troughcolor=self.bg, label='fps', command=self.frame_rate)
self.scale.set(self.rate)
self.scale.pack(fill=X)
def name_call(self, *args):
self.name = self.name_var.get()
def frame_rate(self, *args):
self.rate = self.scale.get()
def click(self, event):
self.root.select_video(self.id)
def enter(self, event):
if self.active:
self.label.configure(bg='#35b')
else:
self.label.configure(bg='#999')
def leave(self, event):
self.label.configure(bg=self.bg)
def make_video(self):
images = ""
for file in self.files:
images += " " + file.filename
print 'saving images', images
rtndir = os.getcwd()
tmpdir = tempfile.gettempdir() + '\\test' + '\\video' + repr(self.id)
command = ['rd', '/s', '/q', tmpdir]
print 'rmdir command: ', command
try:
bash = subprocess.check_output(command, shell=True)
print bash
except:
pass
command = ['mkdir', tmpdir]
print 'mkdir command: ', command
try:
bash = subprocess.check_output(command, shell=True)
print bash
except:
pass
offset = 30
if self.scale.get() > 30:
offset = 1
index = 1
zeros = 8
for i in range(1, len(self.files)+1):
for j in range(0, offset):
link_name = str(index)
link_name = "0" * (zeros-len(link_name))+ link_name
command = ['mklink', tmpdir + '\\' + link_name + '.' + self.files[i-1].filename.split('.')[-1], self.files[i-1].directory.replace('/','\\') + '\\' + self.files[i-1].filename]
index += 1
try:
bash = subprocess.check_output(command, shell=True)
## print bash
except:
pass
command = 'ffmpeg'
os.chdir(tmpdir)
print 'changed directory to', tmpdir
command = [command, '-r', repr(self.scale.get()*offset), '-start_number', '1', '-i', '%0'+repr(zeros)+'d.' + self.files[0].filename.split('.')[-1], '-b', '8000k', '-vcodec', 'libx264', '-pix_fmt', 'yuv420p', self.name.replace(' ','.') + '.avi']
print 'ffmpeg command: ', command
try:
bash = subprocess.check_output(command, shell=True)
print bash
except:
pass
command = ['copy', self.name.replace(' ','.') + '.avi', self.root.save_directory.replace('/','\\') + '\\' + self.name.replace(' ','.') + '.avi']
print 'copy command: ', command
try:
bash = subprocess.check_output(command, shell=True)
print bash
except:
pass
os.chdir(rtndir)
##bash = subprocess.Popen([command], shell=True)
# -----------------