def play_next(self): if self.destroyed: return try: item = self.playlist.next() except StopIteration: for each in _play_list_finished_handlers: each(self.constructor_params, self.weak_texture.object) self._destroy() return if item.lower().startswith('http'): stream = blue.BlueNetworkStream(item) else: if blue.remoteFileCache.FileExists( item) and not blue.paths.FileExistsLocally(item): blue.paths.GetFileContentsWithYield(item) if self.destroyed: return stream = blue.paths.open(item, 'rb') self.video = videoplayer.VideoPlayer(stream, None) self.video.bgra_texture = self.weak_texture.object self.video.on_state_change = self._on_state_change self.video.on_create_textures = self._on_video_info_ready self.video.on_error = self._on_error
def __init__(self, mpd, base_url, base_dst, options): self.config = Config(mpd, base_url) self.quality_rep_map = {} self.file_writer = common.FileWriter(base_dst) for rep in self.config.reps: self.quality_rep_map[rep['bandwidth']] = rep self.bitrates = self.quality_rep_map.keys() self.bitrates.sort() utility_offset = -math.log(self.bitrates[0]) self.utilities = [math.log(b) + utility_offset for b in self.bitrates] self.buffer_size = options.buffer_size * 1000 self.verbose = options.verbose self.segment_time = self.config.reps[0]['dur_s'] * 1000 self.bandwidth_changerscript_path = options.bandwidth_changerscript_path self.player = videoplayer.VideoPlayer(self.segment_time, self.utilities, self.bitrates) self.sess = tf.Session() self.quality_switch = 0 self.actor = a3c.ActorNetwork(self.sess, state_dim=[S_INFO, S_LEN], action_dim=A_DIM, learning_rate=ACTOR_LR_RATE) self.critic = a3c.CriticNetwork(self.sess, state_dim=[S_INFO, S_LEN], learning_rate=CRITIC_LR_RATE) self.sess.run(tf.initialize_all_variables()) self.saver = tf.train.Saver() # restore neural net parameters self.nn_model = NN_MODEL if self.nn_model is not None: # nn_model is the path to file self.saver.restore(self.sess, self.nn_model) print("Model restored.") self.init_action = np.zeros(A_DIM) self.init_action[DEFAULT_QUALITY] = 1 self.s_batch = [np.zeros((S_INFO, S_LEN))] self.a_batch = [self.init_action] self.r_batch = [] self.last_quality = DEFAULT_QUALITY self.last_bit_rate = DEFAULT_QUALITY # need this storage, because observation only contains total rebuffering time # we compute the difference to get self.last_total_rebuf = 0 self.video_chunk_count = 0 self.chunk_fetch_time = 0 self.chunk_size = 0 self.ptime = 0
def load_rest(self): """delay load""" self.station_man = StationManager(self, self.test_channel_path) self.station_man.connect("added", self.on_station_added) self.station_man.connect("load-channel-done", self.on_station_load_done) self.station_man.load_channels() self.combobox_station.set_active(0) self.install_actions() self.player = videoplayer.VideoPlayer(self) self.player.connect("queue-empty", self.on_player_queue_empty) self.player.start_proc_monitor()
def __init__(self, mpd, base_url, base_dst, options): # config can be the mpd file self.config = Config(mpd, base_url) self.quality_rep_map = {} self.file_writer = common.FileWriter(base_dst) for rep in self.config.reps: self.quality_rep_map[rep['bandwidth']] = rep self.bitrates = self.quality_rep_map.keys() self.bitrates.sort() utility_offset = -math.log(self.bitrates[0]) # so utilities[0] = 0 self.utilities = [math.log(b) + utility_offset for b in self.bitrates] self.buffer_size = options.buffer_size * 1000 self.verbose = options.verbose self.quality_switch = 0 # Segment time is in ms self.segment_time = self.config.reps[0]['dur_s'] * 1000 self.player = videoplayer.VideoPlayer(self.segment_time, self.utilities, self.bitrates) self.bandwidth_changerscript_path = options.bandwidth_changerscript_path
def _init(self, video_local=None, video_remote=None): if self._deleted: return if video_local: if blue.remoteFileCache.FileExists( video_local ) and not blue.paths.FileExistsLocally(video_local): blue.paths.GetFileContentsWithYield(video_local) if self._deleted: return stream = blue.paths.open(video_local, 'rb') elif video_remote: stream = blue.BlueNetworkStream(video_remote) else: raise ValueError() self.video = videoplayer.VideoPlayer(stream, None) self.video.bgra_texture = self.weak_texture.object self.video.on_state_change = self._on_state_change self.video.on_create_textures = self._on_video_info_ready self.video.on_error = self._on_error
def test(): screen = pygame.display.set_mode((1280, 720)) clock = pygame.time.Clock() #mov = Movie("Clockwork", "rsc_testing/fsf.mp4") #mov.play() player = videoplayer.VideoPlayer("fbms.mp4","rsc_testing") Thread(target=player.update()).start() while True: screen.fill((255, 255, 255)) player.render(screen) #mov.blit(screen, (0, 0)) # mov.blit_frame(screen,(100,100),20000) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() pygame.mixer.quit() sys.exit() clock.tick(60) pygame.display.update()
def SetVideoPath(self, path, audioTrack=0, videoLoop=False): self._DestroyVideo() self.path = path self.audioTrack = audioTrack self.videoLoop = videoLoop def prefetch(): blue.paths.GetFileContentsWithYield(path) if self._isFetchingFile and path == self.path: self._isFetchingFile = False self.SetVideoPath(path, audioTrack, videoLoop) if path.lower().startswith('res:/'): if blue.remoteFileCache.FileExists(path): if not blue.paths.FileExistsLocally(path): self._isFetchingFile = True uthread.new(prefetch) return if not self.disableAudio: is3D = self._positionComponent is not None self.emitter, outputChannel = uicore.audioHandler.GetAudioBus( is3D=is3D, rate=48000) self.positionComponent = self.SetPositionComponent( self._positionComponent) if path.lower().startswith('res:/') or path.find(':') < 2: stream = blue.paths.open(path) else: stream = blue.BlueNetworkStream(unicode(path).encode('utf-8')) if uicore.audioHandler.active and not self.disableAudio: sink = videoplayer.Audio2Sink(audio2.GetDirectSoundPtr(), audio2.GetStreamPositionPtr(), outputChannel) else: sink = None self.player = videoplayer.VideoPlayer(stream, sink, audioTrack, videoLoop) self.player.on_state_change = self._OnVideoStateChange self.player.on_create_textures = self._OnCreateTextures self.player.on_error = self._OnVideoError
def __init__(self, mpd, base_url, base_dst, options): self.config = Config(mpd, base_url) self.quality_rep_map = {} self.file_writer = common.FileWriter(base_dst) for rep in self.config.reps: self.quality_rep_map[rep['bandwidth']] = rep self.bitrates = self.quality_rep_map.keys() self.bitrates.sort() utility_offset = -math.log(self.bitrates[0]) # so utilities[0] = 0 self.utilities = [math.log(b) + utility_offset for b in self.bitrates] self.verbose = options.verbose self.gp = options.gp self.quality_switch = 0 # buffer_size is in ms self.buffer_size = options.buffer_size * 1000 print "buffer = ", self.buffer_size, "gp = ", self.gp self.bandwidth_changerscript_path = options.bandwidth_changerscript_path # Segment time is in ms self.segment_time = self.config.reps[0]['dur_s'] * 1000 self.Vp = (self.buffer_size - self.segment_time) / (self.utilities[-1] + self.gp) self.player = videoplayer.VideoPlayer(self.segment_time, self.utilities, self.bitrates) if options.verbose: for q in range(len(self.bitrates)): b = self.bitrates[q] u = self.utilities[q] l = self.Vp * (self.gp + u) if q == 0: print('%d %d' % (q, l)) else: qq = q - 1 bb = self.bitrates[qq] uu = self.utilities[qq] ll = self.Vp * (self.gp + (b * uu - bb * u) / (b - bb)) print('%d %d <- %d %d' % (q, l, qq, ll))
wxapp.ProcessPendingEvents() wxapp.ProcessIdle() uthread2.Yield() uthread2.StartTasklet(process_tasklet) def _on_video_info_ready(_, width, height): texture.__init__(width, height, 1, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM) trinity.app.width = width trinity.app.height = height trinity.app.MoveWindow(trinity.app.left, trinity.app.top, trinity.app.width, trinity.app.height) video = videoplayer.VideoPlayer(blue.paths.open(path, 'rb'), videoplayer.WaveOutAudioSink()) texture = trinity.TriTextureRes() video.bgra_texture = texture video.on_create_textures = _on_video_info_ready app = TrinityApp(pauseOnDeactivate=False) init_wx(video) rj = trinity.TriRenderJob() rj.steps.append(trinity.TriStepSetStdRndStates(trinity.RM_ALPHA)) rj.steps.append(trinity.TriStepClear((0.3, 0.3, 0.3, 1), 1.0)) rj.steps.append(trinity.TriStepSetRenderState(27, 1)) rj.steps.append(trinity.TriStepRenderTexture(texture)) trinity.renderJobs.recurring.append(rj) app.exec_()