use Image.frombytes, pass int not float

This commit is contained in:
j 2016-06-16 02:47:34 +02:00
parent b3deeb1c19
commit 82ddda4fb7

View file

@ -27,8 +27,6 @@ class Video(object):
samplerate = 48000
def __init__(self, path, height, audio, video_callback, done_callback):
self.height = height
self.video = self.height > 0
self.audio = audio
@ -71,10 +69,10 @@ class Video(object):
frame = rms(frame, 0) / self.samplerate
self.volume.append(frame)
timestamp += 1/self.framerate
#m = max(max(self.volume, key=lambda v: max(v)))
#self.volume = [(v[0]/m, v[1]/m) for v in self.volume]
# m = max(max(self.volume, key=lambda v: max(v)))
# self.volume = [(v[0]/m, v[1]/m) for v in self.volume]
self.done_callback(self.volume if self.audio else [])
def get_duration(self):
return self.duration
@ -125,7 +123,10 @@ def video(path, height=96, info=None, framerate=FPS):
return
else:
first = False
yield Image.fromstring('RGB', (width, height), data)
if hasattr(Image, 'fromstring'):
yield Image.fromstring('RGB', (width, height), data)
else:
yield Image.frombytes('RGB', (width, height), data)
def audio(path, info=None, samplerate=48000, framerate=FPS):
depth = 2
@ -148,13 +149,12 @@ def audio(path, info=None, samplerate=48000, framerate=FPS):
'-f', 'wav',
'-'
]
#print(' '.join(cmd))
# print(' '.join(cmd))
p = subprocess.Popen(cmd,
bufsize=bufsize,
stdout=subprocess.PIPE,
stderr=open('/dev/null', 'w'),
close_fds=True)
bufsize=bufsize,
stdout=subprocess.PIPE,
stderr=open('/dev/null', 'w'),
close_fds=True)
chunk = int(nbytes / framerate)
first = True
while True:
@ -167,7 +167,7 @@ def audio(path, info=None, samplerate=48000, framerate=FPS):
else:
first = False
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
def rms(x, axis=None):
@ -182,7 +182,7 @@ class AspectRatio(fractions.Fraction):
ratio.append(1)
numerator = ratio[0]
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:
numerator = 4
denominator = 3