Skip to content

Latest commit

 

History

120 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FFmpeg-studio

PyPI License Docs GitHub stars

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.

diagram

Installation

From PyPi

pip install ffmpeg-studio

From Source

pip install git+https://github.com/electro199/ffmpeg-studio.git

Usage

ffmpeg-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()

Quick Examples

Trim a video

from ffmpeg.inputs import VideoFile
from ffmpeg import export

clip = VideoFile("video.mp4").subclip(start=5, duration=10)

export(clip, path="trimmed.mp4").run()

Extract audio from a video

from ffmpeg.inputs import VideoFile
from ffmpeg import export

extracted_audio = VideoFile("video.mp4").audio

export(extracted_audio, path="audio.mp3").run()

Merge separate video and audio files

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()

Add a watermark/logo overlay

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.

Install FFmpeg

This project does not install ffmpeg utility automatically.

Verify ffmpeg is installed:

ffmpeg -version

Windows

Using winget:

winget install --id=Gyan.FFmpeg  -e

or download and install FFmpeg from FFmpeg official website:

  1. Download the latest FFmpeg build from here.
  2. Extract the archive and add the bin directory to your system PATH.

macOS

Using Homebrew:

brew install ffmpeg

Linux

For Debian/Ubuntu:

sudo apt install ffmpeg

About

FFmpeg wrapper for Python with imporoved user experince

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages