Skip to content

Commit 623383f

Browse files
committedJul 5, 2016
Added loopcount, fixed seeking issue
1 parent f516426 commit 623383f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed
 

‎mediadecoder/decoder.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# MoviePy
88
try:
99
from moviepy.video.io.VideoFileClip import VideoFileClip
10-
from moviepy.tools import cvsecs
1110
import numpy as np
1211
except ImportError as e:
1312
print("""Error importing dependencies:
@@ -126,6 +125,8 @@ def reset(self):
126125
self.status = UNINITIALIZED
127126
self.clock.reset()
128127

128+
self.loop_count = 0
129+
129130
def load_media(self, mediafile, play_audio=True):
130131
""" Loads a media file to decode.
131132
@@ -323,7 +324,8 @@ def seek(self, value):
323324
"""
324325
# Pause the stream
325326
self.pause()
326-
self.clock.time = value
327+
# Make sure the movie starts at 1s as 0s gives trouble.
328+
self.clock.time = max(0.5, value)
327329
logger.debug("Seeking to {} seconds; frame {}".format(self.clock.time,
328330
self.clock.current_frame))
329331
if self.audioformat:
@@ -334,7 +336,7 @@ def seek(self, value):
334336
def rewind(self):
335337
""" Rewinds the video to the beginning.
336338
Convenience function simply calling seek(0). """
337-
self.seek(0)
339+
self.seek(0.5)
338340

339341
def __calculate_audio_frames(self):
340342
""" Aligns audio with video.
@@ -374,7 +376,8 @@ def __render(self):
374376
if self.loop:
375377
logger.debug("Looping: restarting stream")
376378
# Seek to the start
377-
self.seek(0)
379+
self.rewind()
380+
self.loop_count += 1
378381
else:
379382
# End of stream has been reached
380383
self.status = EOS

‎mediadecoder/soundrenderers/pyaudiorenderer2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, audioformat, queue=None):
3939
self.stream = self.pa.open(
4040
channels = audioformat["nchannels"],
4141
rate = audioformat["fps"],
42-
frames_per_buffer = audioformat['buffersize'],
42+
#frames_per_buffer = audioformat['buffersize']/2,
4343
format = pyaudio.get_format_from_width(audioformat["nbytes"]),
4444
output = True,
4545
)

‎mediadecoder/soundrenderers/sounddevicerenderer2.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, audioformat, queue=None):
3636
global sd
3737
import sounddevice as sd
3838

39+
# Init thread
3940
super(SoundrendererSounddevice, self).__init__()
4041

4142
if not queue is None:

0 commit comments

Comments
 (0)
Please sign in to comment.