Skip to content

Latest commit

 

History

History
122 lines (104 loc) · 4.7 KB

File metadata and controls

122 lines (104 loc) · 4.7 KB
.. py:currentmodule:: ffmpegio.analyze

:py:mod:`ffmpegio.analyze`: Frame Metadata Analysis Module

There are a number of FFmpeg filters which analyze video and audio streams and inject per-frame results into frame metadata to be used in a later stage of a filtergraph. :py:mod:`run` retrieves the injected metadata by appending metadata and ametadata filters and logs the frame metadata outputs. You can use either the supplied Python classes or a custom class, which conforms to :py:class:`MetadataLogger` interface to specify the FFmpeg filter and to log its output.

Simple examples

The following example detects intervals of pure black frames within the first 30 seconds of the video:

>>> from ffmpegio import analyze as ffa
>>> logger, *_ = ffa.run("input.mp4", ffa.BlackDetect(pix_th=0.0), t=30)
>>> print(logger.output)
Black(interval=[[0.0, 0.166667]])
  • Assign options (e.g., pix_th) of the underlying FFmpeg analysis filter (e.g., blackdetect) as keyword options of its logger object (e.g., BlackDetect)
  • FFmpeg input options (e.g., t) can be assigned as the keyword arguments of :py:func:`run`.
  • The logger output is a namedtuple.

Next example analyzes the audio stream and plot its spectral entropy of the first channel:

>>> logger,*_ = ffa.run("input.mp4", ffa.ASpectralStats(measure='entropy'))
>>> plt.plot(logger.output.time, logger.output.entropy[0])

Finally, multiple loggers can run simultaneously:

>>> loggers = [
...   ffa.AStats(),       # time domain statistics of audio channels
...   ffa.BBox(),         # bounding box of video frames
...   ffa.BlackDetect()]  # detect black frame intervals
...
>>> ffa.run("input.mp4", *loggers, t=10)
>>> print(loggers[0].output)
>>> print(loggers[1].output)
>>> print(loggers[2].output)

Available filter loggers

Following loggers are currently available as a part of the :py:mod:`analyze` module

Type Python class FFmpeg filter Description
audio :py:class:`APhaseMeter` aphasemeter Measures phase of input audio
:py:class:`ASpectralStats` aspectralstats Frequency domain statistical information
:py:class:`AStats` astats Time domain statistical information
:py:class:`SilenceDetect` silencedetect Detect silence
video :py:class:`BBox` bbox Compute the bounding box
:py:class:`BlackDetect` blackdetect Detect intervals of black frames
:py:class:`BlackFrame` blackframe Detect black frames
:py:class:`BlurDetect` blurdetect Detect blurriness of frames
:py:class:`FreezeDetect` freezedetect Detect frozen video
  :py:class:`PSNR` psnr Compute peak signal to noise ratio
:py:class:`ScDet` scdet Detect video scene change

Analyze API Reference

.. autosummary::
   :nosignatures:
   :recursive:

   run
   ffmpegio.video.detect
   ffmpegio.audio.detect
   MetadataLogger
.. autofunction:: ffmpegio.analyze.run
.. autofunction:: ffmpegio.video.detect
.. autofunction:: ffmpegio.audio.detect
.. autoclass:: MetadataLogger
  :members:
.. autoclass:: APhaseMeter
  :members:
.. autoclass:: ASpectralStats
  :members:
.. autoclass:: AStats
  :members:
.. autoclass:: SilenceDetect
  :members:
.. autoclass:: BBox
  :members:
.. autoclass:: BlackDetect
  :members:
.. autoclass:: BlackFrame
  :members:
.. autoclass:: BlurDetect
  :members:
.. autoclass:: FreezeDetect
  :members:
.. autoclass:: ScDet
  :members: