def worker(die_at=None, thumbnails=[]): for i in xrange(5): if die_at == i: raise ValueError("we died") for j in xrange(10): time.sleep(0.01 + 0.1 * random.random()) set_progress(i * 10 + j + 1, maximum=50, status="Working... %d of 50" % (i * 10 + j + 1)) if thumbnails: set_thumbnail(random.choice(thumbnails)) notify(message="Sleeping is complete.")
def worker(die_at=None, thumbnails=[]): for i in xrange(5): if die_at == i: raise ValueError('we died') for j in xrange(10): time.sleep(0.01 + 0.1 * random.random()) set_progress(i * 10 + j + 1, maximum=50, status='Working... %d of 50' % (i * 10 + j + 1)) if thumbnails: set_thumbnail(random.choice(thumbnails)) notify(message='Sleeping is complete.')
def make_quicktime(movie_path, frames_path, audio_path=None, framerate=None, on_progress=None): from uifutures.worker import set_progress, notify # Replace #### with %04d glob_path = re.sub(r'(#+|%.+?[sd])', '*', frames_path) frame_count = len(glob.glob(glob_path)) frames_path = re.sub(r'(#+)', lambda m: '%%0%dd' % len(m.group(1)), frames_path) cmd = ['ffmpeg', '-y'] if framerate: cmd.extend(['-framerate', str(framerate)]) cmd.extend(['-i', frames_path]) if audio_path: cmd.extend(['-i', audio_path]) cmd.extend([ '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-profile:v', 'baseline', '-crf', '22', '-threads', '0' ]) if audio_path: cmd.extend([ '-c:a', 'pcm_s24le', ]) cmd.extend([movie_path]) proc = subprocess.Popen(cmd, stderr=subprocess.PIPE) for line in proc.stderr: if on_progress: m = re.match(r'frame=\s*(\d+)', line) if m: on_progress(int(m.group(1)), frame_count) sys.stderr.write(line) sys.stderr.flush() notify('Your QuickTime is ready.')
def make_quicktime(movie_paths, frames_path, audio_path=None, extended_data=None, progress_callback=None): from uifutures.worker import set_progress, notify from dailymaker import dailymaker from dailymaker import utils as daily_utils from dailymaker import presets if isinstance(movie_paths, basestring): movie_paths = [movie_paths] movie_path = movie_paths[0] frame_sequence = daily_utils.parse_source_path(frames_path) qt = dailymaker.DailyMaker() qt.image_sequence = frame_sequence qt.source = frames_path qt.dest = movie_path qt.render_preview = False qt.extended_data = extended_data qt.set_preset(presets.find_preset(presets.get_default_preset())) # Setup signal to the user. if progress_callback is not None: qt._progress_callback = progress_callback else: qt._progress_callback = lambda value, maximum, image: set_progress( value, maximum, status = "Encoding %s" % os.path.basename(frame_sequence[value]) ) if audio_path: qt.audio = audio_path # Process it. qt.start() for extra_path in movie_paths[1:]: set_progress(status="Copying to %s" % os.path.dirname(extra_path)) copy(movie_path, extra_path) notify('Your QuickTime is ready.')
def make_quicktime(movie_paths, frames_path, audio_path=None): from uifutures.worker import set_progress, notify import ks.core.project import ks.core.quicktime.quicktime if isinstance(movie_paths, basestring): movie_paths = [movie_paths] movie_path = movie_paths[0] # Get an actual file name out of a pattern. if '#' in frames_path: frames_path = re.sub('#+', '*', frames_path) if '*' in frames_path: frames_path = sorted(glob.glob(frames_path))[0] # Read in the sequence. # TODO: Rebuild this functionality. frame_sequence = ks.core.project.get_sequence(frames_path) qt = ks.core.quicktime.quicktime.quicktime() # Setup signal to the user. qt.progress = lambda value, maximum: set_progress( value, maximum, status="Encoding %s" % os.path.basename(frame_sequence[value])) # Process it. qt.make_quicktime(frame_sequence, movie_path) if audio_path: set_progress(status="Adding %s" % os.path.basename(audio_path)) qt.add_audio(movie_path, audio_path) for extra_path in movie_paths[1:]: set_progress(status="Copying to %s" % os.path.dirname(extra_path)) copy(movie_path, extra_path) notify('Your QuickTime is ready.')
def make_quicktime(movie_paths, frames_path, audio_path=None): from uifutures.worker import set_progress, notify import ks.core.project import ks.core.quicktime.quicktime if isinstance(movie_paths, basestring): movie_paths = [movie_paths] movie_path = movie_paths[0] # Get an actual file name out of a pattern. if '#' in frames_path: frames_path = re.sub('#+', '*', frames_path) if '*' in frames_path: frames_path = sorted(glob.glob(frames_path))[0] # Read in the sequence. # TODO: Rebuild this functionality. frame_sequence = ks.core.project.get_sequence(frames_path) qt = ks.core.quicktime.quicktime.quicktime() # Setup signal to the user. qt.progress = lambda value, maximum: set_progress(value, maximum, status="Encoding %s" % os.path.basename(frame_sequence[value])) # Process it. qt.make_quicktime(frame_sequence, movie_path) if audio_path: set_progress(status="Adding %s" % os.path.basename(audio_path)) qt.add_audio(movie_path, audio_path) for extra_path in movie_paths[1:]: set_progress(status="Copying to %s" % os.path.dirname(extra_path)) copy(movie_path, extra_path) notify('Your QuickTime is ready.')