Esempio n. 1
0
 def getFrameRate(self):
     """
     Extracts the FPS from the physical file on first call and returns 
     the cached value thereafter as a float. Requires ffmpeg
     """
     if not self._fps:
         ffmpegParser = FFMPEG(
             ffmpeg=self.settings.get('paths_ffmpeg'),
             closeFDs=(type(self._platform) != util.WindowsPlatform))  # close_fds borked on windows
         
         try:
             metadata = ffmpegParser.get_metadata(self.getLocalPath())
         except:
             log.exception('ffmpeg parsing failed')
             metadata = None
             
         log.debug('ffmpeg metadata for %s = %s' % (self.getLocalPath(), metadata))
         if metadata:
             self._fps = float(metadata.frame_rate)
         else:
             self._fps = 29.97
             log.error("""Could not determine FPS for file %s so defaulting to %s FPS.
                          Make sure you have the ffmpeg executable in your path. 
                          Commercial skipping may be inaccurate""" % (self._fps, self.getLocalPath()))
             ui.showPopup('Error', 'FFMpeg could not determine framerate. Comm skip may be inaccurate')
     return self._fps
Esempio n. 2
0
 def build(self, movie, **kwargs):
     if movie == FFMPEG.getTypeName():
         return FFMPEG(**kwargs)
     elif self._factory:
         return self._factory.build(movie, **kwargs)
     else:
         raise MovieFactoryException('movie encoder: \"' + movie + '\" is not supported')
Esempio n. 3
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. 4
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)