def queued_medias(cfg, overlap_time=1., dim=3): '''Queue of medias, mainly used as a demonstration for the prefetch/release mechanism''' nb_videos = dim * dim tqs = [] q = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0)) ag = AutoGrid(range(nb_videos)) for video_id, _, col, pos in ag: start = video_id * cfg.duration / nb_videos animkf = [ngl.AnimKeyFrameFloat(start, 0)] m = ngl.Media(cfg.medias[video_id % len(cfg.medias)].filename, time_anim=ngl.AnimatedTime(animkf)) m.set_label('media #%d' % video_id) t = ngl.Texture2D(data_src=m) program = ngl.Program(vertex=cfg.get_vert('texture'), fragment=cfg.get_frag('texture')) program.update_vert_out_vars(var_uvcoord=ngl.IOVec2(), var_tex0_coord=ngl.IOVec2()) render = ngl.Render(q, program) render.set_label('render #%d' % video_id) render.update_frag_resources(tex0=t) render = ag.place_node(render, (col, pos)) rf = ngl.TimeRangeFilter(render) if start: rf.add_ranges(ngl.TimeRangeModeNoop(0)) rf.add_ranges(ngl.TimeRangeModeCont(start), ngl.TimeRangeModeNoop(start + cfg.duration/nb_videos + overlap_time)) tqs.append(rf) return ngl.Group(children=tqs)
def queued_medias(cfg, overlap_time=1.0, dim=3): """Queue of medias, mainly used as a demonstration for the prefetch/release mechanism""" nb_videos = dim * dim tqs = [] ag = AutoGrid(range(nb_videos)) for video_id, _, col, pos in ag: start = video_id * cfg.duration / nb_videos animkf = [ ngl.AnimKeyFrameFloat(start, 0), ngl.AnimKeyFrameFloat(start + cfg.duration, cfg.duration), ] m = ngl.Media(cfg.medias[video_id % len(cfg.medias)].filename, time_anim=ngl.AnimatedTime(animkf)) m.set_label("media #%d" % video_id) t = ngl.Texture2D(data_src=m) render = ngl.RenderTexture(t) render.set_label("render #%d" % video_id) render = ag.place_node(render, (col, pos)) rf = ngl.TimeRangeFilter(render) if start: rf.add_ranges(ngl.TimeRangeModeNoop(0)) rf.add_ranges( ngl.TimeRangeModeCont(start), ngl.TimeRangeModeNoop(start + cfg.duration / nb_videos + overlap_time)) tqs.append(rf) return ngl.Group(children=tqs)
def _get_dbg_positions(n=1): if n == 1: return _color_positions(_CIRCLE_RADIUS) ret = {} ag = AutoGrid(range(n)) for _, i, col, row in ag: dbg_positions = _color_positions(_CIRCLE_RADIUS) dbg_positions = dict(('%s%d' % (name, i), ag.transform_coords(p, (col, row))) for name, p in dbg_positions.items()) ret.update(dbg_positions) return ret
def _debug_overlay(cfg, scene, grid_names, show_dbg_points=False, show_labels=False): if not show_dbg_points and not show_labels: return scene assert grid_names is not None text_height = 0.25 overlay = ngl.Group() if show_labels: text_group = ngl.Group() ag = AutoGrid(grid_names) for grid_name, _, col, row in ag: text = ngl.Text( grid_name, fg_color=COLORS.white, bg_opacity=1, valign="top", box_width=(2.0, 0, 0), box_height=(0, text_height, 0), box_corner=(-1, 1.0 - text_height, 0), ) text = ag.place_node(text, (col, row)) text_group.add_children(text) scene = ngl.Translate(scene, (0, -text_height / 2.0 * ag.scale, 0), label="text offsetting") overlay.add_children(scene, text_group) else: overlay.add_children(scene) if show_dbg_points: nb = len(grid_names) dbg_positions = _get_dbg_positions(nb) if show_labels: dbg_positions = { name: (p[0], p[1] - text_height / 2.0 * ag.scale) for name, p in dbg_positions.items() } dbg_points = get_debug_points(cfg, dbg_positions, radius=0.01, text_size=(0.08, 0.08)) overlay.add_children(dbg_points) return overlay
def _get_easing_nodes(cfg, color_program): ag = AutoGrid(_easing_list) cfg.aspect_ratio = (ag.nb_cols, ag.nb_rows) easing_h = 1. / ag.nb_rows easing_w = 1. / ag.nb_cols for easing, easing_id, col, row in ag: easing_name, zoom = easing easing_node = _get_easing_node(cfg, easing_name, zoom, color_program) easing_node = ngl.Scale(easing_node, factors=[easing_w, easing_h, 0]) x = easing_w * (-ag.nb_cols + 1 + 2 * col) y = easing_h * (ag.nb_rows - 1 - 2 * row) easing_node = ngl.Translate(easing_node, vector=(x, y, 0)) yield easing_node
def media_queue(cfg, overlap_time=7.0, dim=3): cfg.duration = 10 cfg.aspect_ratio = (1, 1) nb_medias = dim * dim medias = [ m.filename for m in cfg.medias if m.filename.endswith(("mp4", "jpg")) ] queued_medias = [] ag = AutoGrid(range(nb_medias)) for video_id, _, col, pos in ag: start = video_id * cfg.duration / nb_medias animkf = [ ngl.AnimKeyFrameFloat(start, 0), ngl.AnimKeyFrameFloat(start + cfg.duration, cfg.duration), ] media = ngl.Media(medias[video_id % len(medias)], time_anim=ngl.AnimatedTime(animkf)) texture = ngl.Texture2D(data_src=media, min_filter="linear", mag_filter="linear") render = ngl.RenderTexture(texture) render = ag.place_node(render, (col, pos)) rf = ngl.TimeRangeFilter(render) if start: rf.add_ranges(ngl.TimeRangeModeNoop(0)) rf.add_ranges( ngl.TimeRangeModeCont(start), ngl.TimeRangeModeNoop(start + cfg.duration / nb_medias + overlap_time)) queued_medias.append(rf) return ngl.Group(children=queued_medias)