Esempio n. 1
0
def main():
    """Main controller for Video2X

    This function controls the flow of video conversion
    and handles all necessary functions.
    """
    if args.cpu:
        method = "cpu"
    elif args.gpu:
        method = "gpu"
    elif args.cudnn:
        method = "cudnn"

    fm = FFMPEG("\"" + FFMPEG_PATH + "ffmpeg.exe\"", args.output)
    w2 = WAIFU2X(WAIFU2X_PATH, method)

    # Extract Frames
    if not os.path.isdir(FOLDERIN):
        os.mkdir(FOLDERIN)
    fm.extract_frames(args.video, FOLDERIN)

    info = get_vid_info()
    # Framerate is read as fraction from the json dictionary
    width, height, framerate = info["streams"][0]["width"], info["streams"][0]["height"], float(Fraction(info["streams"][0]["avg_frame_rate"]))
    print("Framerate: ", framerate)
    final_resolution = str(width * int(args.factor)) + "x" + str(height * int(args.factor))

    # Upscale Frames
    if not os.path.isdir(FOLDEROUT):
        os.mkdir(FOLDEROUT)
    w2.upscale(FOLDERIN, FOLDEROUT, int(args.factor) * width, int(args.factor) * height)

    # Frames to Video
    fm.to_vid(framerate, final_resolution, FOLDEROUT)

    # Extract and press audio in
    fm.extract_audio(args.video, FOLDEROUT)
    fm.insert_audio_track("output.mp4", FOLDEROUT)
Esempio n. 2
0
def video2x():
    """Main controller for Video2X

    This function controls the flow of video conversion
    and handles all necessary functions.
    """

    check_model_type(args)

    if args.cpu:
        method = 'cpu'
    elif args.gpu:
        method = 'gpu'
    elif args.cudnn:
        method = 'cudnn'

    fm = FFMPEG('\"' + FFMPEG_PATH + 'ffmpeg.exe\"', args.output)
    w2 = WAIFU2X(WAIFU2X_PATH, method, args.model_type)

    # Clear and create directories
    if os.path.isdir(FRAMES):
        shutil.rmtree(FRAMES)
    if os.path.isdir(UPSCALED):
        shutil.rmtree(UPSCALED)
    os.mkdir(FRAMES)
    os.mkdir(UPSCALED)

    # Extract frames from video
    fm.extract_frames(args.video, FRAMES)

    info = get_vid_info()
    # Analyze original video with ffprobe and retrieve framerate
    width, height, framerate = info['streams'][0]['width'], info['streams'][0][
        'height'], float(Fraction(info['streams'][0]['avg_frame_rate']))
    avalon.info('Framerate: {}'.format(framerate))
    final_resolution = str(width * int(args.factor)) + \
        'x' + str(height * int(args.factor))

    # Upscale images one by one using waifu2x
    avalon.info('Starting to upscale extracted images')
    for (dirpath, dirnames, filenames) in os.walk(FRAMES):
        file_list = tqdm(filenames, ascii=True)
        for file in file_list:
            if file[-4:].lower() == '.png':
                image_path = '{}\\{}'.format(dirpath, file)
                file_list.set_description('Upscaling: {}'.format(file))
                # avalon.dbgInfo('Upscaling: {}'.format(image_path))
                w2.upscale(image_path, UPSCALED,
                           int(args.factor) * width,
                           int(args.factor) * height)
    avalon.info('Extraction complete')

    # Frames to Video
    avalon.info('Converting extracted frames into video')
    fm.to_vid(framerate, final_resolution, UPSCALED)

    # Extract and press audio in
    avalon.info('Stripping audio track from original video')
    fm.extract_audio(args.video, UPSCALED)
    avalon.info('Inserting audio track into new video')
    fm.insert_audio_track(UPSCALED)