Recording

Multimedia User Guide (UG1449)

Document ID
UG1449
Release Date
2023-10-19
Revision
1.7 English

Use the following pipelines to record video from an input source to the required file format.

  • To record only the video stream:
    gst-launch-1.0 v4l2src device=/dev/video0 io-mode=4 ! \
    video/x-raw,format=NV12,width=3840,height=2160,framerate=60/1 ! \
    omxh265enc qp-mode=auto gop-mode=basic gop-length=60 b-frames=0 \
    target-bitrate=60000 num-slices=8 control-rate=constant prefetch-buffer=true \
    low-bandwidth=false filler-data=true cpb-size=1000 initial-delay=500 ! \
    queue ! video/x-h265, profile=main, alignment=au ! mpegtsmux alignment=7 name=mux ! \
    filesink location="/run/media/sda/test.ts"

    This example shows that the live source device link is present under the /dev directory. Encoded video format is H265 and color format is NV12. Video stream resolution is 4k and 60fps. The record file test.ts is present in SATA drive in TS file format.

    Note:
    1. For input source with 1080p@60 resolution, replace width and height with 1920 and 1080 respectively. Frame rate can also be changed to 30.
    2. To encode input stream into H264 video format, replace h265 in the above pipeline with h264.
  • To record both the video and audio stream:

    The following pipeline can be used to record video with audio from an input source to the required file format.

    gst-launch-1.0 v4l2src device=/dev/video0 io-mode=4 ! \
    video/x-raw, format=NV12, width=3840, height=2160, framerate=60/1 ! \
    omxh265enc qp-mode=auto gop-mode=basic gop-length=60 b-frames=0 \
    target-bitrate=60000 num-slices=8 control-rate=constant prefetch-buffer=true \
    low-bandwidth=false filler-data=true cpb-size=1000 initial-delay=500 ! \
    video/x-h265, profile=main, alignment=au ! queue ! mux. alsasrc device=hw:2,1 ! \
    audio/x-raw, format=S24_32LE, rate=48000, channels=2 ! queue ! \
    audioconvert ! audioresample ! faac ! aacparse ! mpegtsmux name=mux ! \
    filesink location="/run/media/sda/test.ts"

    In this example, video and audio can be encoded using a single gstreamer pipeline to record into a single file. Encoded audio stream is AAC. Audio capture device is hw:2,1 and record file test.ts is present in SATA. For video encoding, the pipeline remains the same as the previous example.