basic_bot.commons.vid_utils
This module contains utility functions for working with OpenCV.
record_video
Record a video to BB_VIDEO_PATH for a specified number of seconds.
Calling this function will save an MP4 video file to the BB_VIDEO_PATH directory.
The filename is the current date and time in the format YYYYMMDD-HHMMSS.mp4
.
It will also save the first frame of the video as a JPEG image in the same directory
named YYYYMMDD-HHMMSS.jpg
.
record_webrtc_video
Record video and audio via WebRTC from the vision service for a specified number of seconds.
This function connects to the vision service's WebRTC endpoint to record both video and audio, while still using the provided camera to capture thumbnail frames.
Calling this function will save an MP4 video file to the BB_VIDEO_PATH directory.
The filename is the current date and time in the format YYYYMMDD-HHMMSS.mp4
.
It will also save the first frame of the video as a JPEG image in the same directory
named YYYYMMDD-HHMMSS.jpg
, captured from the provided camera parameter.
Arguments:
camera
- Camera instance used for thumbnail generationduration
- Recording duration in seconds
Returns:
Base filename (without extension) of the recorded files
convert_video_to_h264
Sse system installed ffmpeg to convert video to h264. This was needed to make the mp4 video captured using openCV compatible with web browsers.
TODO: It would be nice to do this directly with cv2 VideoWriter, but I could not get it to work. I think it is running into the same issue described here in StackOverflow The solution descibed however (use apt-get to install opencv python instead of pip) probably causes other issues :/.
get_recorded_videos
Get a list of recorded videos in the BB_VIDEO_PATH directory.