Skip to content

Commit

Permalink
[docs] Update backend docs for MoviePy backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
Breakthrough committed Sep 21, 2023
1 parent e0d3ceb commit a58a966
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
git fetch --depth=1 https://github.com/Breakthrough/PySceneDetect.git refs/heads/resources:refs/remotes/origin/resources
git checkout refs/remotes/origin/resources -- tests/resources/
# TODO: Cache this: https://github.com/actions/cache
# TODO: Install ffmpeg/mkvtoolnix on all runners.
- name: Download FFMPEG
if: ${{ matrix.os == 'windows-latest' }}
Expand Down
15 changes: 15 additions & 0 deletions docs/cli/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Backends

PySceneDetect supports multiple backends for video input. Some can be configured by using :ref:`a config file <scenedetect_cli-config_file>`. Installed backends can be verified by running ``scenedetect version --all``.

Note that the `scenedetect` command output is generated as a post-processing step, after scene detection completes. Most commands require the ability for the input to be replayed, and preferably it should also support seeking. Network streams and other input types are supported with certain backends, however integration with live streams requires use of the Python API.


=======================================================================
OpenCV
Expand All @@ -27,3 +29,16 @@ PyAV
The `PyAV <https://github.com/PyAV-Org/PyAV>`_ backend (`av package <https://pypi.org/project/av/>`_) is a more robust backend that handles multiple audio tracks and frame decode errors gracefully.

This backend can be used by specifying ``-b pyav`` via command line, or setting ``backend = pyav`` under the ``[global]`` section of your :ref:`config file <scenedetect_cli-config_file>`.


=======================================================================
MoviePy
=======================================================================

MoviePy launches ffmpeg as a subprocess, and can be used with various types of inputs. If the input supports seeking it should work fine with most operations, for example, image sequences or AviSynth scripts.

.. warning::

The MoviePy backend is still under development and is not included with current Windows distribution. To enable MoviePy support, you must install PySceneDetect using `python` and `pip`.

This backend can be used by specifying ``-b moviepy`` via command line, or setting ``backend = moviepy`` under the ``[global]`` section of your :ref:`config file <scenedetect_cli-config_file>`.
25 changes: 13 additions & 12 deletions scenedetect/backends/moviepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#
""":class:`VideoStreamMoviePy` provides an adapter for MoviePy's `FFMPEG_VideoReader`.
Uses string identifier ``'moviepy'``.
.. warning::
The MoviePy backend is still under development. Some features are not yet supported.
MoviePy launches ffmpeg as a subprocess, and can be used with various types of inputs. Generally,
the input should support seeking, but does not necessarily have to be a video. For example,
image sequences or AviSynth scripts are supported as inputs.
"""

from logging import getLogger
Expand Down Expand Up @@ -72,13 +70,7 @@ def __init__(self, path: AnyStr, framerate: Optional[float] = None, print_infos:
self._frame_number = 0
# We need to manually keep track of EOF as duration may not be accurate.
self._eof = False
# MoviePy doesn't support extracting the aspect ratio yet, so for now we just fall
# back to using OpenCV to determine it.
try:
self._aspect_ratio = VideoStreamCv2(self._path).aspect_ratio
except VideoOpenFailure as ex:
logger.warning("Unable to determine aspect ratio: %s", str(ex))
self._aspect_ratio = 1.0
self._aspect_ratio: float = None

#
# VideoStream Methods/Properties
Expand Down Expand Up @@ -121,6 +113,15 @@ def duration(self) -> Optional[FrameTimecode]:
@property
def aspect_ratio(self) -> float:
"""Display/pixel aspect ratio as a float (1.0 represents square pixels)."""
# TODO: Use cached_property once Python 3.7 support is deprecated.
if self._aspect_ratio is None:
# MoviePy doesn't support extracting the aspect ratio yet, so for now we just fall
# back to using OpenCV to determine it.
try:
self._aspect_ratio = VideoStreamCv2(self._path).aspect_ratio
except VideoOpenFailure as ex:
logger.warning("Unable to determine aspect ratio: %s", str(ex))
self._aspect_ratio = 1.0
return self._aspect_ratio

@property
Expand Down
5 changes: 1 addition & 4 deletions scenedetect/backends/pyav.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
# PySceneDetect is licensed under the BSD 3-Clause License; see the
# included LICENSE file, or visit one of the above pages for details.
#
""":class:`VideoStreamAv` provides an adapter for the PyAV av.InputContainer object.
Uses string identifier ``'pyav'``.
"""
""":class:`VideoStreamAv` provides an adapter for the PyAV av.InputContainer object."""

from logging import getLogger
from typing import AnyStr, BinaryIO, Optional, Tuple, Union
Expand Down

0 comments on commit a58a966

Please sign in to comment.