`ffmpegio-core`: Media I/O with FFmpeg in Python
===================================================
|pypi| |pypi-status| |pypi-pyvers| |github-license| |github-status|
.. |pypi| image:: https://img.shields.io/pypi/v/ffmpegio
:alt: PyPI
.. |pypi-status| image:: https://img.shields.io/pypi/status/ffmpegio
:alt: PyPI - Status
.. |pypi-pyvers| image:: https://img.shields.io/pypi/pyversions/ffmpegio
:alt: PyPI - Python Version
.. |github-license| image:: https://img.shields.io/github/license/python-ffmpegio/python-ffmpegio
:alt: GitHub License
.. |github-status| image:: https://img.shields.io/github/workflow/status/python-ffmpegio/python-ffmpegio/Run%20Tests
:alt: GitHub Workflow Status
Python `ffmpegio` package aims to bring the full capability of `FFmpeg <https://ffmpeg.org>`__
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.
Install the full `ffmpegio` package via ``pip``:
.. code-block:: bash
pip install ffmpegio
If `numpy.ndarray` data I/O is not needed, instead use
.. code-block:: bash
pip install ffmpegio-core
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
-------------
Visit our `GitHub page here <https://python-ffmpegio.github.io/python-ffmpegio/>`__
Examples
--------
To import `ffmpegio`
.. code-block:: python
>>> import ffmpegio
- `Transcoding <transcoding_>`_
- `Read Audio Files <Read Audio Files_>`_
- `Read Image Files / Capture Video Frames <Read Image Files / Capture Video Frames_>`_
- `Read Video Files <Read Video Files_>`_
- `Read Multiple Files or Streams <Read Multiple Files or Streams_>`_
- `Write Audio, Image, & Video Files <Write Audio, Image, & Video Files_>`_
- `Filter Audio, Image, & Video Data <Filter Audio, Image, & Video Data_>`_
- `Stream I/O <Stream I/O_>`_
- `Device I/O Enumeration <Device I/O Enumeration_>`_
- `Progress Callback <Progress Callback_>`_
- `Filtergraph Builder`_
- `Run FFmpeg and FFprobe Directly <Run FFmpeg and FFprobe Directly_>`_
Transcoding
^^^^^^^^^^^
.. code-block:: python
>>> # transcode, overwrite output file if exists, showing the FFmpeg log
>>> ffmpegio.transcode('input.avi', 'output.mp4', overwrite=True, show_log=True)
>>> # 1-pass H.264 transcoding
>>> ffmpegio.transcode('input.avi', 'output.mkv', vcodec='libx264', show_log=True,
>>> preset='slow', crf=22, acodec='copy')
>>> # 2-pass H.264 transcoding
>>> ffmpegio.transcode('input.avi', 'output.mkv', two_pass=True, show_log=True,
>>> **{'c:v':'libx264', 'b:v':'2600k', 'c:a':'aac', 'b:a':'128k'})
>>> # concatenate videos using concat demuxer
>>> files = ['/video/video1.mkv','/video/video2.mkv']
>>> ffconcat = ffmpegio.FFConcat()
>>> ffconcat.add_files(files)
>>> with ffconcat: # generates temporary ffconcat file
>>> ffmpegio.transcode(ffconcat, 'output.mkv', f_in='concat', codec='copy', safe_in=0)
Read Audio Files
^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # 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 filtered audio samples first 10 seconds
>>> # filter: equalizer which attenuate 10 dB at 1 kHz with a bandwidth of 200 Hz
>>> fs, x = ffmpegio.audio.read('myaudio.mp3', t=10.0, af='equalizer=f=1000:t=h:width=200:g=-10')
Read Image Files / Capture Video Frames
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # list supported image extensions
>>> ffmpegio.caps.muxer_info('image2')['extensions']
['bmp', 'dpx', 'exr', 'jls', 'jpeg', 'jpg', 'ljpg', 'pam', 'pbm', 'pcx', 'pfm', 'pgm', 'pgmyuv',
'png', 'ppm', 'sgi', 'tga', 'tif', 'tiff', 'jp2', 'j2c', 'j2k', 'xwd', 'sun', 'ras', 'rs', 'im1',
'im8', 'im24', 'sunras', 'xbm', 'xface', 'pix', 'y']
>>> # 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')
Read Video Files
^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # read 50 video frames at t=00:32:40 then convert to grayscale
>>> fs, F = ffmpegio.video.read('myvideo.mp4', ss='00:32:40', vframes=50, pix_fmt='gray')
>>> # fs: frame rate in frames/second, F: [nframes x height x width x ncomp] numpy array
>>> # 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')
Read Multiple Files or Streams
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # read both video and audio streams (1 ea)
>>> rates, data = ffmpegio.media.read('mymedia.mp4')
>>> # rates: dict of frame rate and sampling rate: keys="v:0" and "a:0"
>>> # data: dict of video frame array and audio sample array: keys="v:0" and "a:0"
>>> # combine video and audio files
>>> rates, data = ffmpegio.media.read('myvideo.mp4','myaudio.mp3')
>>> # get output of complex filtergraph (can take multiple inputs)
>>> expr = "[v:0]split=2[out0][l1];[l1]edgedetect[out1]"
>>> rates, data = ffmpegio.media.read('myvideo.mp4',filter_complex=expr,map=['[out0]','[out1]'])
>>> # rates: dict of frame rates: keys="v:0" and "v:1"
>>> # data: dict of video frame arrays: keys="v:0" and "v:1"
Write Audio, Image, & Video Files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # create a video file from a numpy array
>>> ffmpegio.video.write('myvideo.mp4', rate, F)
>>> # create an image file from a numpy array
>>> ffmpegio.image.write('myimage.png', F)
>>> # create an audio file from a numpy array
>>> ffmpegio.audio.write('myaudio.mp3', rate, x)
Filter Audio, Image, & Video Data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # Add fade-in and fade-out effects to audio data
>>> fs_out, y = ffmpegio.audio.filter('afade=t=in:ss=0:d=15,afade=t=out:st=875:d=25', fs_in, x)
>>> # Apply mirror effect to an image
>>> I_out = ffmpegio.image.filter('crop=iw/2:ih:0:0,split[left][tmp];[tmp]hflip[right];[left][right] hstack', I_in)
>>> # Add text at the center of the video frame
>>> filter = "drawtext=fontsize=30:fontfile=FreeSerif.ttf:text='hello world':x=(w-text_w)/2:y=(h-text_h)/2"
>>> fs_out, F_out = ffmpegio.video.filter(filter, fs_in, F_in)
Stream I/O
^^^^^^^^^^
.. code-block:: python
>>> # 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
^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # build complex filtergraph
>>> from ffmpegio import filtergraph as fgb
>>>
>>> v0 = "[0]" >> fgb.trim(start_frame=10, end_frame=20)
>>> v1 = "[0]" >> fgb.trim(start_frame=30, end_frame=40)
>>> v3 = "[1]" >> fgb.hflip()
>>> v2 = (v0 | v1) + fgb.concat(2)
>>> v5 = (v2|v3) + fgb.overlay(eof_action='repeat') + fgb.drawbox(50, 50, 120, 120, 'red', t=5)
>>> v5
<ffmpegio.filtergraph.Graph object at 0x1e67f955b80>
FFmpeg expression: "[0]trim=start_frame=10:end_frame=20[L0];[0]trim=start_frame=30:end_frame=40[L1];[L0][L1]concat=2[L2];[1]hflip[L3];[L2][L3]overlay=eof_action=repeat,drawbox=50:50:120:120:red:t=5"
Number of chains: 5
chain[0]: [0]trim=start_frame=10:end_frame=20[L0];
chain[1]: [0]trim=start_frame=30:end_frame=40[L1];
chain[2]: [L0][L1]concat=2[L2];
chain[3]: [1]hflip[L3];
chain[4]: [L2][L3]overlay=eof_action=repeat,drawbox=50:50:120:120:red:t=5
Available input pads (0):
Available output pads: (1): (4, 1, 0)
Device I/O Enumeration
^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> # record 5 minutes of audio from Windows microphone
>>> fs, x = ffmpegio.audio.read('a:0', f_in='dshow', sample_fmt='dbl', t=300)
>>> # capture Windows' webcam frame
>>> with ffmpegio.open('v:0', 'rv', f_in='dshow') as webcam,
>>> for frame in webcam:
>>> process_frame(frame)
Progress Callback
^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> import pprint
>>> # progress callback
>>> def progress(info, done):
>>> pprint(info) # bunch of stats
>>> if done:
>>> print('video decoding completed')
>>> else:
>>> return check_cancel_command(): # return True to kill immediately
>>> # can be used in any butch processing
>>> rate, F = ffmpegio.video.read('myvideo.mp4', progress=progress)
>>> # as well as for stream processing
>>> with ffmpegio.open('myvideo.mp4', 'rv', blocksize=100, progress=progress) as fin:
>>> for frames in fin:
>>> myprocess(frames)
Run FFmpeg and FFprobe Directly
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> from ffmpegio import ffmpeg, FFprobe, ffmpegprocess
>>> from subprocess import PIPE
>>> # call with options as a long string
>>> ffmpeg('-i input.avi -b:v 64k -bufsize 64k output.avi')
>>> # or call with list of options
>>> ffmpeg(['-i', 'input.avi' ,'-r', '24', 'output.avi'])
>>> # the same for ffprobe
>>> ffprobe('ffprobe -show_streams -select_streams a INPUT')
>>> # specify subprocess arguments to capture stdout
>>> out = ffprobe('ffprobe -of json -show_frames INPUT',
stdout=PIPE, universal_newlines=True).stdout
>>> # use ffmpegprocess to take advantage of ffmpegio's default behaviors
>>> out = ffmpegprocess.run({"inputs": [("input.avi", None)],
"outputs": [("out1.mp4", None),
("-", {"f": "rawvideo", "vframes": 1, "pix_fmt": "gray", "an": None})
}, capture_log=True)
>>> print(out.stderr) # print the captured FFmpeg logs (banner text omitted)
>>> b = out.stdout # width*height bytes of the first frame
Raw data
{
"_id": null,
"home_page": null,
"name": "ffmpegio-core",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "multimedia, ffmpeg",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c7/f8/d0efc4022efdcc5fe0100010034bce2e4c3c39b1332733a56af25a9b539b/ffmpegio_core-0.10.0.tar.gz",
"platform": null,
"description": "`ffmpegio-core`: Media I/O with FFmpeg in Python\n===================================================\n\n|pypi| |pypi-status| |pypi-pyvers| |github-license| |github-status|\n\n.. |pypi| image:: https://img.shields.io/pypi/v/ffmpegio\n :alt: PyPI\n.. |pypi-status| image:: https://img.shields.io/pypi/status/ffmpegio\n :alt: PyPI - Status\n.. |pypi-pyvers| image:: https://img.shields.io/pypi/pyversions/ffmpegio\n :alt: PyPI - Python Version\n.. |github-license| image:: https://img.shields.io/github/license/python-ffmpegio/python-ffmpegio\n :alt: GitHub License\n.. |github-status| image:: https://img.shields.io/github/workflow/status/python-ffmpegio/python-ffmpegio/Run%20Tests\n :alt: GitHub Workflow Status\n\nPython `ffmpegio` package aims to bring the full capability of `FFmpeg <https://ffmpeg.org>`__\nto read, write, probe, and manipulate multimedia data to Python. FFmpeg is an open-source cross-platform \nmultimedia framework, which can handle most of the multimedia formats available today.\n\n.. note::\n \n Since v0.3.0, `ffmpegio` Python distribution package has been split into `ffmpegio-core` and `ffmpegio` to allow\n Numpy-independent installation.\n\nInstall the full `ffmpegio` package via ``pip``:\n\n.. code-block:: bash\n\n pip install ffmpegio\n\nIf `numpy.ndarray` data I/O is not needed, instead use \n\n.. code-block:: bash\n\n pip install ffmpegio-core\n\nMain Features\n-------------\n\n* Pure-Python light-weight package interacting with FFmpeg executable found in \n the system\n* Transcode a media file to another in Python\n* Read, write, filter, and create functions for audio, image, and video data\n* Context-managing `ffmpegio.open` to perform stream read/write operations of video and audio\n* Automatically detect and convert audio & video formats to and from `numpy.ndarray` properties\n* Probe media file information\n* Accepts all FFmpeg options including filter graphs\n* Supports a user callback whenever FFmpeg updates its progress information file \n (see `-progress` FFmpeg option)\n* `ffconcat` scripter to make the use of `-f concat` demuxer easier\n* I/O device enumeration to eliminate the need to look up device names. (currently supports only: Windows DirectShow)\n* More features to follow\n\nDocumentation\n-------------\n\nVisit our `GitHub page here <https://python-ffmpegio.github.io/python-ffmpegio/>`__\n\nExamples\n--------\n\nTo import `ffmpegio`\n\n.. code-block:: python\n\n >>> import ffmpegio\n\n- `Transcoding <transcoding_>`_\n- `Read Audio Files <Read Audio Files_>`_\n- `Read Image Files / Capture Video Frames <Read Image Files / Capture Video Frames_>`_\n- `Read Video Files <Read Video Files_>`_\n- `Read Multiple Files or Streams <Read Multiple Files or Streams_>`_\n- `Write Audio, Image, & Video Files <Write Audio, Image, & Video Files_>`_\n- `Filter Audio, Image, & Video Data <Filter Audio, Image, & Video Data_>`_\n- `Stream I/O <Stream I/O_>`_\n- `Device I/O Enumeration <Device I/O Enumeration_>`_\n- `Progress Callback <Progress Callback_>`_\n- `Filtergraph Builder`_\n- `Run FFmpeg and FFprobe Directly <Run FFmpeg and FFprobe Directly_>`_\n\nTranscoding\n^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # transcode, overwrite output file if exists, showing the FFmpeg log\n >>> ffmpegio.transcode('input.avi', 'output.mp4', overwrite=True, show_log=True) \n\n >>> # 1-pass H.264 transcoding\n >>> ffmpegio.transcode('input.avi', 'output.mkv', vcodec='libx264', show_log=True,\n >>> preset='slow', crf=22, acodec='copy') \n\n >>> # 2-pass H.264 transcoding\n >>> ffmpegio.transcode('input.avi', 'output.mkv', two_pass=True, show_log=True,\n >>> **{'c:v':'libx264', 'b:v':'2600k', 'c:a':'aac', 'b:a':'128k'}) \n\n >>> # concatenate videos using concat demuxer\n >>> files = ['/video/video1.mkv','/video/video2.mkv']\n >>> ffconcat = ffmpegio.FFConcat()\n >>> ffconcat.add_files(files)\n >>> with ffconcat: # generates temporary ffconcat file\n >>> ffmpegio.transcode(ffconcat, 'output.mkv', f_in='concat', codec='copy', safe_in=0)\n\nRead Audio Files\n^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # read audio samples in its native sample format and return all channels\n >>> fs, x = ffmpegio.audio.read('myaudio.wav') \n >>> # fs: sampling rate in samples/second, x: [nsamples x nchannels] numpy array\n\n >>> # read audio samples from 24.15 seconds to 63.2 seconds, pre-convert to mono in float data type \n >>> fs, x = ffmpegio.audio.read('myaudio.flac', ss=24.15, to=63.2, sample_fmt='dbl', ac=1)\n\n >>> # read filtered audio samples first 10 seconds\n >>> # filter: equalizer which attenuate 10 dB at 1 kHz with a bandwidth of 200 Hz \n >>> fs, x = ffmpegio.audio.read('myaudio.mp3', t=10.0, af='equalizer=f=1000:t=h:width=200:g=-10')\n\nRead Image Files / Capture Video Frames\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # list supported image extensions\n >>> ffmpegio.caps.muxer_info('image2')['extensions']\n ['bmp', 'dpx', 'exr', 'jls', 'jpeg', 'jpg', 'ljpg', 'pam', 'pbm', 'pcx', 'pfm', 'pgm', 'pgmyuv', \n 'png', 'ppm', 'sgi', 'tga', 'tif', 'tiff', 'jp2', 'j2c', 'j2k', 'xwd', 'sun', 'ras', 'rs', 'im1', \n 'im8', 'im24', 'sunras', 'xbm', 'xface', 'pix', 'y']\n\n >>> # read BMP image with auto-detected pixel format (rgb24, gray, rgba, or ya8)\n >>> I = ffmpegio.image.read('myimage.bmp') # I: [height x width x ncomp] numpy array\n\n >>> # read JPEG image, then convert to grayscale and proportionally scale so the width is 480 pixels\n >>> I = ffmpegio.image.read('myimage.jpg', pix_fmt='grayscale', s='480x-1')\n\n >>> # read PNG image with transparency, convert it to plain RGB by filling transparent pixels orange\n >>> I = ffmpegio.image.read('myimage.png', pix_fmt='rgb24', fill_color='orange')\n\n >>> # capture video frame at timestamp=4:25.3 and convert non-square pixels to square\n >>> I = ffmpegio.image.read('myvideo.mpg', ss='4:25.3', square_pixels='upscale')\n\n >>> # capture 5 video frames and tile them on 3x2 grid with 7px between them, and 2px of initial margin\n >>> I = ffmpegio.image.read('myvideo.mp4', vf='tile=3x2:nb_frames=5:padding=7:margin=2')\n\n >>> # create spectrogram of the audio input (must specify pix_fmt if input is audio)\n >>> I = ffmpegio.image.read('myaudio.mp3', filter_complex='showspectrumpic=s=960x540', pix_fmt='rgb24')\n\n\nRead Video Files\n^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # read 50 video frames at t=00:32:40 then convert to grayscale\n >>> fs, F = ffmpegio.video.read('myvideo.mp4', ss='00:32:40', vframes=50, pix_fmt='gray')\n >>> # fs: frame rate in frames/second, F: [nframes x height x width x ncomp] numpy array\n\n >>> # get running spectrogram of audio input (must specify pix_fmt if input is audio)\n >>> fs, F = ffmpegio.video.read('myvideo.mp4', pix_fmt='rgb24', filter_complex='showspectrum=s=1280x480')\n \n\nRead Multiple Files or Streams\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # read both video and audio streams (1 ea)\n >>> rates, data = ffmpegio.media.read('mymedia.mp4')\n >>> # rates: dict of frame rate and sampling rate: keys=\"v:0\" and \"a:0\"\n >>> # data: dict of video frame array and audio sample array: keys=\"v:0\" and \"a:0\"\n\n >>> # combine video and audio files\n >>> rates, data = ffmpegio.media.read('myvideo.mp4','myaudio.mp3')\n\n >>> # get output of complex filtergraph (can take multiple inputs)\n >>> expr = \"[v:0]split=2[out0][l1];[l1]edgedetect[out1]\"\n >>> rates, data = ffmpegio.media.read('myvideo.mp4',filter_complex=expr,map=['[out0]','[out1]'])\n >>> # rates: dict of frame rates: keys=\"v:0\" and \"v:1\"\n >>> # data: dict of video frame arrays: keys=\"v:0\" and \"v:1\"\n\nWrite Audio, Image, & Video Files\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # create a video file from a numpy array\n >>> ffmpegio.video.write('myvideo.mp4', rate, F)\n\n >>> # create an image file from a numpy array\n >>> ffmpegio.image.write('myimage.png', F)\n\n >>> # create an audio file from a numpy array\n >>> ffmpegio.audio.write('myaudio.mp3', rate, x)\n\nFilter Audio, Image, & Video Data\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # Add fade-in and fade-out effects to audio data\n >>> fs_out, y = ffmpegio.audio.filter('afade=t=in:ss=0:d=15,afade=t=out:st=875:d=25', fs_in, x)\n\n >>> # Apply mirror effect to an image\n >>> I_out = ffmpegio.image.filter('crop=iw/2:ih:0:0,split[left][tmp];[tmp]hflip[right];[left][right] hstack', I_in)\n\n >>> # Add text at the center of the video frame\n >>> filter = \"drawtext=fontsize=30:fontfile=FreeSerif.ttf:text='hello world':x=(w-text_w)/2:y=(h-text_h)/2\"\n >>> fs_out, F_out = ffmpegio.video.filter(filter, fs_in, F_in)\n\nStream I/O\n^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # process video 100 frames at a time and save output as a new video \n >>> # with the same frame rate\n >>> with ffmpegio.open('myvideo.mp4', 'rv', blocksize=100) as fin,\n >>> ffmpegio.open('myoutput.mp4', 'wv', rate=fin.rate) as fout:\n >>> for frames in fin:\n >>> fout.write(myprocess(frames))\n\nFiltergraph Builder\n^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # build complex filtergraph\n >>> from ffmpegio import filtergraph as fgb\n >>>\n >>> v0 = \"[0]\" >> fgb.trim(start_frame=10, end_frame=20)\n >>> v1 = \"[0]\" >> fgb.trim(start_frame=30, end_frame=40)\n >>> v3 = \"[1]\" >> fgb.hflip()\n >>> v2 = (v0 | v1) + fgb.concat(2)\n >>> v5 = (v2|v3) + fgb.overlay(eof_action='repeat') + fgb.drawbox(50, 50, 120, 120, 'red', t=5)\n >>> v5\n <ffmpegio.filtergraph.Graph object at 0x1e67f955b80>\n FFmpeg expression: \"[0]trim=start_frame=10:end_frame=20[L0];[0]trim=start_frame=30:end_frame=40[L1];[L0][L1]concat=2[L2];[1]hflip[L3];[L2][L3]overlay=eof_action=repeat,drawbox=50:50:120:120:red:t=5\"\n Number of chains: 5\n chain[0]: [0]trim=start_frame=10:end_frame=20[L0];\n chain[1]: [0]trim=start_frame=30:end_frame=40[L1];\n chain[2]: [L0][L1]concat=2[L2];\n chain[3]: [1]hflip[L3];\n chain[4]: [L2][L3]overlay=eof_action=repeat,drawbox=50:50:120:120:red:t=5 \n Available input pads (0): \n Available output pads: (1): (4, 1, 0)\n\nDevice I/O Enumeration\n^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> # record 5 minutes of audio from Windows microphone\n >>> fs, x = ffmpegio.audio.read('a:0', f_in='dshow', sample_fmt='dbl', t=300)\n\n >>> # capture Windows' webcam frame\n >>> with ffmpegio.open('v:0', 'rv', f_in='dshow') as webcam,\n >>> for frame in webcam:\n >>> process_frame(frame)\n\nProgress Callback\n^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> import pprint\n\n >>> # progress callback\n >>> def progress(info, done):\n >>> pprint(info) # bunch of stats\n >>> if done:\n >>> print('video decoding completed')\n >>> else:\n >>> return check_cancel_command(): # return True to kill immediately\n \n >>> # can be used in any butch processing\n >>> rate, F = ffmpegio.video.read('myvideo.mp4', progress=progress)\n\n >>> # as well as for stream processing\n >>> with ffmpegio.open('myvideo.mp4', 'rv', blocksize=100, progress=progress) as fin:\n >>> for frames in fin:\n >>> myprocess(frames)\n\nRun FFmpeg and FFprobe Directly\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n >>> from ffmpegio import ffmpeg, FFprobe, ffmpegprocess\n >>> from subprocess import PIPE\n\n >>> # call with options as a long string\n >>> ffmpeg('-i input.avi -b:v 64k -bufsize 64k output.avi')\n\n >>> # or call with list of options\n >>> ffmpeg(['-i', 'input.avi' ,'-r', '24', 'output.avi'])\n\n >>> # the same for ffprobe\n >>> ffprobe('ffprobe -show_streams -select_streams a INPUT')\n\n >>> # specify subprocess arguments to capture stdout\n >>> out = ffprobe('ffprobe -of json -show_frames INPUT', \n stdout=PIPE, universal_newlines=True).stdout\n\n >>> # use ffmpegprocess to take advantage of ffmpegio's default behaviors\n >>> out = ffmpegprocess.run({\"inputs\": [(\"input.avi\", None)],\n \"outputs\": [(\"out1.mp4\", None),\n (\"-\", {\"f\": \"rawvideo\", \"vframes\": 1, \"pix_fmt\": \"gray\", \"an\": None})\n }, capture_log=True)\n >>> print(out.stderr) # print the captured FFmpeg logs (banner text omitted)\n >>> b = out.stdout # width*height bytes of the first frame\n",
"bugtrack_url": null,
"license": "GPL-2.0 License",
"summary": "Media I/O with FFmpeg",
"version": "0.10.0",
"project_urls": {
"Discussions": "https://github.com/python-ffmpegio/python-ffmpegio/discussions",
"Documentation": "https://python-ffmpegio.github.io/python-ffmpegio/",
"Issues": "https://github.com/python-ffmpegio/python-ffmpegio/issues",
"Pull_Requests": "https://github.com/python-ffmpegio/python-ffmpegio/pulls",
"Repository": "https://github.com/python-ffmpegio/python-ffmpegio"
},
"split_keywords": [
"multimedia",
" ffmpeg"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6944d62a059a2c93161d022ea4045960cd7d374a48d12f9f6ac35c396cab45f2",
"md5": "d078bbf798aa2bcf1b39d64281f78657",
"sha256": "1cab40edd977b1205695c7ab89e6c5c97f33dd738177d9986a26c26dca58145b"
},
"downloads": -1,
"filename": "ffmpegio_core-0.10.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d078bbf798aa2bcf1b39d64281f78657",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 154767,
"upload_time": "2024-07-04T03:31:33",
"upload_time_iso_8601": "2024-07-04T03:31:33.750934Z",
"url": "https://files.pythonhosted.org/packages/69/44/d62a059a2c93161d022ea4045960cd7d374a48d12f9f6ac35c396cab45f2/ffmpegio_core-0.10.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c7f8d0efc4022efdcc5fe0100010034bce2e4c3c39b1332733a56af25a9b539b",
"md5": "f7a347457c3dc31bba09881ce465e849",
"sha256": "aa56b504273ee2a64960daa15ac07960c6d9dcc95e02821e9c264a26a3f5f57a"
},
"downloads": -1,
"filename": "ffmpegio_core-0.10.0.tar.gz",
"has_sig": false,
"md5_digest": "f7a347457c3dc31bba09881ce465e849",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 168754,
"upload_time": "2024-07-04T03:31:35",
"upload_time_iso_8601": "2024-07-04T03:31:35.941398Z",
"url": "https://files.pythonhosted.org/packages/c7/f8/d0efc4022efdcc5fe0100010034bce2e4c3c39b1332733a56af25a9b539b/ffmpegio_core-0.10.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-04 03:31:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "python-ffmpegio",
"github_project": "python-ffmpegio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "ffmpegio-core"
}