Skip to main content

VidDiffusion is a Python library that provides vid2vid pipeline by using Hugging Face's `diffusers`.

Project description

🎥 VidDiffusion

VidDiffusion is a Python library that provides vid2vid pipeline by using Hugging Face's diffusers.

Show some works generated by VidDiffusion:

Openjourney V4

https://user-images.githubusercontent.com/1396267/232981471-33406bff-6b2b-44d8-a294-7b8268c57552.mov

Anime style

https://user-images.githubusercontent.com/1396267/232980819-02f7e15a-af37-4d2d-a66d-f82f4163eb87.mov

Original Video: https://mixkit.co/free-stock-video/girl-dancing-with-her-headphones-while-taking-a-walk-4823/

Sharing Your Work

Although it is not required, we would appreciate if you could share your generated videos and the configurations you used on SNS, etc. Please include the GitHub URL of this library in your post: VidDiffusion

Also, please post config values you used to generate the video by instance.show_config(). I hope we can all find the best value and produce great videos!

Installation

To install the library, run the following commands:

export HUGGING_FACE_HUB_TOKEN=your_hf_auth_token
pip install --upgrade transformers diffusers
pip install viddiffusion

VidDiffusion on PyPI

Usage

First, import the library:

from viddiffusion import VidDiffusionPipeline

Next, create a configuration dictionary and initialize the pipeline:

config = {
	'pretrained_model_name_or_path': 'your_pretrained_model_name_or_path',
	'hf_auth_token': 'your_hf_auth_token', #Optional

	'input_video_path': 'your_input_video_path',
	'output_video_path': 'your_output_video_path'
}
vid_pipe = VidDiffusionPipeline(config)

Optionally, you can change the path of temp save directory and other parameters:

vid_pipe.set_config({
	'init_image_dir': './vid_temp/init',
	'output_image_dir': './vid_temp/output',

	'fps': 20,
	'end_time': 5.0,

	'prompt': 'Fantasy, dynamic, cinamatic, cinematic light, hyperrealism',
	'negative_prompt': 'deformed, out of focus, blurry, low resolution, low quality',
})
vid_pipe.show_config()

Finally, apply the diffusion model to the video:

vid_pipe.vid2vid()

Configuration:

Required parameters:

  • pretrained_model_name_or_path: The name or path of the pretrained diffusion model to use. The model must be a Hugging Face model. The model can be a local path or a model name from the Hugging Face model hub. E.g. pretrained_model_name_or_path = 'stabilityai/stable-diffusion-2'
  • input_video_path: The path to the input video file. E.g. input_video_path = 'input_video.mp4'
  • output_video_path: The path to the output video file. E.g. output_video_path = 'output_video.mp4'

Optional parameters:

  • huggingface parameters:

    • hf_auth_token: Hugging Face auth token. Default: None.
  • Folder parameters:

    • init_image_dir: Path to images separated from the video directory. Default: None.
    • output_image_dir: Path to regenerated images directory. Default: /tmp/viddiffusion.
  • Video parameters:

    • fps: FPS of output video. Default: fps of input video.
    • duration: Duration of output video. Default: duration of input video.
    • start_time: Start time of output video. Default: 0.
    • end_time: End time of output video. Default: duration of input video.
  • Diffusion parameters:

    • custom_pipeline: Custom pipeline. Default: lpw_stable_diffusion.
    • torch_dtype: Torch dtype. Default: torch.float.
    • safety_checker: Safety checker. Callable. Default: None.
    • image_size: Image size. Default: 512 * 512 = 262144.
  • Prompt parameters:

    • prompt: Prompt. Default: 'Cyberpunk style, intricate details, high-quality'
    • negative_prompt: Negative prompt. Default: 'Low-quality, blurry, pixelated, low-resolution'
  • Scheduler parameters:

    • scheduler: Scheduler. Default: DPMSolverMultistepScheduler.
    • beta_start: Beta start. Default: 0.00085 * 0.75.
    • beta_end: Beta end. Default: 0.012 * 0.75.
    • num_train_timesteps: Number of train timesteps. Default: int(1000 * 0.75).
    • blend_alph: Blend alph. Default: 0.15.
    • blend_decay_rate: Blend decay rate. Default: 0.997.
    • strength: Strength. Default: 0.65.
    • num_inference_steps: Number of inference steps. Default: 30.
    • guidance_scale: Guidance scale. Default: 7.5.
    • seed: Seed for generator. Default: 2023.
  • Other parameters:

    • preprocess_image: Preprocess image. Default: lambda image: image.

