MIPI Camera Testing

QuecPi Alpha single-board computer supports MIPI interface cameras. Here, we take a imx219 CSI interface CMOS camera from Waveshare as an example for testing.

Camera Connection

Connect as shown in the figure below. When connecting, pull up the black latch part of the connector, insert the FPC cable. Note that the metal contact surface should face the inner metal contact surface of the board. Press the latch and confirm that the FPC cable is stable and not loose.

Image 1

QuecPi Connection Diagram

Image 3

Camera Connection Diagram

Single Camera Stream Startup

  1. Run the following command in the device terminal.
mount -o rw,remount /
export XDG_RUNTIME_DIR=/dev/socket/weston
export WAYLAND_DISPLAY=wayland-1
gst-launch-1.0 -e qtiqmmfsrc name=camsrc ! 'video/x-raw(memory:GBM),format=NV12,width=1280,height=720,framerate=30/1' ! fakesink
  1. This example shows how to start the camera with the 720p@30 FPS configuration. Frames from the camera sensor are discarded by fakesink. If the gst pipeline state changes to “PLAYING” as shown below, it means the camera is running. Since this command dumps camera frames to fakesink, nothing will be saved on the device.
gbm_create_device(187): Info: backend name is: msm_drm 
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ... 
New clock: GstSystemClock
  1. If you want to display the captured image in real-time, you need to connect the HDMI screen in advance and execute the following command:
gst-launch-1.0 -e qtiqmmfsrc name=camsrc ! 'video/x-raw(memory:GBM),format=NV12,width=1280,height=720,framerate=30/1' ! waylandsink
  • If you want to display in full screen, add fullscreen=true at the end of the command
  • If you want to stop the camera recording, press CTRL+C

Video Encoding

  1. Run the following command in the device terminal:
gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 ! \
video/x-raw\(memory:GBM\),format=NV12,width=1280,height=720,framerate=30/1,\
compression=ubwc,interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc \
capture-io-mode=5 output-io-mode=5 extra-controls="controls,video_bitrate=6000000,\
video_bitrate_mode=0;" ! h264parse ! mp4mux ! filesink location=/opt/mux_avc.mp4
  1. This command starts the camera with the 720p 30 FPS configuration and saves it as a video file after h264 video encoding. If the gst pipeline state changes to “PLAYING”, it means the camera is running.
  2. If you want to stop the camera recording, press CTRL+C.
  3. The MP4 file is saved in the /opt/ directory.

Command description:

  • ! is a connection symbol used to connect the output of the previous element to the input of the next element.

  • gst-launch-1.0 This is the command-line tool of GStreamer used to start a GStreamer pipeline. The -e parameter means to exit when the pipeline ends instead of continuing to run.

  • qtiqmmfsrc name=camsrc camera=0 A camera source plugin dedicated to the Qualcomm platform, capturing video from device camera=0 (main camera).

  • video/x-raw\(memory:GBM\),format=NV12,width=1280,height=720,framerate=30/1 video/x-raw (raw video), using GBM memory management (suitable for Qualcomm GPU acceleration), NV12 (YUV 4:2:0, single-plane format, common in video encoding), resolution 1280×720 (720p), frame rate 30fps.

  • compression=ubwc,interlace-mode=progressive,colorimetry=bt601video/x-raw (raw video), using GBM memory management (suitable for Qualcomm GPU acceleration), NV12 (YUV 4:2:0, single-plane format, common in video encoding), resolution 1280×720 (720p), frame rate 30fps.

  • `v4l2h264enc capture-io-mode=5 output-io-mode=5 \

extra-controls="controls,video_bitrate=6000000,video_bitrate_mode=0;"` Uses DMABUF (Direct Memory Access Buffer) for input to optimize data transmission efficiency, also uses DMABUF to output encoded data, the target bitrate is 6 Mbps, and uses CBR (Constant Bit Rate) mode, suitable for network streaming media or scenarios that require stable bandwidth.

  • h264parse ! mp4mux ! filesink location=/opt/mux_avc.mp4 Parses the H.264 stream, adds the necessary NAL unit headers to make it conform to the MP4 encapsulation requirements, encapsulates the H.264 video stream into MP4 format, and writes the data to the file /opt/mux_avc.mp4.

Video Encoding and Snapshot

  1. Run the following command in the device terminal:
gst-pipeline-app -e qtiqmmfsrc name=camsrc camera=0 ! \
video/x-raw\(memory:GBM\),format=NV12,width=1280,height=720,framerate=30/1,\
compression=ubwc,interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc \
capture-io-mode=5 output-io-mode=5 extra-controls="controls,video_bitrate=6000000,\
video_bitrate_mode=0;" ! h264parse ! mp4mux ! filesink location=/opt/mux_avc.mp4 \
camsrc.image_1 ! "image/jpeg,width=1280,height=720,framerate=30/1" \
! multifilesink location=/opt/frame%d.jpg async=false sync=true
  1. Press the Enter key. This command will print the following menu and wait for user input.
##################################### MENU #####################################

============================== Pipeline Controls==============================
(0) NULL: Set the pipeline into NULL state
(1) READY: Set the pipeline into READY state
(2) PAUSED: Set the pipeline into PAUSED state
(3) PLAYING: Set the pipeline into PLAYING state

==================================== Other====================================
(p) Plugin Mode: Choose a plugin which to control
(q) Quit : Exit the application

Choose an option:
  1. Use the following menu steps to take a snapshot while recording a video.
(1) ready -> (3) Playing -> (p)Plugin Mode : Select (8)camerasrc ->(36) capture-image -> (1): still – Snapshot ->(1) Snapshot count ('guint' value for arg1)
  1. To stop the camera, press Enter, press b (back), and then press q (quit). The recorded video files and snapshot images are saved in /opt/. You can extract the recorded content from the device by running the following scp command on the host PC:
scp -r root@[ip-addr]:/opt/<file name> .
  • The generated files are as shown in the figure below: