use Image.frombytes, pass int not float
This commit is contained in:
parent
b3deeb1c19
commit
82ddda4fb7
1 changed files with 14 additions and 14 deletions
|
@ -27,8 +27,6 @@ class Video(object):
|
||||||
samplerate = 48000
|
samplerate = 48000
|
||||||
|
|
||||||
def __init__(self, path, height, audio, video_callback, done_callback):
|
def __init__(self, path, height, audio, video_callback, done_callback):
|
||||||
|
|
||||||
|
|
||||||
self.height = height
|
self.height = height
|
||||||
self.video = self.height > 0
|
self.video = self.height > 0
|
||||||
self.audio = audio
|
self.audio = audio
|
||||||
|
@ -71,8 +69,8 @@ class Video(object):
|
||||||
frame = rms(frame, 0) / self.samplerate
|
frame = rms(frame, 0) / self.samplerate
|
||||||
self.volume.append(frame)
|
self.volume.append(frame)
|
||||||
timestamp += 1/self.framerate
|
timestamp += 1/self.framerate
|
||||||
#m = max(max(self.volume, key=lambda v: max(v)))
|
# m = max(max(self.volume, key=lambda v: max(v)))
|
||||||
#self.volume = [(v[0]/m, v[1]/m) for v in self.volume]
|
# self.volume = [(v[0]/m, v[1]/m) for v in self.volume]
|
||||||
self.done_callback(self.volume if self.audio else [])
|
self.done_callback(self.volume if self.audio else [])
|
||||||
|
|
||||||
def get_duration(self):
|
def get_duration(self):
|
||||||
|
@ -125,7 +123,10 @@ def video(path, height=96, info=None, framerate=FPS):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
first = False
|
first = False
|
||||||
|
if hasattr(Image, 'fromstring'):
|
||||||
yield Image.fromstring('RGB', (width, height), data)
|
yield Image.fromstring('RGB', (width, height), data)
|
||||||
|
else:
|
||||||
|
yield Image.frombytes('RGB', (width, height), data)
|
||||||
|
|
||||||
def audio(path, info=None, samplerate=48000, framerate=FPS):
|
def audio(path, info=None, samplerate=48000, framerate=FPS):
|
||||||
depth = 2
|
depth = 2
|
||||||
|
@ -148,13 +149,12 @@ def audio(path, info=None, samplerate=48000, framerate=FPS):
|
||||||
'-f', 'wav',
|
'-f', 'wav',
|
||||||
'-'
|
'-'
|
||||||
]
|
]
|
||||||
#print(' '.join(cmd))
|
# print(' '.join(cmd))
|
||||||
p = subprocess.Popen(cmd,
|
p = subprocess.Popen(cmd,
|
||||||
bufsize=bufsize,
|
bufsize=bufsize,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=open('/dev/null', 'w'),
|
stderr=open('/dev/null', 'w'),
|
||||||
close_fds=True)
|
close_fds=True)
|
||||||
|
|
||||||
chunk = int(nbytes / framerate)
|
chunk = int(nbytes / framerate)
|
||||||
first = True
|
first = True
|
||||||
while True:
|
while True:
|
||||||
|
@ -167,7 +167,7 @@ def audio(path, info=None, samplerate=48000, framerate=FPS):
|
||||||
else:
|
else:
|
||||||
first = False
|
first = False
|
||||||
audio = np.fromstring(data, dtype="int16")
|
audio = np.fromstring(data, dtype="int16")
|
||||||
audio = audio.reshape((len(audio)/channels,channels)).astype('float')
|
audio = audio.reshape((int(len(audio)/channels), channels)).astype('float')
|
||||||
yield audio
|
yield audio
|
||||||
|
|
||||||
def rms(x, axis=None):
|
def rms(x, axis=None):
|
||||||
|
@ -182,7 +182,7 @@ class AspectRatio(fractions.Fraction):
|
||||||
ratio.append(1)
|
ratio.append(1)
|
||||||
numerator = ratio[0]
|
numerator = ratio[0]
|
||||||
denominator = ratio[1]
|
denominator = ratio[1]
|
||||||
#if its close enough to the common aspect ratios rather use that
|
# if its close enough to the common aspect ratios rather use that
|
||||||
if abs(numerator/denominator - 4/3) < 0.03:
|
if abs(numerator/denominator - 4/3) < 0.03:
|
||||||
numerator = 4
|
numerator = 4
|
||||||
denominator = 3
|
denominator = 3
|
||||||
|
|
Loading…
Reference in a new issue