How to Improve Video Quality

This library's feature is using generated image one frame before and after the current frame to improve video quality. This feature is enabled by default. I guess this feature is good for videos that have a lot of motion.

Parameters to change to improve video quality

  • scheduler : Try various scheduler such as DPMSolverMultistepScheduler, DDIMScheduler, LMSDiscreteScheduler, EulerDiscreteScheduler, PNDMScheduler, DDPMScheduler, EulerAncestralDiscreteScheduler.

  • beta_start : 0.00085 * 0.65~0.75 is good, but I don't know the best value.

  • beta_end : 0.012 * 0.65~0.75 is good, but I don't know the best value.

  • num_train_timesteps : int(1000 * 0.65~0.75) is good, but I don't know the best value.

  • strength : 0.4 ~ 0.9 is good, but I don't know the best value.

  • guidance_scale : 5.0~14.0 is good, but I don't know the best value.

  • blend_alph : 0.03 ~ 0.28 is good, but I don't know the best value.

  • blend_decay_rate : 0.992 ~ 1.0 is good, but I don't know the best value.

  • prompt : Try various prompt such as 'Cyberpunk style, intricate details, high-quality', 'Fantasy, dynamic, cinamatic, cinematic light, hyperrealism', 'Cyberpunk, cyberpunk style, cyberpunk aesthetic, cyber punk city, cyberpunk cityscape, cyberpunk cityscape aesthetic, cyberpunk cityscape style, cyberpunk cityscape light, cyberpunk cityscape light aesthetic, cyberpunk cityscape light style, cyberpunk cityscape light

  • negative_prompt : Try various negative_prompt such as 'Low-quality, blurry, pixelated, low-resolution', 'deformed, out of focus, blurry, low resolution, low quality', 'Low-quality, blurry, pixelated, low-resolution, deformed, out of focus, blurry, low resolution, low quality'

  • preprocess_image : Try various preprocess_image function such as torchvision.

License

VidDiffusion is licensed under the Apache License 2.0.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.

Contact

If you have any questions, please feel free to contact me. Twitter DM is best option for me

Citation

@misc{masaishi2023viddiffusion,
	title={VidDiffusion: Vid2Vid Diffuser Pipeline for Video Filter}, 
	author={Masamune Ishihara},
	year={2023},
	publisher = {GitHub},
	journal = {GitHub repository},
	howpublished = {\url{https://github.com/masaishi/VidDiffusion}}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viddiffusion-0.1.2.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

viddiffusion-0.1.2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file viddiffusion-0.1.2.tar.gz.

File metadata

  • Download URL: viddiffusion-0.1.2.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for viddiffusion-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d3e4e034dd7a38ca0d1d8a261aac8c3988a0b0df299dde0b34c56f0cfdb661e8
MD5 88475976a88bdd5b0eb5543c9b9dcc30
BLAKE2b-256 5c366e946438d570b9a79cdc407b4560dada994e69a1fd7e2bf3b930a66350ba

See more details on using hashes here.

File details

Details for the file viddiffusion-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: viddiffusion-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for viddiffusion-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aefca857d14ecf197b192ac18a97c7bf28f01ce63a9fe1ba59b3a8e726ef2146
MD5 ec244bbaaf66fab5f9c46f571752bd52
BLAKE2b-256 5aaf34d6c15fc0bdd5fe87b9af12712a75aa6ece2ca03fde7ba82b712dd2ab7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page