Skip to main content

Minimal video generation and processing library.

Project description

About

Minimal video generation and processing library.

Setup

Install ffmpeg

# Install with brew for MacOS:
brew install ffmpeg
# Install with apt-get for Ubuntu:
sudo apt-get install ffmpeg

Install with pip

pip install videopython[generation]

You can install without [generation] dependencies for basic video handling and processing. The funcionalities found in videopython.generation won't work.

Basic Usage

Video handling

from videopython.base.video import Video

# Load videos and print metadata
video1 = Video.from_path("tests/test_data/fast_benchmark.mp4")
print(video1)

video2 = Video.from_path("tests/test_data/slow_benchmark.mp4")
print(video2)

# Define the transformations
from videopython.base.transforms import CutSeconds, ResampleFPS, Resize, TransformationPipeline

pipeline = TransformationPipeline(
    [CutSeconds(start=1.5, end=6.5), ResampleFPS(fps=30), Resize(width=1000, height=1000)]
)
video1 = pipeline.run(video1)
video2 = pipeline.run(video2)

# Combine videos, add audio and save
from videopython.base.transitions import FadeTransition

fade = FadeTransition(effect_time_seconds=3.0)
video = fade.apply(videos=(video1, video2))
video.add_audio_from_file("tests/test_data/test_audio.mp3")

savepath = video.save()

Video Generation

Using Nvidia A40 or better is recommended for the videopython.generation module.

# Generate image and animate it
from videopython.generation import ImageToVideo
from videopython.generation import TextToImage
from videopython.generation import TextToMusic

image = TextToImage().generate_image(prompt="Golden Retriever playing in the park")
video = ImageToVideo().generate_video(image=image, fps=24)

# Video generation directly from prompt
from videopython.generation import TextToVideo
video_gen = TextToVideo()
video = video_gen.generate_video("Dogs playing in the snow")
for _ in range(10):
    video += video_gen.generate_video("Dogs playing in the snow")

# Cut the first 2 seconds
from videopython.base.transforms import CutSeconds
transformed_video = CutSeconds(start_second=0, end_second=2).apply(video.copy())

# Upsample to 30 FPS
from videopython.base.transforms import ResampleFPS
transformed_video = ResampleFPS(new_fps=30).apply(transformed_video)

# Resize to 1000x1000
from videopython.base.transforms import Resize
transformed_video = Resize(width=1000, height=1000).apply(transformed_video)

# Add generated music
# MusicGen cannot generate more than 1503 tokens (~30seconds of audio)
text_to_music = TextToMusic()
audio = text_to_music.generate_audio("Happy dogs playing together in a park", max_new_tokens=256)
transformed_video.add_audio(audio=audio)

filepath = transformed_video.save()

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

videopython-0.2.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

videopython-0.2.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file videopython-0.2.1.tar.gz.

File metadata

  • Download URL: videopython-0.2.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for videopython-0.2.1.tar.gz
Algorithm Hash digest
SHA256 237e06b1eb1ca57ec7f89bd37a92bf6eaa1f9033d6bc5a8e2807ad6f519f144c
MD5 1a6eae4d5fdf9398565c59dde38ef850
BLAKE2b-256 a23e73c925e5b6fa1363512b4203eb54b6899e81f57d6a0fbfc2ee05fe30cd9b

See more details on using hashes here.

File details

Details for the file videopython-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: videopython-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for videopython-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03c7ba811e1e21d8a40b758e11cae0814054b10b19aa6de8da1c73fdfaa81da7
MD5 d48fdf4f6b4a8a4ea8363b1b30a2ca7d
BLAKE2b-256 330fc16e320a187684f56dcb15101c476dde10fa6d91d8214f203b60d590b8e1

See more details on using hashes here.

Supported by

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