From 52949f2fd1ce0c40211ef38453de0f075f1405f1 Mon Sep 17 00:00:00 2001 From: Akshay <59740725+Killua7362@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:12:18 +0300 Subject: [PATCH 1/5] Support for all the codes --- supervision/utils/video.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/supervision/utils/video.py b/supervision/utils/video.py index d9f2ed1e..3b4b6481 100644 --- a/supervision/utils/video.py +++ b/supervision/utils/video.py @@ -80,13 +80,18 @@ class VideoSink: ``` """ - def __init__(self, target_path: str, video_info: VideoInfo): + def __init__(self, target_path: str, video_info: VideoInfo, /, codec: str = 'mp4v'): self.target_path = target_path self.video_info = video_info - self.__fourcc = cv2.VideoWriter_fourcc(*"mp4v") + self.__codec = codec self.__writer = None def __enter__(self): + try: + self.__fourcc = cv2.VideoWriter_fourcc(*self.__codec) + except: + print(f"{self.__codec} does not exist. Defaulting to mp4v...") + self.__fourcc = cv2.VideoWriter_fourcc(*'mp4v') self.__writer = cv2.VideoWriter( self.target_path, self.__fourcc, From 5c25e58e39d3fe7711debd9222a8b556de5a11fb Mon Sep 17 00:00:00 2001 From: Akshay <59740725+Killua7362@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:22:07 +0300 Subject: [PATCH 2/5] Added docstrings for codec --- supervision/utils/video.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/supervision/utils/video.py b/supervision/utils/video.py index 3b4b6481..5beae6ee 100644 --- a/supervision/utils/video.py +++ b/supervision/utils/video.py @@ -65,6 +65,7 @@ class VideoSink: target_path (str): The path to the output file where the video will be saved. video_info (VideoInfo): Information about the video resolution, fps, and total frame count. + codec (str): FOURCC code for video format Example: ```python @@ -73,14 +74,15 @@ class VideoSink: >>> video_info = sv.VideoInfo.from_video_path(video_path='source_video.mp4') >>> with sv.VideoSink(target_path='target_video.mp4', - ... video_info=video_info) as sink: + ... video_info=video_info, + codec='H264') as sink: ... for frame in get_video_frames_generator(source_path='source_video.mp4', ... stride=2): ... sink.write_frame(frame=frame) ``` """ - def __init__(self, target_path: str, video_info: VideoInfo, /, codec: str = 'mp4v'): + def __init__(self, target_path: str, video_info: VideoInfo, codec: str = 'mp4v'): self.target_path = target_path self.video_info = video_info self.__codec = codec From 53dfeac19b1d92a3fe1b25eb8f5494aa10e8c76b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:25:00 +0000 Subject: [PATCH 3/5] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/utils/video.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/supervision/utils/video.py b/supervision/utils/video.py index 5beae6ee..337768b1 100644 --- a/supervision/utils/video.py +++ b/supervision/utils/video.py @@ -82,10 +82,10 @@ class VideoSink: ``` """ - def __init__(self, target_path: str, video_info: VideoInfo, codec: str = 'mp4v'): + def __init__(self, target_path: str, video_info: VideoInfo, codec: str = "mp4v"): self.target_path = target_path self.video_info = video_info - self.__codec = codec + self.__codec = codec self.__writer = None def __enter__(self): @@ -93,7 +93,7 @@ class VideoSink: self.__fourcc = cv2.VideoWriter_fourcc(*self.__codec) except: print(f"{self.__codec} does not exist. Defaulting to mp4v...") - self.__fourcc = cv2.VideoWriter_fourcc(*'mp4v') + self.__fourcc = cv2.VideoWriter_fourcc(*"mp4v") self.__writer = cv2.VideoWriter( self.target_path, self.__fourcc, From 9736eba9e6144ac0005aa61ffad902241d714a9f Mon Sep 17 00:00:00 2001 From: Akshay <59740725+Killua7362@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:38:46 +0300 Subject: [PATCH 4/5] FIX: Added type error exception in videosink --- supervision/utils/video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/utils/video.py b/supervision/utils/video.py index 5beae6ee..5cb079ae 100644 --- a/supervision/utils/video.py +++ b/supervision/utils/video.py @@ -91,8 +91,8 @@ class VideoSink: def __enter__(self): try: self.__fourcc = cv2.VideoWriter_fourcc(*self.__codec) - except: - print(f"{self.__codec} does not exist. Defaulting to mp4v...") + except TypeError as e: + print(str(e)+". Defaulting to mp4v...") self.__fourcc = cv2.VideoWriter_fourcc(*'mp4v') self.__writer = cv2.VideoWriter( self.target_path, From 9c081b0e11ec17684ed478c2f5d7fc3a6b0e4c0f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:40:22 +0000 Subject: [PATCH 5/5] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/utils/video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/utils/video.py b/supervision/utils/video.py index 27527b9a..9d39d621 100644 --- a/supervision/utils/video.py +++ b/supervision/utils/video.py @@ -92,8 +92,8 @@ class VideoSink: try: self.__fourcc = cv2.VideoWriter_fourcc(*self.__codec) except TypeError as e: - print(str(e)+". Defaulting to mp4v...") - self.__fourcc = cv2.VideoWriter_fourcc(*'mp4v') + print(str(e) + ". Defaulting to mp4v...") + self.__fourcc = cv2.VideoWriter_fourcc(*"mp4v") self.__writer = cv2.VideoWriter( self.target_path, self.__fourcc,