ffmpeg-studio provides a Pythonic interface to FFmpeg, allowing users to construct and execute FFmpeg commands programmatically.
It simplifies and Handles:
- Complex filter generation
- All popular Filters and Baseclass for custom filters
- Automatic Safe quoting & escaping
- Input handling & stream selection
- Output mapping & stream selection
- Progress tracking with callbacks
- Allows direct flags in command.
- Scanning metadata with ffprobe.
- Long filter graphs.
From PyPi
pip install ffmpeg-studioFrom Source
pip install git+https://github.com/electro199/ffmpeg-studio.gitffmpeg-studio support complex Filters and can be used with apply or apply2.
from ffmpeg import FFmpeg, InputFile, FileInputOptions, Map
from ffmpeg.filters import apply, Scale, Overlay
# set options
clip = InputFile("video.mp4", FileInputOptions(duration=10))
overlay = InputFile("overlay.png")
# apply scale filter on clip
upscaled_clip = apply(Scale(1440, 1920), clip)
# apply scale filter on overlay
overlay = apply(Scale(100, 100), overlay)
# apply overlay filter with overlay on upscaled_clip
upscaled_clip = apply(Overlay(overlay, x=0, y=10), clip)
ffmpeg = FFmpeg()
# add output
ffmpeg.output(upscaled_clip, path="out.mp4")
# run command
ffmpeg.run(progress_callback=print)For simple media conversion :
from ffmpeg.inputs import VideoFile
from ffmpeg import export
clip = VideoFile("video.mp4")
export(
clip,
path="out.mkv",
).run()from ffmpeg.inputs import VideoFile
from ffmpeg import export
clip = VideoFile("video.mp4").subclip(start=5, duration=10)
export(clip, path="trimmed.mp4").run()from ffmpeg.inputs import VideoFile
from ffmpeg import export
extracted_audio = VideoFile("video.mp4").audio
export(extracted_audio, path="audio.mp3").run()from ffmpeg import FFmpeg
from ffmpeg.inputs import VideoFile, AudioFile
video = VideoFile("video.mp4")
audio = AudioFile("audio.mp3")
ffmpeg = FFmpeg()
ffmpeg.output(video.video, audio, path="merged.mp4")
ffmpeg.run()from ffmpeg import FFmpeg
from ffmpeg.inputs import VideoFile, ImageFile
from ffmpeg.filters import apply, Overlay
video = VideoFile("video.mp4")
logo = ImageFile("logo.png")
watermarked = apply(Overlay(logo, x=10, y=10), video)
ffmpeg = FFmpeg()
ffmpeg.output(watermarked, path="watermarked.mp4")
ffmpeg.run()More recipes and full explanations are in the docs, including Cookbooks and Examples.
This project does not install ffmpeg utility automatically.
Verify ffmpeg is installed:
ffmpeg -versionUsing winget:
winget install --id=Gyan.FFmpeg -eor download and install FFmpeg from FFmpeg official website:
- Download the latest FFmpeg build from here.
- Extract the archive and add the
bindirectory to your systemPATH.
Using Homebrew:
brew install ffmpegFor Debian/Ubuntu:
sudo apt install ffmpeg