-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·38 lines (32 loc) · 1.19 KB
/
test.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
#!/usr/bin/python
import gobject
import gst
from gst.extend import discoverer
import os
import sys
gobject.threads_init()
main_loop = gobject.MainLoop()
def human_readable_size(size):
if size == 0:
return '0B'
assert size >= 1
good = (pair for pair in human_readable_size.denominations if size >= pair[0])
while True:
try:
selected = good.next()
except StopIteration:
break
return '{:.1f}{}'.format(float(size) / selected[0], selected[1])
human_readable_size.denominations = [(1, 'B'), (1 << 10, 'kB'), (1 << 20, 'MB'), (1 << 30, 'GB')]
def on_discovered(discoverer, is_media, size):
if discoverer.is_video:
seconds = discoverer.videolength / gst.SECOND
print 'V {}x{} {}s {}/s'.format(discoverer.videowidth, discoverer.videoheight, seconds, human_readable_size(size / seconds))
elif discoverer.is_audio:
seconds = discoverer.audiolength / gst.SECOND
print 'A {}s {}/s'.format(seconds, human_readable_size(size / seconds))
main_loop.quit()
d = discoverer.Discoverer(sys.argv[1])
d.connect('discovered', on_discovered, os.stat(sys.argv[1]).st_size)
gobject.idle_add(d.discover)
main_loop.run()