Files
Praveenhalder-ComfyUI-DeOldify/VideoColorizerColab.ipynb
T

8.1 KiB

Open In Colab

#◢ DeOldify - Not just for photos!

##Use this Colab notebook to colorize black & white videos in four simple steps.

  1. Specify media URL - YouTube, Twitter, Imgur, etc.
  2. Select 'Render Factor'. Generally, older and lower quality videos will render bettter with lower render factors (14-21 range) while higher quality videos will do better on higher render factors.
  3. Run DeOldify to extract single images from your video or gif. Behind the scenes, the code does the following:
    • Extracts single images from the specified media file.
    • Processes the images with DeOldify.
    • Rebuilds the video from colorized images.
  4. Download the video to your device to view!

FYI: This notebook is intended as a tool to colorize gifs and short videos, if you are trying to convert longer video you may hit the limit on processing space. Running the Jupyter notebook on your own machine is recommended (and faster) for larger video sizes.


####Credits:

Big special thanks to:

Robert Bell for all his work on the video Colab notebook, and paving the way to video in DeOldify!

Dana Kelley for doing things, breaking stuff & having an opinion on everything.


#◢ Verify Correct Runtime Settings

IMPORTANT

In the "Runtime" menu for the notebook window, select "Change runtime type." Ensure that the following are selected:

  • Runtime Type = Python 3
  • Hardware Accelerator = GPU
In [ ]:
from os import path
import torch

#◢ Git clone and install DeOldify

In [ ]:
!git clone -b FastAIv1 --single-branch https://github.com/jantic/DeOldify.git DeOldify
#!git clone https://github.com/jantic/DeOldify.git DeOldify
In [ ]:
cd DeOldify

#◢ Setup

In [ ]:
!pip install PyDrive
!pip install ffmpeg-python
!pip install youtube-dl
!pip install tensorboardX
In [ ]:
import fastai
from fasterai.visualize import *
from pathlib import Path
torch.backends.cudnn.benchmark=True
In [ ]:
!mkdir 'models'
!wget https://www.dropbox.com/s/336vn9y4qwyg9yz/ColorizeVideo_gen.pth?dl=0 -O ./models/ColorizeVideo_gen.pth
In [ ]:
file_name = 'video.mp4'
source_dir = './video/source/'
source_path = source_dir + file_name
dest_dir = './video/result/'
dest_path = dest_dir + file_name
In [ ]:
!mkdir file_dir
In [ ]:
colorizer = get_video_colorizer()

#◢ Video URL

YouTube, Imgur, Twitter, Reddit ... files of type .gif, .gifv and .mp4 work. NOTE: If you want to use your own video, upload it first to a site like Imgur.

In [ ]:
source_url = '' #@param {type:"string"}

#◢ Render Factor

The default value of 21 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which video is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality film in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality videos and inconsistencies (flashy render) will generally be reduced, but the colors may get slightly washed out.

In [ ]:
render_factor = 21  #@param {type: "slider", min: 7, max: 45}

#◢ Colorize Video

In [ ]:
if source_url is not None and source_url !='':
    colorizer.colorize_from_url(source_url, file_name, render_factor)
else:
    print('Provide a video url and try again.')

#◢ Download

  • In the menu to the left, click Files
  • If you don't see the 'DeOldify' folder, click "Refresh"
  • By default, rendered video will be in /DeOldify/video/result/

#⚙ Recommended video and gif sources