GitHub Python Ffmpegio - Python Ffmpegio
GitHub Python Ffmpegio - Python Ffmpegio
GPL-2.0 license
Star Notifications
Python ffmpegio package aims to bring the full capability of FFmpeg to read, write, probe, and manipulate multimedia data to Python. FFmpeg
is an open-source cross-platform multimedia framework, which can handle most of the multimedia formats available today.
Note
Since v0.3.0, ffmpegio Python distribution package has been split into ffmpegio-core and ffmpegio to allow Numpy-independent installation.
https://github.com/python-ffmpegio/python-ffmpegio 1/6
7/8/24, 11:25 PM GitHub - python-ffmpegio/python-ffmpegio: Python package to read/write media files with FFmpeg
Main Features
Pure-Python light-weight package interacting with FFmpeg executable found in the system
Transcode a media file to another in Python
Read, write, filter, and create functions for audio, image, and video data
Context-managing ffmpegio.open to perform stream read/write operations of video and audio
Automatically detect and convert audio & video formats to and from numpy.ndarray properties
Probe media file information
Accepts all FFmpeg options including filter graphs
Supports a user callback whenever FFmpeg updates its progress information file (see -progress FFmpeg option)
ffconcat scripter to make the use of -f concat demuxer easier
I/O device enumeration to eliminate the need to look up device names. (currently supports only: Windows DirectShow)
More features to follow
Documentation
Examples
To import ffmpegio
Transcoding
Read Audio Files
Read Image Files / Capture Video Frames
Read Video Files
Read Multiple Files or Streams
Write Audio, Image, & Video Files
Filter Audio, Image, & Video Data
Stream I/O
Device I/O Enumeration
Progress Callback
Filtergraph Builder
Run FFmpeg and FFprobe Directly
Transcoding
>>> # transcode, overwrite output file if exists, showing the FFmpeg log
>>> ffmpegio.transcode('input.avi', 'output.mp4', overwrite=True, show_log=True)
https://github.com/python-ffmpegio/python-ffmpegio 2/6
7/8/24, 11:25 PM GitHub - python-ffmpegio/python-ffmpegio: Python package to read/write media files with FFmpeg
>>> with ffconcat: # generates temporary ffconcat file
>>> ffmpegio.transcode(ffconcat, 'output.mkv', f_in='concat', codec='copy', safe_in=0)
>>> # read audio samples in its native sample format and return all channels
>>> fs, x = ffmpegio.audio.read('myaudio.wav')
>>> # fs: sampling rate in samples/second, x: [nsamples x nchannels] numpy array
>>> # read audio samples from 24.15 seconds to 63.2 seconds, pre-convert to mono in float data type
>>> fs, x = ffmpegio.audio.read('myaudio.flac', ss=24.15, to=63.2, sample_fmt='dbl', ac=1)
>>> # read BMP image with auto-detected pixel format (rgb24, gray, rgba, or ya8)
>>> I = ffmpegio.image.read('myimage.bmp') # I: [height x width x ncomp] numpy array
>>> # read JPEG image, then convert to grayscale and proportionally scale so the width is 480 pixels
>>> I = ffmpegio.image.read('myimage.jpg', pix_fmt='grayscale', s='480x-1')
>>> # read PNG image with transparency, convert it to plain RGB by filling transparent pixels orange
>>> I = ffmpegio.image.read('myimage.png', pix_fmt='rgb24', fill_color='orange')
>>> # capture video frame at timestamp=4:25.3 and convert non-square pixels to square
>>> I = ffmpegio.image.read('myvideo.mpg', ss='4:25.3', square_pixels='upscale')
>>> # capture 5 video frames and tile them on 3x2 grid with 7px between them, and 2px of initial margin
>>> I = ffmpegio.image.read('myvideo.mp4', vf='tile=3x2:nb_frames=5:padding=7:margin=2')
>>> # create spectrogram of the audio input (must specify pix_fmt if input is audio)
>>> I = ffmpegio.image.read('myaudio.mp3', filter_complex='showspectrumpic=s=960x540', pix_fmt='rgb24')
>>> # get running spectrogram of audio input (must specify pix_fmt if input is audio)
>>> fs, F = ffmpegio.video.read('myvideo.mp4', pix_fmt='rgb24', filter_complex='showspectrum=s=1280x480')
https://github.com/python-ffmpegio/python-ffmpegio 3/6
7/8/24, 11:25 PM GitHub - python-ffmpegio/python-ffmpegio: Python package to read/write media files with FFmpeg
>>> # rates: dict of frame rates: keys="v:0" and "v:1"
>>> # data: dict of video frame arrays: keys="v:0" and "v:1"
Stream I/O
>>> # process video 100 frames at a time and save output as a new video
>>> # with the same frame rate
>>> with ffmpegio.open('myvideo.mp4', 'rv', blocksize=100) as fin,
>>> ffmpegio.open('myoutput.mp4', 'wv', rate=fin.rate) as fout:
>>> for frames in fin:
>>> fout.write(myprocess(frames))
Filtergraph Builder
https://github.com/python-ffmpegio/python-ffmpegio 4/6
7/8/24, 11:25 PM GitHub - python-ffmpegio/python-ffmpegio: Python package to read/write media files with FFmpeg
>>> # capture Windows' webcam frame
>>> with ffmpegio.open('v:0', 'rv', f_in='dshow') as webcam,
>>> for frame in webcam:
>>> process_frame(frame)
Progress Callback
Releases 35
v0.10.0 Latest
5 days ago
+ 34 releases
Packages
No packages published
Contributors 3
https://github.com/python-ffmpegio/python-ffmpegio 5/6
7/8/24, 11:25 PM GitHub - python-ffmpegio/python-ffmpegio: Python package to read/write media files with FFmpeg
dependabot[bot]
Languages
https://github.com/python-ffmpegio/python-ffmpegio 6/6