Esempio n. 1
0
def frames(ctx, input_dir, seed, filename, save_frames, width, height, watermark):
    with tempfile.TemporaryDirectory() as tmp:
        for i in range(30):
            frame_filename = f'{tmp}/{i:04d}.png'

            util.check_call(['magic-mashup', 'frame',
                             '--input-dir', input_dir,
                             '--frame', str(i),
                             '--seed', str(seed),
                             '--width', str(width),
                             '--height', str(height),
                             '--filename', frame_filename])

            util.check_call(['noisemaker', 'effect', 'crt', frame_filename,
                             '--no-resize',
                             '--seed', str(seed),
                             '--speed', '0.25',
                             '--time', str(i / 30.0),
                             '--filename', frame_filename])

            if save_frames:
                shutil.copy(frame_filename, save_frames)

            if watermark:
                util.watermark(watermark, frame_filename)

        util.magick(f'{tmp}/*png', filename)

    print('magic-mashup')
Esempio n. 2
0
def animation(ctx, width, height, channels, seed, effect_preset, filename, save_frames, frame_count, watermark, preset_name):
    if seed is None:
        seed = random.randint(1, MAX_SEED_VALUE)

    value.set_seed(seed)
    reload_presets(PRESETS)

    if preset_name == 'random':
        preset_name = list(GENERATOR_PRESETS)[random.randint(0, len(GENERATOR_PRESETS) - 1)]

    if effect_preset == 'random':
        effect_preset = list(EFFECT_PRESETS)[random.randint(0, len(EFFECT_PRESETS) - 1)]

    if effect_preset:
        print(f"{preset_name} vs. {effect_preset} (seed: {seed})")
    else:
        print(f"{preset_name} (seed: {seed})")

    preset = GENERATOR_PRESETS[preset_name]

    with tempfile.TemporaryDirectory() as tmp:
        for i in range(frame_count):
            frame_filename = f'{tmp}/{i:04d}.png'

            common_params = ['--seed', str(seed),
                             '--time', f'{i/frame_count:0.4f}',
                             '--filename', frame_filename]

            util.check_call(['noisemaker', 'generator', preset_name,
                             '--speed', str(_use_reasonable_speed(preset, frame_count)),
                             '--height', str(height),
                             '--width', str(width)] + common_params)

            if effect_preset:
                util.check_call(['noisemaker', 'effect', effect_preset, frame_filename,
                                 '--no-resize',
                                 '--speed', str(_use_reasonable_speed(EFFECT_PRESETS[effect_preset], frame_count))] + common_params)

            if save_frames:
                shutil.copy(frame_filename, save_frames)

            if watermark:
                util.watermark(watermark, frame_filename)

        if filename.endswith(".mp4"):
            # when you want something done right
            util.check_call(['ffmpeg',
                             '-y',  # overwrite existing
                             '-framerate', '30',
                             '-i', f'{tmp}/%04d.png',
                             '-c:v', 'libx264',  # because this is what twitter wants
                             '-pix_fmt', 'yuv420p',  # because this is what twitter wants
                             '-b:v', '1700000',  # maximum allowed bitrate for 720x720 (2048k), minus some encoder overhead
                             '-s', '720x720',  # a twitter-recommended size
                             filename])

        else:
            util.magick(f'{tmp}/*png', filename)
Esempio n. 3
0
def main(ctx, width, height, channels, seed, effect_preset, name, save_frames,
         frame_count, watermark, overrides, preset_name):
    if preset_name == 'random':
        preset_name = 'random-preset'

    if effect_preset == 'random':
        effect_preset = 'random-effect'

    kwargs = presets.preset(preset_name)

    preset_name = kwargs['name']

    if effect_preset:
        effect_kwargs = presets.preset(effect_preset)

        effect_preset = effect_kwargs['name']

        print(preset_name + " vs. " + effect_preset)
    else:
        print(preset_name)

    if overrides:
        overrides = json.loads(overrides)

    else:
        overrides = {}

    # Override defaults to animate better
    distrib = overrides.get('distrib', kwargs.get('distrib'))

    if distrib and isinstance(distrib, int):
        distrib = ValueDistribution(distrib)

    elif distrib and isinstance(distrib, str):
        distrib = ValueDistribution[distrib]

    if 'point_drift' not in kwargs:
        overrides['point_drift'] = 0.25

    speed = overrides.get("speed", kwargs.get("speed", 0.25))

    # Adjust speed for length of clip. A "normal" length is 30 frames.
    overrides['speed'] = speed * (frame_count / 30.0)

    with tempfile.TemporaryDirectory() as tmp:
        for i in range(frame_count):
            filename = f'{tmp}/{i:04d}.png'

            common_params = [
                '--seed',
                str(seed or 1), '--overrides',
                json.dumps(overrides), '--time', f'{i/frame_count:0.4f}',
                '--name', filename
            ]

            util.check_call([
                'artmaker', preset_name, '--height',
                str(height), '--width',
                str(width)
            ] + common_params)

            if effect_preset:
                util.check_call(
                    ['artmangler', effect_preset, filename, '--no-resize'] +
                    common_params)

            if save_frames:
                shutil.copy(filename, save_frames)

            if watermark:
                util.watermark(watermark, filename)

        if name.endswith(".mp4"):
            # when you want something done right
            util.check_call([
                'ffmpeg',
                '-y',  # overwrite existing
                '-framerate',
                '30',
                '-i',
                f'{tmp}/%04d.png',
                '-c:v',
                'libx264',  # because this is what twitter wants
                '-pix_fmt',
                'yuv420p',  # because this is what twitter wants
                '-b:v',
                '1700000',  # maximum allowed bitrate for 720x720 (2048k), minus some encoder overhead
                '-s',
                '720x720',  # a twitter-recommended size
                name
            ])

        else:
            util.magick(f'{tmp}/*png', name)