Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render videos from CLI #795

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions sleap/io/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -139,6 +142,25 @@ 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)

frames = int(args.frames)
frames = (
input_label.video.frames
if int(args.frames) == 0 or int(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)),
)

else:
print("You didn't specify how to convert the file.")
print(args)
Expand Down