def test_music_video_generator__creates_music_video_with_duration(
        orange_source):
    generator = MusicVideoGenerator(video_sources=[orange_source],
                                    duration=.1,
                                    video_filters=[])

    music_video = generator.generate_from_events([.02, .04],
                                                 progress_bar=False)

    assert len(music_video.segments) == 3
    assert music_video.compose().duration == .1
Esempio n. 2
0
def test_music_video_generator__creates_music_video(shinsekai_source):
    generator = MusicVideoGenerator(audio_file=f'{DATA_PATH}/audio/soft.mp3',
                                    video_sources=[shinsekai_source])
    music_video = generator.generate_from_events(generator.audio.beats(),
                                                 progress_bar=False)
Esempio n. 3
0
def create_music_video(args):
    output_directory = args.output_directory
    video_name = args.video_name

    audio_source = args.audio_source
    duration = args.duration
    video_sources = args.video_sources
    video_source_weights = args.video_source_weights
    fade_in = args.fade_in
    fade_out = args.fade_out

    video_filters = args.video_filters
    exclude_video_filters = args.exclude_video_filters
    include_video_filters = args.include_video_filters

    use_original_audio = args.use_original_audio
    video_dimensions = args.video_dimensions
    video_aspect_ratio = args.video_aspect_ratio
    video_preset = args.video_preset
    video_codec = args.video_codec
    video_crf = args.video_crf
    audio_codec = args.audio_codec
    audio_bitrate = args.audio_bitrate

    save_segments = args.save_segments

    # Prepare Inputs
    audio_file = get_audio_file(audio_source, duration)

    if video_sources:
        video_source_files = cli_util.video_files_from_sources(video_sources)
    else:
        video_source_files = cli_util.prompt_files_selection(c.FileType.VIDEO)
    video_sources = VideoSourceList(video_source_files,
                                    weights=video_source_weights)

    generator = MusicVideoGenerator(
        audio_file,
        video_sources,
        duration=duration,
        video_filters=video_filters,
        exclude_video_filters=exclude_video_filters,
        include_video_filters=include_video_filters)

    message(
        f"Weights\n------------\n{generator.video_sources.flatten().weight_stats()}"
    )

    try:
        events = prepare_events(generator, args)
    except ParameterError as e:
        shutdown(str(e))

    message("Generating music video from video segments and audio...")

    music_video = generator.generate_from_events(events)

    # Apply effects
    if fade_in:
        music_video.segments[0].effects.add_fadein(fade_in)
    if fade_out:
        music_video.segments[-1].effects.add_fadeout(fade_out)

    # Print stats for rejected video segments
    cli_util.print_rejected_segment_stats(generator)

    # Create the directory for the music video
    music_video_name = cli_util.get_music_video_name(output_directory,
                                                     video_name)
    music_video_directory = os.path.join(output_directory, music_video_name)
    music_video_output_path = os.path.join(
        music_video_directory, music_video_name + VideoWriter.VIDEO_EXTENSION)
    music_video_pickle_path = os.path.join(
        music_video_directory, music_video_name + Persistable.PICKLE_EXTENSION)
    util.ensure_dir(music_video_directory)

    message(f"Writing music video '{music_video_output_path}'...")

    # Save the music video
    if video_preset:
        music_video.writer.preset = video_preset
    if video_codec:
        music_video.writer.codec = video_codec
    if video_crf:
        music_video.writer.crf = video_crf
    if audio_codec:
        music_video.writer.audio_codec = audio_codec
    if audio_bitrate:
        music_video.writer.audio_bitrate = audio_bitrate

    if use_original_audio:
        music_video.audio_file = None
    if video_dimensions:
        music_video.dimensions = video_dimensions
    if video_aspect_ratio:
        music_video.aspect_ratio = video_aspect_ratio

    music_video.write_to_video_file(music_video_output_path)
    music_video.save(music_video_pickle_path)

    # Save the individual segments if asked to do so
    if save_segments:
        message("Saving video segments...")
        music_video.write_video_segments(music_video_directory)
Esempio n. 4
0
def create_music_video(args):
    output_directory = args.output_directory
    video_name = args.video_name
    audio_source = args.audio_source
    duration = args.duration
    video_sources = args.video_sources
    video_source_weights = args.video_source_weights
    fade_in = args.fade_in
    fade_out = args.fade_out
    video_filters = args.video_filters
    exclude_video_filters = args.exclude_video_filters
    include_video_filters = args.include_video_filters
    use_original_audio = args.use_original_audio
    video_dimensions = args.video_dimensions
    video_aspect_ratio = args.video_aspect_ratio
    video_preset = args.video_preset
    video_codec = args.video_codec
    video_crf = args.video_crf
    audio_codec = args.audio_codec
    audio_bitrate = args.audio_bitrate
    save_segments = args.save_segments
    video_ext = args.video_ext
    force_video_split = args.force_video_split
    force_video_split_locs = args.force_video_split_locs

    VideoWriter.VIDEO_EXTENSION = video_ext

    video_source_files = files_from_sources(video_sources)
    video_sources = VideoSourceList(video_source_files,
                                    weights=video_source_weights)

    generator = MusicVideoGenerator(
        audio_source,
        video_sources,
        duration=duration,
        video_filters=video_filters,
        exclude_video_filters=exclude_video_filters,
        include_video_filters=include_video_filters,
    )

    message(
        f"Weights\n------------\n{generator.video_sources.flatten().weight_stats()}"
    )

    try:
        events = prepare_events(generator, args)
    except ParameterError as e:
        shutdown(str(e))

    message("Generating music video from video segments and audio...")

    music_video = generator.generate_from_events(
        events,
        force_video_split=force_video_split,
        force_video_split_locs=force_video_split_locs)

    # Apply effects
    if fade_in:
        music_video.segments[0].effects.add_fadein(fade_in)
    if fade_out:
        music_video.segments[-1].effects.add_fadeout(fade_out)

    # Print stats for rejected video segments
    print_rejected_segment_stats(generator)

    # Create the directory for the music video
    music_video_name = get_music_video_name(output_directory, video_name)
    music_video_directory = os.path.join(output_directory, music_video_name)
    music_video_output_path = os.path.join(
        music_video_directory, music_video_name + VideoWriter.VIDEO_EXTENSION)
    music_video_pickle_path = os.path.join(
        music_video_directory, music_video_name + Persistable.PICKLE_EXTENSION)
    util.ensure_dir(music_video_directory)

    message(f"Writing music video '{music_video_output_path}'...")

    # Save the music video
    if video_preset:
        music_video.writer.preset = video_preset
    if video_codec:
        music_video.writer.codec = video_codec
    if video_crf:
        music_video.writer.crf = video_crf
    if audio_codec:
        music_video.writer.audio_codec = audio_codec
    if audio_bitrate:
        music_video.writer.audio_bitrate = audio_bitrate

    if use_original_audio:
        music_video.audio_file = None
    if video_dimensions:
        music_video.dimensions = video_dimensions
    if video_aspect_ratio:
        music_video.aspect_ratio = video_aspect_ratio

    music_video.save(music_video_pickle_path)
    if VideoWriter.VIDEO_EXTENSION == '.mkv':
        print('Adding subtitles because mkv supports')
        music_video.write_to_video_file(music_video_output_path)
    else:
        print('Mp4 doesnt support multiple subtitle tracks')
        music_video.write_to_video_file(music_video_output_path,
                                        add_auxiliary_tracks=False)

    #music_video.save(music_video_pickle_path)

    # Save the individual segments if asked to do so
    if save_segments:
        message("Saving video segments...")
        music_video.write_video_segments(music_video_directory)