Skip to main content

Bindings for FFmpegSource

Project description

ffms2 – Python bindings for FFmpegSource

Actions Status

This project is a fork that supports more recent versions of FFMS. The original repository can be found at https://bitbucket.org/spirit/ffms.

Example usage

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

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

Or you can create an indexer:

>>> indexer = ffms2.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:

>>> for track in indexer.track_info_list:
>>>     indexer.track_index_settings(track.num, 1, 0)
>>> index = indexer.do_indexing2()
>>> track_number = index.get_first_indexed_track_of_type(ffms2.FFMS_TYPE_VIDEO)
>>> vsource = ffms2.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, ..., 41, 41, 41], dtype=uint8)

Audio stuff:

>>> track_number = index.get_first_indexed_track_of_type(ffms2.FFMS_TYPE_AUDIO)
>>> asource = ffms2.AudioSource(source_file, track_number, index)
>>> aprops = asource.properties
>>> aprops.SampleRate, aprops.BitsPerSample, aprops.Channels
(48000, 16, 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
(-16191, 18824)

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

Installation

To install the package for Python 3, use:

$ ./setup.py install

Prerequisites

The API was designed to be an object-oriented and Pythonic version of the original FFmpegSource API.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ffms2-0.4.5.2.tar.gz (692.0 kB view details)

Uploaded Source

Built Distribution

ffms2-0.4.5.2-cp37-none-win_amd64.whl (34.4 MB view details)

Uploaded CPython 3.7 Windows x86-64

File details

Details for the file ffms2-0.4.5.2.tar.gz.

File metadata

  • Download URL: ffms2-0.4.5.2.tar.gz
  • Upload date:
  • Size: 692.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for ffms2-0.4.5.2.tar.gz
Algorithm Hash digest
SHA256 3b3ab7321e6a0c851770cbfb3c7815e2b5a499ac0e64a019c98eaa45c763fbfe
MD5 c7988e9ad28851c1ae3ca7cdb209984c
BLAKE2b-256 6b15ec345500f6e0b89b379e4d273631445e3176af45dcf744cff81b954ae017

See more details on using hashes here.

File details

Details for the file ffms2-0.4.5.2-cp37-none-win_amd64.whl.

File metadata

  • Download URL: ffms2-0.4.5.2-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 34.4 MB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for ffms2-0.4.5.2-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 26bfc732fab973dd7e5f2287ea00c35e43a32e006bd9216891f0eafef11c9269
MD5 ca744518a3fb1840753ffad67e39f643
BLAKE2b-256 2d546ed556b92f0b2ca2cca8af2840c8ebb2e78f1794cc9314046ab4e6cfa9c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page