Metadata-Version: 2.4
Name: ffms
Version: 0.4
Summary: Bindings for FFmpegSource
Project-URL: Homepage, https://github.com/hiddenspirit/ffms
Project-URL: Repository, https://github.com/hiddenspirit/ffms
Project-URL: Download, https://github.com/hiddenspirit/ffms/releases
Author-email: spirit <hiddenspirit@gmail.com>
License-Expression: LGPL-3.0-or-later
License-File: COPYING
License-File: COPYING.LESSER
Keywords: audio,bindings,ffmpeg,ffmpegsource,ffms,video
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Multimedia :: Video
Requires-Python: >=3.8
Requires-Dist: numpy
Requires-Dist: pywin32; sys_platform == 'win32'
Description-Content-Type: text/x-rst

ffms – Python bindings for FFmpegSource
=======================================


Example usage
-------------

If you don’t need to keep the index, create a video source right away:

>>> import ffms
>>> source_file = "test/CINT_Nik_H264_720_512kb.mp4"
>>> vsource = ffms.VideoSource(source_file)


Or you can create an indexer:

>>> indexer = ffms.Indexer(source_file)
>>> indexer.format_name
'mov,mp4,m4a,3gp,3g2,mj2'
>>> indexer.track_info_list
[TrackInfo(type=0, codec_name='h264'), TrackInfo(type=1, codec_name='aac')]


Then create the index for the video source:

>>> index = indexer.do_indexing(-1)
>>> track_number = index.get_first_indexed_track_of_type(ffms.FFMS_TYPE_VIDEO)
>>> vsource = ffms.VideoSource(source_file, track_number, index)


Extract information from the video source:

>>> vsource.properties.NumFrames
1430
>>> vsource.track.keyframes[:5]
[0, 12, 24, 36, 48]
>>> vsource.track.timecodes[:5]
[0.0, 41.666666666666664, 83.33333333333333, 125.0, 166.66666666666666]


Retrieve a video frame:

>>> frame = vsource.get_frame(0)
>>> frame.EncodedWidth, frame.EncodedHeight
(416, 240)
>>> frame.planes[0]
array([41, 41, 41, ...,  0,  0,  0], dtype=uint8)


Audio stuff:

>>> track_number = index.get_first_indexed_track_of_type(ffms.FFMS_TYPE_AUDIO)
>>> asource = ffms.AudioSource(source_file, track_number, index)
>>> aprops = asource.properties
>>> aprops.SampleRate, aprops.BitsPerSample, aprops.Channels
(48000, 32, 2)
>>> min_audio, max_audio = float("inf"), float("-inf")
>>> for audio in asource.linear_access(rate=100):
...     if audio.min() < min_audio:
...         min_audio = audio.min()
...     if audio.max() > max_audio:
...         max_audio = audio.max()
>>> min_audio, max_audio
(-0.4941235, 0.57445675)


``ffmsinfo.py`` is a demo script showing how this package can be used.


Installation
------------

Install from PyPI::

  $ pip install ffms

Or install the latest version from source::

  $ pip install git+https://github.com/hiddenspirit/ffms

You also need the FFmpegSource shared library (``libffms2``) installed and
reachable by the dynamic loader. On Debian/Ubuntu::

  $ sudo apt install libffms2-5

On Windows, place ``ffms2.dll`` (or ``ffms2-x64.dll``) next to your script or
in a directory on the library search path.


Prerequisites
-------------

- `Python 3.8+ <https://www.python.org>`_
- `FFmpegSource <https://github.com/FFMS/ffms2>`_ (the ``libffms2`` shared library)
- `numpy <https://www.numpy.org>`_
- `pywin32 <https://github.com/mhammond/pywin32>`_ (Windows only)


The API was designed to be an object-oriented and Pythonic version
of the original `FFmpegSource API
<https://github.com/FFMS/ffms2/blob/master/doc/ffms2-api.md>`_.
