# 使用 gst-launch-1.0

Source: [https://docs.qualcomm.com/doc/80-70014-17Y/topic/using_gst_launch_1_0.html](https://docs.qualcomm.com/doc/80-70014-17Y/topic/using_gst_launch_1_0.html)

使用 gst-launch-1.0 命令行 GStreamer 实用工具编译并运行 GStreamer Pipeline。

Pipeline 被指定为元素的集合，其属性以 `!`分隔。

## 前提条件

要使用 [gst-launch-1.0](https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html?gi-language=c) 和 GStreamer 插件，必须在设备上安装 QIM SDK (meta-qcom-qim-product-sdk)。有关 QIM SDK 的编译和安装信息，可参见 [Qualcomm Linux 编译指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/introduction.html)。

Note: 使用 SSH 连接到设备控制台。相关说明，请参见[如何使用 SSH？](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/how_to.html#how-to-ssh-)确保在 Permissive 模式下启用 SSH。

在 SSH 终端中运行以下命令：

    # mount -o rw,remount /
    # export XDG_RUNTIME_DIR=/dev/socket/weston
    # export WAYLAND_DISPLAY=wayland-1
    Copy to clipboard

## 单摄像头流启动

1. 在设备终端运行以下命令：

        gst-launch-1.0 -e qtiqmmfsrc name=camsrc ! 'video/x-raw(memory:GBM),format=NV12,\
        width=1280,height=720,framerate=30/1' ! fakesink
        Copy to clipboard
2. 以下示例说明如何使用 720p@30 FPS 配置启动摄像头。来自摄像头传感器的帧被 fakesink 丢弃。如果 gst pipeline 状态更改为 "PLAYING"，则表示摄像头正在运行。由于此命令会将摄像头帧转储到 fakesink，因此不会在设备上保存任何内容。有关操作摄像头和保存视频文件的信息，可参见 [视频编码](https://docs.qualcomm.com/doc/80-70014-17Y/topic/using_gst_launch_1_0.html#using_gst_launch_1_0__video-encode) 和 [视频编码和快照](https://docs.qualcomm.com/doc/80-70014-17Y/topic/using_gst_launch_1_0.html#using_gst_launch_1_0__video-encode-snapshot)。

        gst-launch-1.0 -e qtiqmmfsrc name=camsrc ! 'video/x-
        raw(memory:GBM),form at=NV12,width=1280,height=720,framerate=30/1' ! fakesink 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
        Copy to clipboard

要停止摄像头，按 CTRL+C。

## 视频编码

1. 在设备终端运行以下命令：

        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
        Copy to clipboard

    此命令以 720p@30 FPS 配置启动摄像头，并在 h264 视频编码后将其另存为视频文件。如果 gst pipeline 状态更改为 "PLAYING"，则表示摄像头正在运行。

    要停止摄像头，按 CTRL+C。
2. /opt/mux\_avc.mp4 在设备上生成。通过在主机 PC 上运行以下 scp 命令，可以从设备中提取录制的内容：

        $ scp -r root@[ip-addr]:/opt/mux_avc.mp4。Copy to clipboard

## 视频编码和快照

1. 在设备终端运行以下命令：

        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,i nterlace-mode=progressive,colorimetry=bt601 \
        ! v4l2h264enc capture-io-mode=5 output-io-mode=5 extra- controls="controls,video_bitrate=5000000,video_bitrate_mode=0;" \
        ! queue ! h264parse ! mp4mux ! queue ! filesink location=/opt/mux3.mp4
        \
        camsrc.image_1 ! "image/jpeg,width=1280,height=720,framerate=30/1" \
        ! multifilesink location=/opt/frame%d.jpg async=false sync=true
        Copy to clipboard
2. 按 Enter。此命令将打印以下菜单并等待用户输入。

        ##################################### 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:
        Copy to clipboard
3. 使用以下菜单步骤在录制视频时拍摄快照（输入 arg1 的 guint 值）。

        (1) ready -> (3) Playing -> (p)Plugin Mode : Select (10)camerasrc ->(36) capture-image -> (1): still – Snapshot -> Snapshot countCopy to clipboard
4. 若要停止摄像头，按 **Enter**，按 **b**（返回），然后按 **q**（退出）。录制的视频文件和快照保存在 /opt/ 中。通过在主机 PC 上运行以下 scp 命令，可以从设备中提取录制的内容：

        $ scp -r root@[ip-addr]:/opt/<file name> .Copy to clipboard

**Parent Topic:** [GStreamer 摄像头应用程序](https://docs.qualcomm.com/doc/80-70014-17Y/topic/gstreamer_camera_application.html)

Last Published: Oct 23, 2024

[Previous Topic
GStreamer 摄像头应用程序](https://docs.qualcomm.com/bundle/publicresource/80-70014-17Y/topics/gstreamer_camera_application.md) [Next Topic
编写源代码](https://docs.qualcomm.com/bundle/publicresource/80-70014-17Y/topics/writing_source_code.md)