Video, Natural

Required Hardware

Make sure that both built-in cameras are working properly. After booting Spiri, run this command:

$ dmesg | grep mt9m021

You should see both cameras 1 and 2 show lots of output, and successfully probe.

Insert an SD card into the Elroy. The SD card cannot be just anything, it needs to be UHS-1. Sandisk cards usually are. It is easiest to do this at assembly time. You need to mount the card after booting up.

$ sudo mount dev/mmcblk1p1

The first time you put the card in, you might have to format it. This reformats as ext4:

$ sudo mkfs.ext4 /dev/mmcblk1p1

On the card, you can create folders, but you should change them to be owned by your username rather than root. So:

$ sudo mkdir -p /mnt/video
$ chown nvidia:nvidia /mnt/video

You only need to do these things once.

Video Capture

There are roslaunch files to start the cameras. These commands will generate all the topics in stereo_image_proc, including rectified, color images. This is how to save the rectified color image from the right side camera.

$ roslaunch jetson_csi_cam cameras.launch
$ rosbag record -o video_file /stereo/right/image_rect_color > /mnt/video

This starts recording right away, and the -o tag means that “video_file” will be appended with the date and time. The file format will be .bag -- a rosbag file and it will be written to the SD card.

Frame Extraction and Video Encoding

It is good to make a folder to put all the frames in and extract them there.

$ mkdir -p /mnt/video/video_file_frames
$ cd /mnt/video/video_file_frames
$ mv /mnt/video/video_file_.bag .

Now extract the video. You need two terminal screens, one for each of the following commands.

Screen 1:

$ rosrun image_view extract_images _sec_per_frame:=0.033 image:=/stereo/right/image_rect_color

Screen 2:

$ robag play video_file_.bag

This extracts frames from the rosbag assuming 30 frames per second. Next, you can encode those frames into a video:

$ ffmpeg -f image2 -r 30 -i %04d.jpg -vcodec libx264 -profile:v high444 -refs 16 -crf 0 video_file_.mp4