From e20bb18925cdfc22b0166173eb7428ac8c94a3d4 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Fri, 9 Aug 2024 09:40:43 -0700 Subject: [PATCH 01/21] modify `VideoWriter` to use imageio with ffmpeg backend --- sleap/io/videowriter.py | 94 ++++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index 510fad739..25c01b1f9 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -68,8 +68,52 @@ def close(self): self._writer.release() -class VideoWriterSkvideo(VideoWriter): - """Writes video using scikit-video as wrapper for ffmpeg. +# class VideoWriterSkvideo(VideoWriter): +# """Writes video using scikit-video as wrapper for ffmpeg. + +# Attributes: +# filename: Path to mp4 file to save to. +# height: Height of movie frames. +# width: Width of movie frames. +# fps: Playback framerate to save at. +# crf: Compression rate factor to control lossiness of video. Values go from +# 2 to 32, with numbers in the 18 to 30 range being most common. Lower values +# mean less compressed/higher quality. +# preset: Name of the libx264 preset to use (default: "superfast"). +# """ + +# def __init__( +# self, filename, height, width, fps, crf: int = 21, preset: str = "superfast" +# ): +# import skvideo.io + +# fps = str(fps) +# self._writer = skvideo.io.FFmpegWriter( +# filename, +# inputdict={ +# "-r": fps, +# }, +# outputdict={ +# "-c:v": "libx264", +# "-preset": preset, +# "-vf": "scale=trunc(iw/2)*2:trunc(ih/2)*2", # Need even dims for libx264 +# "-framerate": fps, +# "-crf": str(crf), +# "-pix_fmt": "yuv420p", +# }, +# ) + +# def add_frame(self, img, bgr: bool = False): +# if bgr: +# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) +# self._writer.writeFrame(img) + +# def close(self): +# self._writer.close() + + +class VideoWriterImageio(VideoWriter): + """Writes video using imageio as a wrapper for ffmpeg. Attributes: filename: Path to mp4 file to save to. @@ -85,28 +129,40 @@ class VideoWriterSkvideo(VideoWriter): def __init__( self, filename, height, width, fps, crf: int = 21, preset: str = "superfast" ): - import skvideo.io - - fps = str(fps) - self._writer = skvideo.io.FFmpegWriter( + self.filename = filename + self.height = height + self.width = width + self.fps = fps + self.crf = crf + self.preset = preset + + import imageio_ffmpeg as ffmpeg + + # Imageio's ffmpeg writer parameters + # https://imageio.readthedocs.io/en/stable/examples.html#writing-videos-with-ffmpeg-and-vaapi + # iio.help(name='FFMPEG') to test + self.writer = iio.get_writer( filename, - inputdict={ - "-r": fps, - }, - outputdict={ - "-c:v": "libx264", - "-preset": preset, - "-vf": "scale=trunc(iw/2)*2:trunc(ih/2)*2", # Need even dims for libx264 - "-framerate": fps, - "-crf": str(crf), - "-pix_fmt": "yuv420p", - }, + fps=fps, + codec="libx264", + format="FFMPEG", + pixelformat="yuv420p", + output_params=[ + "-preset", + preset, + "-crf", + str(crf), + "-vf", + "scale=trunc(iw/2)*2:trunc(ih/2)*2", # Ensure even dimensions + "-r", + str(fps), + ], ) def add_frame(self, img, bgr: bool = False): if bgr: img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) - self._writer.writeFrame(img) + self.writer.append_data(img) def close(self): - self._writer.close() + self.writer.close() From bae9fd054abe27fb8d321a3ca6e69c040beb5ec2 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Fri, 9 Aug 2024 09:41:05 -0700 Subject: [PATCH 02/21] check to see if ffmpeg is present --- sleap/io/videowriter.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index 25c01b1f9..873623ad0 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -32,22 +32,26 @@ def close(self): @staticmethod def safe_builder(filename, height, width, fps): """Builds VideoWriter based on available dependencies.""" - if VideoWriter.can_use_skvideo(): - return VideoWriterSkvideo(filename, height, width, fps) + if VideoWriter.can_use_ffmpeg(): + return VideoWriterImageio(filename, height, width, fps) else: return VideoWriterOpenCV(filename, height, width, fps) @staticmethod - def can_use_skvideo(): - # See if we can import skvideo + def can_use_ffmpeg(): + """Check if ffmpeg is available for writing videos.""" try: - import skvideo + import imageio_ffmpeg as ffmpeg except ImportError: return False - # See if skvideo can find FFMPEG - if skvideo.getFFmpegVersion() != "0.0.0": - return True + try: + # Try to get the version of the ffmpeg plugin + ffmpeg_version = ffmpeg.get_ffmpeg_version() + if ffmpeg_version: + return True + except Exception: + return False return False From fa5299b8ad353400ca0717dcd1ede30751d3d6be Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Fri, 9 Aug 2024 09:41:41 -0700 Subject: [PATCH 03/21] use the new check for ffmpeg --- sleap/gui/dialogs/export_clip.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sleap/gui/dialogs/export_clip.py b/sleap/gui/dialogs/export_clip.py index 312f9a807..f84766d18 100644 --- a/sleap/gui/dialogs/export_clip.py +++ b/sleap/gui/dialogs/export_clip.py @@ -11,16 +11,16 @@ def __init__(self): super().__init__(form_name="labeled_clip_form") - can_use_skvideo = VideoWriter.can_use_skvideo() + can_use_ffmpeg = VideoWriter.can_use_ffmpeg() - if can_use_skvideo: + if can_use_ffmpeg: message = ( "MP4 file will be encoded using " - "system ffmpeg via scikit-video (preferred option)." + "system ffmpeg via imageio (preferred option)." ) else: message = ( - "Unable to use ffpmeg via scikit-video. " + "Unable to use ffpmeg via imageio. " "AVI file will be encoding using OpenCV." ) From b80ee45ac6abd895535c2fab76e52d8ef90312a2 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Fri, 9 Aug 2024 09:41:49 -0700 Subject: [PATCH 04/21] import imageio.v2 --- sleap/io/videowriter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index 873623ad0..a27ad7b82 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -12,6 +12,7 @@ from abc import ABC, abstractmethod import cv2 import numpy as np +import imageio.v2 as iio class VideoWriter(ABC): From 933c694eeb28f415ce772940b7efdedcc64a0251 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Tue, 13 Aug 2024 11:32:45 -0700 Subject: [PATCH 05/21] add imageio-ffmpeg to environments to test --- environment.yml | 1 + environment_mac.yml | 1 + environment_no_cuda.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/environment.yml b/environment.yml index 9c5758c13..2aba3c7d2 100644 --- a/environment.yml +++ b/environment.yml @@ -12,6 +12,7 @@ dependencies: # Packages SLEAP uses directly - conda-forge::attrs >=21.2.0 #,<=21.4.0 - conda-forge::cattrs ==1.1.1 + - conda-forge::imageio-ffmpeg # Required for imageio to read/write videos with ffmpeg - conda-forge::jsmin - conda-forge::jsonpickle ==1.2 - conda-forge::networkx diff --git a/environment_mac.yml b/environment_mac.yml index 42d6e028c..9ab10a1b8 100644 --- a/environment_mac.yml +++ b/environment_mac.yml @@ -12,6 +12,7 @@ dependencies: - conda-forge::importlib-metadata <7.1.0 - conda-forge::cattrs ==1.1.1 - conda-forge::h5py + - conda-forge::imageio-ffmpeg # Required for imageio to read/write videos with ffmpeg - conda-forge::jsmin - conda-forge::jsonpickle ==1.2 - conda-forge::keras <2.10.0,>=2.9.0rc0 # Required by tensorflow-macos diff --git a/environment_no_cuda.yml b/environment_no_cuda.yml index fc13f839a..2adee7a89 100644 --- a/environment_no_cuda.yml +++ b/environment_no_cuda.yml @@ -13,6 +13,7 @@ dependencies: # Packages SLEAP uses directly - conda-forge::attrs >=21.2.0 #,<=21.4.0 - conda-forge::cattrs ==1.1.1 + - conda-forge::imageio-ffmpeg # Required for imageio to read/write videos with ffmpeg - conda-forge::jsmin - conda-forge::jsonpickle ==1.2 - conda-forge::networkx From bd521753e464b4cf0cf77d4dda7aa420cb482a9b Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Tue, 13 Aug 2024 11:33:12 -0700 Subject: [PATCH 06/21] using avi format for now --- sleap/gui/commands.py | 8 +++----- sleap/gui/dialogs/export_clip.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sleap/gui/commands.py b/sleap/gui/commands.py index e3ef8522d..43522f49f 100644 --- a/sleap/gui/commands.py +++ b/sleap/gui/commands.py @@ -1329,12 +1329,10 @@ def ask(context: CommandContext, params: dict) -> bool: # makes mp4's that most programs can't open (VLC can). default_out_filename = context.state["filename"] + ".avi" - # But if we can write mpegs using sci-kit video, use .mp4 - # since it has trouble writing .avi files. - if VideoWriter.can_use_skvideo(): - default_out_filename = context.state["filename"] + ".mp4" + if VideoWriter.can_use_ffmpeg(): + default_out_filename = context.state["filename"] + ".avi" - # Ask where use wants to save video file + # Ask where user wants to save video file filename, _ = FileDialog.save( context.app, caption="Save Video As...", diff --git a/sleap/gui/dialogs/export_clip.py b/sleap/gui/dialogs/export_clip.py index f84766d18..b55279425 100644 --- a/sleap/gui/dialogs/export_clip.py +++ b/sleap/gui/dialogs/export_clip.py @@ -15,7 +15,7 @@ def __init__(self): if can_use_ffmpeg: message = ( - "MP4 file will be encoded using " + "AVI file will be encoded using " "system ffmpeg via imageio (preferred option)." ) else: From 9776426f547a6f67a984a655359afad5092f8f2f Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Tue, 13 Aug 2024 11:33:38 -0700 Subject: [PATCH 07/21] remove SKvideo videowriter --- sleap/io/videowriter.py | 46 +---------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index a27ad7b82..b397725c4 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -73,55 +73,11 @@ def close(self): self._writer.release() -# class VideoWriterSkvideo(VideoWriter): -# """Writes video using scikit-video as wrapper for ffmpeg. - -# Attributes: -# filename: Path to mp4 file to save to. -# height: Height of movie frames. -# width: Width of movie frames. -# fps: Playback framerate to save at. -# crf: Compression rate factor to control lossiness of video. Values go from -# 2 to 32, with numbers in the 18 to 30 range being most common. Lower values -# mean less compressed/higher quality. -# preset: Name of the libx264 preset to use (default: "superfast"). -# """ - -# def __init__( -# self, filename, height, width, fps, crf: int = 21, preset: str = "superfast" -# ): -# import skvideo.io - -# fps = str(fps) -# self._writer = skvideo.io.FFmpegWriter( -# filename, -# inputdict={ -# "-r": fps, -# }, -# outputdict={ -# "-c:v": "libx264", -# "-preset": preset, -# "-vf": "scale=trunc(iw/2)*2:trunc(ih/2)*2", # Need even dims for libx264 -# "-framerate": fps, -# "-crf": str(crf), -# "-pix_fmt": "yuv420p", -# }, -# ) - -# def add_frame(self, img, bgr: bool = False): -# if bgr: -# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) -# self._writer.writeFrame(img) - -# def close(self): -# self._writer.close() - - class VideoWriterImageio(VideoWriter): """Writes video using imageio as a wrapper for ffmpeg. Attributes: - filename: Path to mp4 file to save to. + filename: Path to video file to save to. height: Height of movie frames. width: Width of movie frames. fps: Playback framerate to save at. From a080f55fde827503a7fb335a111db9dd47ed96d4 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Tue, 13 Aug 2024 11:34:07 -0700 Subject: [PATCH 08/21] test `VideoWriterImageio` minimally --- tests/io/test_videowriter.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index dea193117..4aa5785a2 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -1,5 +1,6 @@ import os -from sleap.io.videowriter import VideoWriter, VideoWriterOpenCV +from pathlib import Path +from sleap.io.videowriter import VideoWriter, VideoWriterOpenCV, VideoWriterImageio def test_video_writer(tmpdir, small_robot_mp4_vid): @@ -38,3 +39,29 @@ def test_cv_video_writer(tmpdir, small_robot_mp4_vid): writer.close() assert os.path.exists(out_path) + + +def test_imageio_video_writer(tmpdir, small_robot_mp4_vid): + out_path = Path(tmpdir) / "clip.avi" + + # Make sure imageio video writer works + writer = VideoWriterImageio( + out_path, + height=small_robot_mp4_vid.height, + width=small_robot_mp4_vid.width, + fps=small_robot_mp4_vid.fps, + ) + + writer.add_frame(small_robot_mp4_vid[0][0]) + writer.add_frame(small_robot_mp4_vid[1][0]) + + writer.close() + + assert os.path.exists(out_path) + # Check attributes + assert writer.height == small_robot_mp4_vid.height + assert writer.width == small_robot_mp4_vid.width + assert writer.fps == small_robot_mp4_vid.fps + assert writer.filename == out_path + assert writer.crf == 21 + assert writer.preset == "superfast" From 3a03ceefb4f57a731887cebb14952a417bbc5af4 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Tue, 13 Aug 2024 16:13:19 -0700 Subject: [PATCH 09/21] add more documentation for ffmpeg --- sleap/io/videowriter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index b397725c4..6ffeeb47e 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -101,6 +101,8 @@ def __init__( # Imageio's ffmpeg writer parameters # https://imageio.readthedocs.io/en/stable/examples.html#writing-videos-with-ffmpeg-and-vaapi + # Use `ffmpeg -h encoder=libx264`` to see all options for libx264 output_params + # output_params must be a list of strings # iio.help(name='FFMPEG') to test self.writer = iio.get_writer( filename, @@ -115,8 +117,6 @@ def __init__( str(crf), "-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", # Ensure even dimensions - "-r", - str(fps), ], ) From 4c8014daef6a67d575d9bf63fab3d8dca0d790e0 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 10:52:12 -0700 Subject: [PATCH 10/21] default mp4 for ffmpeg should be mp4 --- sleap/gui/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleap/gui/commands.py b/sleap/gui/commands.py index 43522f49f..692f19c78 100644 --- a/sleap/gui/commands.py +++ b/sleap/gui/commands.py @@ -1330,7 +1330,7 @@ def ask(context: CommandContext, params: dict) -> bool: default_out_filename = context.state["filename"] + ".avi" if VideoWriter.can_use_ffmpeg(): - default_out_filename = context.state["filename"] + ".avi" + default_out_filename = context.state["filename"] + ".mp4" # Ask where user wants to save video file filename, _ = FileDialog.save( From 107abe2e972161748e76ea8eb859f75d607ceb64 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 10:52:41 -0700 Subject: [PATCH 11/21] print using `IMAGEIO` when using ffmpeg --- sleap/io/videowriter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index 6ffeeb47e..94bc397c4 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -34,6 +34,7 @@ def close(self): def safe_builder(filename, height, width, fps): """Builds VideoWriter based on available dependencies.""" if VideoWriter.can_use_ffmpeg(): + print("USING IMAGEIO") return VideoWriterImageio(filename, height, width, fps) else: return VideoWriterOpenCV(filename, height, width, fps) From 2d1b265651f69716ea7f5f0d28087f6b1d940872 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 10:58:00 -0700 Subject: [PATCH 12/21] mp4 for ffmpeg --- sleap/gui/dialogs/export_clip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleap/gui/dialogs/export_clip.py b/sleap/gui/dialogs/export_clip.py index b55279425..f84766d18 100644 --- a/sleap/gui/dialogs/export_clip.py +++ b/sleap/gui/dialogs/export_clip.py @@ -15,7 +15,7 @@ def __init__(self): if can_use_ffmpeg: message = ( - "AVI file will be encoded using " + "MP4 file will be encoded using " "system ffmpeg via imageio (preferred option)." ) else: From 8478b871c61ac392b7e2d8b3d0b72b152ebb2f27 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 13:45:22 -0700 Subject: [PATCH 13/21] use mp4 ending in test --- tests/io/test_videowriter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index 4aa5785a2..c3c35ed52 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -1,4 +1,5 @@ import os +import cv2 from pathlib import Path from sleap.io.videowriter import VideoWriter, VideoWriterOpenCV, VideoWriterImageio From 38359e7acdc11985a99a609e8aa9f4f0999fbff5 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 13:47:11 -0700 Subject: [PATCH 14/21] test `VideoWriterImageio` with avi file extension --- tests/io/test_videowriter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index c3c35ed52..5f9640a38 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -42,7 +42,7 @@ def test_cv_video_writer(tmpdir, small_robot_mp4_vid): assert os.path.exists(out_path) -def test_imageio_video_writer(tmpdir, small_robot_mp4_vid): +def test_imageio_video_writer_avi(tmpdir, small_robot_mp4_vid): out_path = Path(tmpdir) / "clip.avi" # Make sure imageio video writer works From a6b9709516994290a9861a91e40eb50e36384410 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 14:13:56 -0700 Subject: [PATCH 15/21] test video with odd size --- tests/io/test_videowriter.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index 5f9640a38..c80642e27 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -66,3 +66,36 @@ def test_imageio_video_writer_avi(tmpdir, small_robot_mp4_vid): assert writer.filename == out_path assert writer.crf == 21 assert writer.preset == "superfast" + + +def test_imageio_video_writer_odd_size(tmpdir, movenet_video): + out_path = Path(tmpdir) / "clip.mp4" + + # Reduce the size of the video frames by 1 pixel in each dimension + reduced_height = movenet_video.height - 1 + reduced_width = movenet_video.width - 1 + + # Initialize the writer with the reduced dimensions + writer = VideoWriterImageio( + out_path, + height=reduced_height, + width=reduced_width, + fps=movenet_video.fps, + ) + + # Resize frames and add them to the video + for i in range(len(movenet_video) - 1): + frame = movenet_video[i][0] # Access the actual frame object + reduced_frame = cv2.resize(frame, (reduced_width, reduced_height)) + writer.add_frame(reduced_frame) + + writer.close() + + # Assertions to validate the test + assert os.path.exists(out_path) + assert writer.height == reduced_height + assert writer.width == reduced_width + assert writer.fps == movenet_video.fps + assert writer.filename == out_path + assert writer.crf == 21 + assert writer.preset == "superfast" \ No newline at end of file From e04743bd2b6e7bbe9a70005f99e72682cc4f9507 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 14:14:19 -0700 Subject: [PATCH 16/21] remove redundant filter since imageio-ffmpeg resizes automatically --- sleap/io/videowriter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index 94bc397c4..7cf98f154 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -116,8 +116,6 @@ def __init__( preset, "-crf", str(crf), - "-vf", - "scale=trunc(iw/2)*2:trunc(ih/2)*2", # Ensure even dimensions ], ) From eac1d89f035c9ab63b18436bce5f5b236fb9855c Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 14:17:35 -0700 Subject: [PATCH 17/21] black --- tests/io/test_videowriter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index c80642e27..35d9bc6df 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -98,4 +98,4 @@ def test_imageio_video_writer_odd_size(tmpdir, movenet_video): assert writer.fps == movenet_video.fps assert writer.filename == out_path assert writer.crf == 21 - assert writer.preset == "superfast" \ No newline at end of file + assert writer.preset == "superfast" From 75d637eb0ea9fbee7968cca6381e82c4e28c3077 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 14:21:53 -0700 Subject: [PATCH 18/21] remove unused import --- tests/io/test_videowriter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index 35d9bc6df..b40ed90fb 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -1,5 +1,4 @@ import os -import cv2 from pathlib import Path from sleap.io.videowriter import VideoWriter, VideoWriterOpenCV, VideoWriterImageio From 15c502c6cdf2b66af55d27a285b01891281f7988 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 14:38:57 -0700 Subject: [PATCH 19/21] use logging instead of print statement --- sleap/io/videowriter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index 7cf98f154..b80861802 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -13,6 +13,7 @@ import cv2 import numpy as np import imageio.v2 as iio +import logging class VideoWriter(ABC): @@ -34,7 +35,7 @@ def close(self): def safe_builder(filename, height, width, fps): """Builds VideoWriter based on available dependencies.""" if VideoWriter.can_use_ffmpeg(): - print("USING IMAGEIO") + logging.info("USING IMAGEIO") return VideoWriterImageio(filename, height, width, fps) else: return VideoWriterOpenCV(filename, height, width, fps) From 9f488e325f07ec2ada97e02f68dab5cd7e0229b1 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Wed, 14 Aug 2024 15:06:04 -0700 Subject: [PATCH 20/21] import cv2 is needed for resize --- tests/io/test_videowriter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/io/test_videowriter.py b/tests/io/test_videowriter.py index b40ed90fb..35d9bc6df 100644 --- a/tests/io/test_videowriter.py +++ b/tests/io/test_videowriter.py @@ -1,4 +1,5 @@ import os +import cv2 from pathlib import Path from sleap.io.videowriter import VideoWriter, VideoWriterOpenCV, VideoWriterImageio From 8def1c874c1cbde3b477bf35ca40b0a7e1a3c9a4 Mon Sep 17 00:00:00 2001 From: Elizabeth Berrigan Date: Thu, 15 Aug 2024 09:43:21 -0700 Subject: [PATCH 21/21] remove logging --- sleap/io/videowriter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sleap/io/videowriter.py b/sleap/io/videowriter.py index b80861802..cd710c9d5 100644 --- a/sleap/io/videowriter.py +++ b/sleap/io/videowriter.py @@ -13,7 +13,6 @@ import cv2 import numpy as np import imageio.v2 as iio -import logging class VideoWriter(ABC): @@ -35,7 +34,6 @@ def close(self): def safe_builder(filename, height, width, fps): """Builds VideoWriter based on available dependencies.""" if VideoWriter.can_use_ffmpeg(): - logging.info("USING IMAGEIO") return VideoWriterImageio(filename, height, width, fps) else: return VideoWriterOpenCV(filename, height, width, fps)