示例#1
0
def create_video_from_image_paths(image_paths: List[str],
                                  output_file_path: str,
                                  seconds_per_image: float = 3.0,
                                  temp_folder_path: Optional[str] = None,
                                  debug: bool = False) -> bool:
    temp_folder_path = temp_folder_path or path.join(
        kpath.folder_path_of_file(), '.__ffmpeg_images_temp')
    import os
    os.makedirs(temp_folder_path, exist_ok=True)

    file_base_name = 'image'
    i = 1
    file_extension = kpath.extension(image_paths[0], include_dot=True)

    for image_path in image_paths:
        new_image_path = path.join(
            temp_folder_path,
            file_base_name + '{:03d}'.format(i) + file_extension)
        sh.cp(image_path, new_image_path)
        i += 1

    res = create_video_from_images(temp_folder_path,
                                   output_file_path,
                                   seconds_per_image=seconds_per_image,
                                   file_base_name=file_base_name,
                                   file_extension=file_extension,
                                   debug=debug)
    kpath.remove(temp_folder_path)

    return res
示例#2
0
def concat_videos_copy(in_paths: List[str],
                       out_path: str,
                       debug: bool = False) -> bool:
    if len(in_paths) == 0:
        return False
    elif len(in_paths) == 1:
        sh.cp(in_paths[0], out_path)

        return True

    temp_txt_path = path.join(kpath.folder_path_of_file(out_path),
                              '__temp_list.txt')
    temp_txt_content = ''

    for in_path in in_paths:
        if len(temp_txt_content) > 0:
            temp_txt_content += '\n'

        temp_txt_content += 'file \'' + in_path + '\''

    with open(temp_txt_path, 'w') as f:
        f.write(temp_txt_content)

    sh.sh('ffmpeg -y -f concat -safe 0 -i ' + sh.path(temp_txt_path) +
          ' -c copy ' + sh.path(out_path),
          debug=debug)
    kpath.remove(temp_txt_path)

    return path.exists(out_path)
示例#3
0
def concat_videos_loop(in_paths: List[str],
                       out_path: str,
                       video_duration: float,
                       randomize_videos: Optional[bool] = False,
                       debug: bool = False) -> bool:
    if len(in_paths) == 0:
        return False
    elif len(in_paths) == 1:
        sh.cp(in_paths[0], out_path)

        return True

    temp_txt_path = path.join(kpath.folder_path_of_file(out_path),
                              '__temp_video_paths.txt')
    current_video_duration = 0
    final_text = ''

    while current_video_duration < video_duration:
        if randomize_videos:
            random.shuffle(in_paths)

        for vid_path in in_paths:
            final_text += 'file ' + '\'' + vid_path + '\'\n'
            subvid_duration = ffprobe.get_duration(vid_path)
            current_video_duration += subvid_duration

            if current_video_duration >= video_duration:
                with open(temp_txt_path, 'w') as f:
                    f.write(final_text)

                break

    sh.sh('ffmpeg -y -f concat -safe 0 -i ' + sh.path(temp_txt_path) +
          ' -c copy ' + sh.path(out_path),
          debug=debug)
    kpath.remove(temp_txt_path)

    return path.exists(out_path)