How to capture,record,playback and stream at 1080p with LeopardBoard DM36x

From RidgeRun Developer Connection
Jump to: navigation, search

Introduction

RidgeRun offers a pre-built bootable SD card image you can use to capture to file or stream 1080p with your LeopardBoard DM368. You can also configure your RidgeRun evaluation or professional SDK to build the image yourself if you prefer.

Hardware needed

  • LeopardBoard DM368
  • LI-5M03 camera module with MT9P031 sensor.

Command to run to view the component output on the display monitor

Setting the component output port of the leoboard to 1080I_30 component output:

After boot process completes, please run below command on the board prompt:

echo 1080I-30 > /sys/class/davinci_display/ch0/mode

GStreamer 1080P Pipelines

Live preview

Video from MT9P031 CMOS camera sensor is sent out component output signals.

gst-launch -v --gst-debug-level=2 v4l2src input-src=camera chain-ipipe=true always-copy=false num-buffers=2000 ! \
           capsfilter caps='video/x-raw-yuv,format=(fourcc)NV12,width=1920,height=1088' ! dmaiaccel ! \
           dmaiperf print-arm-load=true ! TIDmaiVideoSink enable-last-buffer=false videoStd=1080I_30 

Record to file H264 encoding and QT muxer

Video from MT9P031 CMOS camera sensor is H264 encoded and wrapped in QT (MP4) muxer and saved to file.

H264ENC_PARMS="encodingpreset=2 ratecontrol=2 intraframeinterval=23 idrinterval=46 targetbitrate=3000000 \
               profile=100 level=50 entropy=1 t8x8inter=true t8x8intra=true single-nalu=true"
VIDEO_FILE=h264file.mp4

gst-launch -e --gst-debug-level=2 v4l2src always-copy=FALSE input-src=camera chain-ipipe=true num-buffers=1500 ! \
           capsfilter caps='video/x-raw-yuv,format=(fourcc)NV12,width=1920,height=1088' ! dmaiaccel ! \
           dmaienc_h264 $H264ENC_PARMS ! queue ! dmaiperf print-arm-load=true ! qtmux ! queue ! /
           filesink location=$VIDEO_FILE sync=false enable-last-buffer=false 

Play previously recorded file

Play a file to composite output signals that was recorded using the pipeline shown in the previous section.

VIDEO_FILE=h264file.mp4

gst-launch filesrc location=$VIDEO_FILE ! qtdemux ! queue ! dmaidec_h264 numOutputBufs=8 closedloop=1 ! queue ! \
           dmaiperf ! 'video/x-raw-yuv, format=(fourcc)NV12' ! \
           TIDmaiVideoSink videoOutput=component videoStd=1080I_30 enable-last-buffer=false

Live preview while recording

Use case is a device that is capturing video with a camera, having an HD Monitor (HD 1080p TV) showing a live preview of the video being captured, along with the video being saved to file. A simple gst-launch type command is shown below. For a real product, you might want to consider using GStreamer daemon so that you can start and stop the recording.

H264ENC_PARMS="encodingpreset=2 ratecontrol=2 intraframeinterval=23 idrinterval=46 targetbitrate=3000000 \
               profile=100 level=50 entropy=1 t8x8inter=true t8x8intra=true single-nalu=true"
VIDEO_FILE=h264file.mp4

gst-launch -e v4l2src input-src=camera chain-ipipe=true always-copy=false num-buffers=1500 ! \
           capsfilter caps='video/x-raw-yuv,format=(fourcc)NV12,width=1920,height=1088' ! dmaiaccel ! \
           tee name=t1 ! TIDmaiVideoSink enable-last-buffer=false videoStd=1080I_30 videoOutput=COMPONENT \
           t1. ! queue ! dmaienc_h264 $H264ENC_PARMS ! queue ! dmaiperf print-arm-load=true ! \
           qtmux ! queue ! filesink location=$VIDEO_FILE sync=false enable-last-buffer=false

1080P RTSP streaming

On Leopardboard368 run the following pipeline:

H264ENC_PARMS="encodingpreset=2 ratecontrol=2 targetbitrate=2000000 intraframeinterval=30 idrinterval=90 \
               bytestream=true"

