From dd0e41c8029e3a34bef878f6c8f8d9e88a9b2fa2 Mon Sep 17 00:00:00 2001 From: David Samy Date: Tue, 14 Jun 2022 12:16:21 -0700 Subject: [PATCH 1/4] add command to render video thru CLI --- sleap/io/convert.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sleap/io/convert.py b/sleap/io/convert.py index 303cb628f..7d7737a6b 100644 --- a/sleap/io/convert.py +++ b/sleap/io/convert.py @@ -89,6 +89,7 @@ def default_analysis_filename( def main(args: list = None): parser = create_parser() args = parser.parse_args(args=args) + print(args) video_callback = Labels.make_video_callback([os.path.dirname(args.input_path)]) try: @@ -139,6 +140,18 @@ def main(args: list = None): print(f"Output SLEAP dataset: {output_path}") Labels.save_file(labels, output_path) + elif args.format == "mp4": + import sleap.io.visuals + + input_label = sleap.load_file(args.input_path) + + sleap.io.visuals.save_labeled_video( + filename="sleap_render.mp4", + labels=input_label, + video=input_label.video, + frames=list(range(input_label.video.frames)), + ) + else: print("You didn't specify how to convert the file.") print(args) From 0313f0535d87be8d5344a1ac79941bcee9dafe99 Mon Sep 17 00:00:00 2001 From: David Samy Date: Tue, 14 Jun 2022 12:37:58 -0700 Subject: [PATCH 2/4] Add frames parameter --- sleap/io/convert.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sleap/io/convert.py b/sleap/io/convert.py index 7d7737a6b..c79c89573 100644 --- a/sleap/io/convert.py +++ b/sleap/io/convert.py @@ -69,6 +69,9 @@ def create_parser(): parser.add_argument( "--video", default="", help="Path to video (if needed for conversion)." ) + parser.add_argument( + "--frames", default=0, help="Amount of frames to render (mp4 only)" + ) return parser @@ -89,7 +92,6 @@ def default_analysis_filename( def main(args: list = None): parser = create_parser() args = parser.parse_args(args=args) - print(args) video_callback = Labels.make_video_callback([os.path.dirname(args.input_path)]) try: @@ -145,11 +147,14 @@ def main(args: list = None): input_label = sleap.load_file(args.input_path) + frames = int(args.frames) + frames = input_label.video.frames if args.frames == 0 or args.frames > input_label.video.frames else frames + sleap.io.visuals.save_labeled_video( filename="sleap_render.mp4", labels=input_label, video=input_label.video, - frames=list(range(input_label.video.frames)), + frames=list(range(frames)), ) else: From f88df369252f8cc284d503fccbd58557e6b5d44c Mon Sep 17 00:00:00 2001 From: David Samy Date: Tue, 14 Jun 2022 12:40:57 -0700 Subject: [PATCH 3/4] Black format --- sleap/io/convert.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sleap/io/convert.py b/sleap/io/convert.py index c79c89573..5d371d02c 100644 --- a/sleap/io/convert.py +++ b/sleap/io/convert.py @@ -148,14 +148,18 @@ def main(args: list = None): input_label = sleap.load_file(args.input_path) frames = int(args.frames) - frames = input_label.video.frames if args.frames == 0 or args.frames > input_label.video.frames else frames - + frames = ( + input_label.video.frames + if args.frames == 0 or args.frames > input_label.video.frames + else frames + ) + sleap.io.visuals.save_labeled_video( - filename="sleap_render.mp4", - labels=input_label, - video=input_label.video, - frames=list(range(frames)), - ) + filename="sleap_render.mp4", + labels=input_label, + video=input_label.video, + frames=list(range(frames)), + ) else: print("You didn't specify how to convert the file.") From 8b12088e901cd2e417a4c8b087dbfb136474adb4 Mon Sep 17 00:00:00 2001 From: David Samy Date: Tue, 14 Jun 2022 12:48:33 -0700 Subject: [PATCH 4/4] Handles empty and too large --frames --- sleap/io/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleap/io/convert.py b/sleap/io/convert.py index 5d371d02c..941b7f276 100644 --- a/sleap/io/convert.py +++ b/sleap/io/convert.py @@ -150,7 +150,7 @@ def main(args: list = None): frames = int(args.frames) frames = ( input_label.video.frames - if args.frames == 0 or args.frames > input_label.video.frames + if int(args.frames) == 0 or int(args.frames) > input_label.video.frames else frames )