Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
7fba113
ADD: Added audio stream for process_video
Ashp116 Jul 30, 2025
8947f77
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Jul 30, 2025
73b5836
REMOVE: Removed ffprobe
Ashp116 Jul 30, 2025
e02d298
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Jul 30, 2025
5e07794
UPDATE: Added a new Video class with OpenCV writer and backend
Ashp116 Aug 2, 2025
46ec693
Merge pull request #1 from Ashp116/update/video-core
Ashp116 Aug 2, 2025
b2096d0
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 2, 2025
9fb7098
Precommit
Ashp116 Aug 2, 2025
850a2c6
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 2, 2025
46900f8
Precommit
Ashp116 Aug 2, 2025
34cb9a1
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 2, 2025
c700394
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 2, 2025
fce8ade
UPDATE: Fixed incomplete write closing
Ashp116 Aug 2, 2025
f86f4f2
ADD: Docstrings
Ashp116 Aug 2, 2025
2265977
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 2, 2025
bf67bfa
UPDATE: Allow for ffmpeg error passthrough
Ashp116 Aug 2, 2025
ec4bd01
UPDATE: Writer and Backend abstract class
Ashp116 Aug 2, 2025
b9e7968
Precommit
Ashp116 Aug 2, 2025
a96c3f0
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 2, 2025
a6c91bc
Precommit
Ashp116 Aug 2, 2025
d075e03
UPDATE: Added manual control
Ashp116 Aug 6, 2025
7f078ff
ADD: Added docstrings
Ashp116 Aug 6, 2025
af49e9a
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 6, 2025
320d817
UPDATE: Deprecate warning old Video API
Ashp116 Aug 6, 2025
cb8d2f8
FIX: Prototype resolution for #1687
Ashp116 Aug 7, 2025
a3a3a9e
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 7, 2025
ecbf5af
FIX: Rounding type
Ashp116 Aug 7, 2025
1da4466
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 7, 2025
3b4c68f
UPDATE: Updated the file structure for the video API
Ashp116 Aug 8, 2025
385639b
UPDATE: Added frame generator within backend
Ashp116 Aug 8, 2025
61dd016
UPDATE: Added .save codec support
Ashp116 Aug 8, 2025
d2bb428
UPDATE: Added default mp4v codec
Ashp116 Aug 8, 2025
f3a3133
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 8, 2025
421cd5d
UPDATE: Trying to pass checks
Ashp116 Aug 9, 2025
dce0717
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 9, 2025
b9da794
UPDATE: Typings for optional params
Ashp116 Aug 9, 2025
e8b39a1
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
90885b0
Import check fix
Ashp116 Aug 9, 2025
9d0b5ed
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
f983113
Import check fix
Ashp116 Aug 9, 2025
c1544f0
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
3a33982
Import check fix
Ashp116 Aug 9, 2025
343600d
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
bf0f884
Import check fix
Ashp116 Aug 9, 2025
c7e5f44
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 9, 2025
881c9f4
Import check fix
Ashp116 Aug 9, 2025
5fed10b
Import check fix
Ashp116 Aug 9, 2025
a84dde8
Import check fix
Ashp116 Aug 9, 2025
012b950
RM: Remove video folder
Ashp116 Aug 9, 2025
af3db7f
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
e2edb96
ADD: Added video folder
Ashp116 Aug 9, 2025
f31d377
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 9, 2025
ed5e15b
UPDATE: Revert typings
Ashp116 Aug 9, 2025
fd66925
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
13010e0
UPDATE: sv imports
Ashp116 Aug 9, 2025
55727a7
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 9, 2025
25e3b5f
UPDATE: default imports using __init__
Ashp116 Aug 9, 2025
0ad6cd1
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
3e7b247
FIX: Fixed VideoInfo definition
Ashp116 Aug 9, 2025
cc7477a
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 9, 2025
e855b14
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
29fb666
FIX: Fixed futuer annotations
Ashp116 Aug 9, 2025
d9ab61c
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
941d487
UPDATE: Restructure video saves
Ashp116 Aug 9, 2025
1db5596
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 9, 2025
2175d25
UPDATE: Restructure manual writer
Ashp116 Aug 9, 2025
27f1266
FORMAT: Formatting changes
Ashp116 Aug 9, 2025
cf31e29
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 9, 2025
abba880
UPDATE: Restructured frame generator
Ashp116 Aug 9, 2025
3374544
FIX: Removed frames from BaseBackend
Ashp116 Aug 9, 2025
2e78c48
ADD: Added pyAV backend support
Ashp116 Aug 9, 2025
a3aca42
ADD: Added pyAV docstrings
Ashp116 Aug 9, 2025
819c70b
ADD: Added pyAV audio support
Ashp116 Aug 9, 2025
dfd9407
UPDATE: Backend support needed for all writers
Ashp116 Aug 9, 2025
d29e50e
FIX: Formatting
Ashp116 Aug 9, 2025
3ff8644
ADD: Added backend utils and type safe support
Ashp116 Aug 9, 2025
d006c47
UPDATE: Type safe syntax
Ashp116 Aug 10, 2025
8894819
FORMAT: Changed backend param
Ashp116 Aug 10, 2025
55b5ea0
UPDATE: Added ctx for pyAV
Ashp116 Aug 10, 2025
4b1c9bc
UPDATE: Updated docstrings
Ashp116 Aug 10, 2025
706e85a
UPDATE: Negate audio stream
Ashp116 Aug 10, 2025
8eb0774
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 10, 2025
9ea0f2b
FIX: Fixed av import error and formatting
Ashp116 Aug 10, 2025
40c2a7c
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 10, 2025
10482f4
FIX: Fixed av error message and formatting
Ashp116 Aug 10, 2025
337f65e
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 10, 2025
1e40420
FIX: Fixed issue with audio sync with fps
Ashp116 Aug 10, 2025
62b1fc6
UPDATE: Finer audio mux
Ashp116 Aug 10, 2025
e3e21ab
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 10, 2025
055c4fc
UPDATE: Param config to render audio
Ashp116 Aug 10, 2025
e35ddc7
Merge branch 'bug/process-video-audio' of https://github.com/Ashp116/…
Ashp116 Aug 10, 2025
7450573
UPDATE: Changed config to render audio to be isolated
Ashp116 Aug 10, 2025
9223804
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 10, 2025
fcee1a1
UPDATE: Updated deprecated warnings
Ashp116 Aug 10, 2025
42a0f24
ADD: Added unit tests from PR #1941
Ashp116 Aug 10, 2025
c004d24
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 10, 2025
c5e1d2e
FIX: Updated the pyproject.toml's extra requirements for ffmpeg
Ashp116 Aug 11, 2025
b258d1b
FIX: Fixes of formatting from code review
Ashp116 Aug 11, 2025
79e003d
UPDATE: Removed video info from path as it is dependant on the backend
Ashp116 Aug 11, 2025
c6e6e6c
UPDATE: Updated backend to Enum
Ashp116 Aug 11, 2025
4f5ac58
FIX: Reverted video utils
Ashp116 Aug 11, 2025
29a1045
FIX: Fixed backend bug issues
Ashp116 Aug 11, 2025
7e401ca
UPDATE: Updated render_audio param default value config
Ashp116 Aug 11, 2025
232ace5
BUG: Fixed pyav not resolving webcam source path
Ashp116 Aug 12, 2025
84f90ea
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 12, 2025
f6cea28
UPDATE: Updated file names
Ashp116 Aug 12, 2025
048ebc0
Precommit error fix
Ashp116 Aug 12, 2025
de62eb8
FIX: render_audio opencv param fix
Ashp116 Aug 12, 2025
afea7c0
UPDATE: Updated docstrings
Ashp116 Aug 12, 2025
6208f3d
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 12, 2025
9cb2170
UPDATE: Updated docstrings
Ashp116 Aug 12, 2025
70b73d8
UPDATE: Added .show()
Ashp116 Aug 12, 2025
01f8b2c
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 12, 2025
11fc8a5
UPDATE: Add support for IPython display
Ashp116 Aug 13, 2025
1dac635
UPDATE: Added support for headless machines and notebook for sv.Video…
Ashp116 Aug 13, 2025
dedb68a
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 13, 2025
035196a
UPDATE: Updated error msg for IPython
Ashp116 Aug 13, 2025
a1218e8
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 13, 2025
76d8145
Precommit
Ashp116 Aug 13, 2025
32a5e2c
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 13, 2025
7680cae
UPDATE: Fixed av module install
Ashp116 Aug 14, 2025
68fb727
UPDATE: Revert av error
Ashp116 Aug 14, 2025
3f403fe
UPDATE: updated av module getter
Ashp116 Aug 14, 2025
c9badc1
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 14, 2025
7a507e5
UPDATE: Updated .show() with more configuration params
Ashp116 Aug 14, 2025
824fa98
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 14, 2025
8aa364c
UPDATE: Updated IPython import
Ashp116 Aug 15, 2025
2bec991
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 15, 2025
43830f7
BUG: Frame iteration fix
Ashp116 Aug 15, 2025
f827455
UPDATE: Updated audio stream to use atempo reflecting changes in fps
Ashp116 Aug 31, 2025
2d90915
UPDATE: Updated docstrings
Ashp116 Aug 31, 2025
e9ccca2
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 31, 2025
9f115c4
UPDATE: Changed backend type class and added ref to root
Ashp116 Aug 31, 2025
c67aad3
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 31, 2025
ba9efc2
BUG: Appending fixes for VideoBackend error
Ashp116 Aug 31, 2025
1dcbb4b
FIX: Merge conflicts
Ashp116 Aug 31, 2025
9c7a9ec
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 31, 2025
fb2171c
UPDATE: Decompose playback speed into valid atempo chain
Ashp116 Aug 31, 2025
c78e4f7
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] Aug 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
"pillow>=9.4",
"requests>=2.26.0",
"tqdm>=4.62.3",
"opencv-python>=4.5.5.64"
"opencv-python>=4.5.5.64",
]

