ffms2 – Python bindings for FFmpegSource
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.
easy_usage.py is a demo script showing how write the index file to speed up access to the media file.
Installation
To install the package for Python 3, use:
$ ./setup.py install
Prerequisites
- Python 3.7+
- FFmpegSource
- numpy
- pywin32 (Windows only)
The API was designed to be an object-oriented and Pythonic version of the original FFmpegSource API.
Development
Thanks to GitHub actions, releasing a new version is only a matter of creating a tag on the newest master.
Metadata
Release files for ffms2 0.4.5.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ffms2-0.4.5.5.tar.gz | 693.2 kB | Without provenance | Details for ffms2-0.4.5.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ffms2-0.4.5.5-cp37.cp38.cp39-none-win_amd64.whl | CPython 3.9, CPython 3.7, CPython 3.8 | none | Windows x86-64 | Details for ffms2-0.4.5.5-cp37.cp38.cp39-none-win_amd64.whl |
Total release size: 36.5 MB
Release files / ffms2-0.4.5.5.tar.gz
| Download URL | ffms2-0.4.5.5.tar.gz |
|---|---|
| Size | 693.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dfd9b2a0078629723597cb37358795a3d3858effb4b7760f60c3a173ad50529
|
|
BLAKE2b-256 checksum How to use checksums |
f929a2a9afda2e49b4039c8e26c1090f2a8863837b97fd21fca5db097aff94b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
|
Release files / ffms2-0.4.5.5-cp37.cp38.cp39-none-win_amd64.whl
| Download URL | ffms2-0.4.5.5-cp37.cp38.cp39-none-win_amd64.whl |
|---|---|
| Size | 35.8 MB |
| Tags | CPython 3.7 CPython 3.8 CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1564c75505e6057634dab47df6895feaf1f4774a4fd4ce65730f268284bc6dd4
|
|
BLAKE2b-256 checksum How to use checksums |
e4d5bf83d494a1ade8315908e11324ad9c35e7f88d744b51e8a95984a6dbe788
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
|
Security for ffms2 0.4.5.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.