Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bartwojtowicz/videopython
Minimal video generation and processing library.
https://github.com/bartwojtowicz/videopython
ffmpeg python video video-generation video-processing
Last synced: 3 months ago
JSON representation
Minimal video generation and processing library.
- Host: GitHub
- URL: https://github.com/bartwojtowicz/videopython
- Owner: BartWojtowicz
- License: apache-2.0
- Created: 2023-10-12T16:48:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-18T11:34:59.000Z (6 months ago)
- Last Synced: 2024-11-06T04:40:17.034Z (3 months ago)
- Topics: ffmpeg, python, video, video-generation, video-processing
- Language: Python
- Homepage:
- Size: 10.1 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
Minimal video generation and processing library.
## Setup
### Install ffmpeg
```bash
# Install with brew for MacOS:
brew install ffmpeg
# Install with apt-get for Ubuntu:
sudo apt-get install ffmpeg
```### Install with pip
```bash
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
```python
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, TransformationPipelinepipeline = 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 FadeTransitionfade = 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.
```python
# Generate image and animate it
from videopython.generation import ImageToVideo
from videopython.generation import TextToImage
from videopython.generation import TextToMusicimage = 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()
```