gst-launch v4l2src input-src=camera always-copy=false ! \
           capsfilter caps='video/x-raw-yuv, width=1920, height=1088, framerate=(fraction)30/1' ! dmaiaccel ! \
           dmaiperf ! dmaienc_h264 $H264ENC_PARMS ! queue ! mpegtsmux ! "video/mpegts, mapping=/stream" ! rtspsink

OR


Note : Please try below combination of pipelines if above pipelines causing any issues because of 'mpegtsmux'. (This pipeline is tested using VLC Player at host PC)

H264ENC_PARMS="encodingpreset=2 ratecontrol=2 targetbitrate=2000000 intraframeinterval=30 idrinterval=90"
                                        

gst-launch v4l2src input-src=camera always-copy=false ! capsfilter caps='video/x-raw-yuv, width=1920, height=1088, framerate=(fraction)30/1' ! dmaiaccel ! d
maiperf ! dmaienc_h264 $H264ENC_PARMS ! "video/x-h264, mapping=/stream" ! rtspsink


Note: You can test for 720P Video Streaming by setting width=1280,height=720 and framerate=(fraction)23/1'in the above pipeline. (host side pipeline remains the same).

On the host you can use VLC to browse to the Leopardboard368.

LEO_IP_ADDR=192.168.0.1 # replace with the IP address of your target hardware

vlc rtsp://$LEO_IP_ADDR/stream

OR

mplayer rtsp://$LEO_IP_ADDR/stream

OR

openRTSP rtsp://$LEO_IP_ADDR/stream  

(You may have to run 'sudo apt-get install livemedia-utils' to work with 'openRTSP')

If you rather, you can run GStreamer on your host PC.

gst-launch rtspsrc location="rtsp://$LEO_IP_ADDR/stream" ! rtpmp2tdepay ! mpegtsdemux ! queue ! ffdec_h264 ! \
           xvimagesink sync=false

You need GStreamer packages installed on your Ubuntu desktop.

sudo apt-get install gstreamer0.10-alsa gstreamer0.10-ffmpeg gstreamer0.10-fluendo-mp3 gstreamer0.10-plugins-bad 
sudo apt-get install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly 
sudo apt-get install gstreamer0.10-tools gstreamer0.10-x

SDK Configuration

1. Select the MT9P031 driver to support your camera module

Prompt: mt9p031 support
Location:
-> Kernel configuration
-> Device Drivers
-> Multimedia support (MEDIA_SUPPORT [=y])
-> Video capture adapters (VIDEO_CAPTURE_DRIVERS [=y])

2. Configure your SDK in order to be able to capture at 1080p as is shown below:

Architecture configurations
Video Output (Component) --->
Component Standard (720P) --->
Maximum Video Output Buffer Size (1080I-30) --->
Maximum Video Input Buffer Size (1080P) --->

3. Increase the reserved memory and the CMEM space to allocate the 1080p buffers.

Proprietary Software
[*] Reserve memory from the kernel for codec engine and friends automatically
(0X4FCA000) Amount of reserved memory from the kernel
[*] Automatically setup CMEM at the beggining of the reserved memory area
(0X35CA000) Amount of reserved memory for cmemk 

4. If your target format is H264 and you are using an EVAL version of the SDK you will need to do the following modification into you MT9P031 driver:

Index: kernel/linux-2.6.32.17-psp03.01.01.39/drivers/media/video/mt9p031.c
===================================================================
--- kernel.orig/linux-2.6.32.17-psp03.01.01.39/drivers/media/video/mt9p031.c 2012-08-10 09:44:39.763840232 -0700
+++ kernel/linux-2.6.32.17-psp03.01.01.39/drivers/media/video/mt9p031.c 2012-08-10 09:45:20.195126497 -0700
@@ -204,7 +204,7 @@
},
{
/* 1080P-HDTV */
- .framesize = { 1920, 1080},
+ .framesize = { 1920, 1088},
.frameintervals = {
{ .numerator = 1, .denominator = 30 },
},

This modification will allow use 1080p with the H264 encoder.

5. Re-built your SDK and install it into your board.

6. Setting the component output port of the leoboard to 1080I_30 component output:

After boot process completes, please run below command on the board prompt:

echo 1080I-30 > /sys/class/davinci_display/ch0/mode

7.We use 'rtspsink' element for RTSP streaming in this setup.So please check whether 'rtspsink' element is properly installed under target board using the command 'gst-inspect rtspsink'