[project.urls]
Expand All @@ -58,6 +58,8 @@ Documentation = "https://supervision.roboflow.com/latest/"
metrics = [
"pandas>=2.0.0",
]
ffmpeg = ["av (>=15.0.0)"]
rich_display = ["ipython (>=8.15,<9.0)"]

[dependency-groups]
dev = [
Expand Down
5 changes: 4 additions & 1 deletion supervision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@
from supervision.utils.notebook import plot_image, plot_images_grid
from supervision.utils.video import (
FPSMonitor,
VideoInfo,
VideoSink,
get_video_frames_generator,
process_video,
)
from supervision.video import Video, VideoInfo
from supervision.video.backend import VideoBackendType

__all__ = [
"LMM",
Expand Down Expand Up @@ -192,6 +193,8 @@
"TriangleAnnotator",
"VertexAnnotator",
"VertexLabelAnnotator",
"Video",
"VideoBackendType",
"VideoInfo",
"VideoSink",
"approximate_polygon",
Expand Down
18 changes: 18 additions & 0 deletions supervision/utils/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import numpy as np
from tqdm.auto import tqdm

from supervision.utils.internal import deprecated


@deprecated(
"`process_video` is deprecated and will be removed in "
"`supervision-0.32.0`. Use `sv.VideoInfo` instead."
)
@dataclass
class VideoInfo:
"""
Expand Down Expand Up @@ -60,6 +66,10 @@ def resolution_wh(self) -> tuple[int, int]:
return self.width, self.height


@deprecated(
"`process_video` is deprecated and will be removed in "
"`supervision-0.32.0`. Use `sv.Video().save` instead."
)
class VideoSink:
"""
Context manager that saves video frames to a file using OpenCV.
Expand Down Expand Up @@ -141,6 +151,10 @@ def _validate_and_setup_video(
return video, start, end


@deprecated(
"`process_video` is deprecated and will be removed in "
"`supervision-0.32.0`. Use `sv.Video().frame()` or `sv.Video()` instead."
)
def get_video_frames_generator(
source_path: str,
stride: int = 1,
Expand Down Expand Up @@ -192,6 +206,10 @@ def get_video_frames_generator(
video.release()


@deprecated(
"`process_video` is deprecated and will be removed in "
"`supervision-0.32.0`. Use `sv.Video().save` instead."
)
def process_video(
source_path: str,
target_path: str,
Expand Down
4 changes: 4 additions & 0 deletions supervision/video/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from supervision.video.core import Video
from supervision.video.utils import SourceType, VideoInfo

__all__ = ["SourceType", "Video", "VideoInfo"]
62 changes: 62 additions & 0 deletions supervision/video/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

from enum import Enum
from typing import Literal, Union

from supervision.video.backend.opencv import OpenCVBackend, OpenCVWriter
from supervision.video.backend.pyav import pyAVBackend, pyAVWriter

VideoBackendTypes = Union[OpenCVBackend, pyAVBackend]
VideoWriterTypes = Union[OpenCVWriter, pyAVWriter]


class VideoBackendType(Enum):
"""
Enumeration of Backends.

Attributes:
PYAV (str): PyAV backend (powered by FFmpeg, supports audio rendering)
OPENCV (str): OpenCV backend

"""

PYAV = "pyav"
OPENCV = "opencv"

@classmethod
def list(cls):
return list(map(lambda c: c.value, cls))

@classmethod
def from_value(cls, value: VideoBackendType | str) -> VideoBackendType:
if isinstance(value, cls):
return value
if isinstance(value, str):
value = value.lower()
try:
return cls(value)
except ValueError:
raise ValueError(f"Invalid value: {value}. Must be one of {cls.list()}")
raise ValueError(
f"Invalid value type: {type(value)}. Must be an instance of "
f"{cls.__name__} or str."
)


VideoBackendDict = {
VideoBackendType.PYAV: pyAVBackend,
VideoBackendType.OPENCV: OpenCVBackend,
}

VideoWriterDict = {
VideoBackendType.PYAV: pyAVWriter,
VideoBackendType.OPENCV: OpenCVWriter,
}

__all__ = [
"VideoBackendDict",
"VideoBackendType",
"VideoBackendTypes",
"VideoWriterDict",
"VideoWriterTypes",
]
77 changes: 77 additions & 0 deletions supervision/video/backend/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from __future__ import annotations

from abc import ABC, abstractmethod

import numpy as np

from supervision.video.utils import VideoInfo


class BaseBackend(ABC):
def __init__(self):
self.cap = None
self.video_info: VideoInfo | None = None
self.writer: BaseWriter | None = None
self.path = None

@abstractmethod
def open(self, path: str | int) -> None:
pass

@abstractmethod
def isOpened(self) -> bool:
pass

@abstractmethod
def _set_video_info(self) -> VideoInfo:
pass

@abstractmethod
def info(self) -> VideoInfo:
pass

@abstractmethod
def read(self) -> tuple[bool, np.ndarray]:
pass

@abstractmethod
def grab(self) -> bool:
pass

@abstractmethod
def seek(self, frame_idx: int) -> None:
pass

@abstractmethod
def release(self) -> None:
pass


class BaseWriter(ABC):
@abstractmethod
def __init__(
self,
filename: str,
fps: int,
frame_size: tuple[int, int],
codec: str | None = None,
backend: BaseBackend | None = None,
render_audio: bool | None = None,
):
pass

@abstractmethod
def __enter__(self):
pass

@abstractmethod
def __exit__(self, exc_type, exc_value, traceback):
pass

@abstractmethod
def write(self, frame: np.ndarray) -> None:
pass

@abstractmethod
def close(self) -> None:
pass
Loading
Loading