LoginSignup
7
9

More than 3 years have passed since last update.

Raspberry PiのカメラをGStreamerプラグインとして使用する方法

Last updated at Posted at 2020-02-01

GstRpiCamSrc

本稿では、Raspberry PiにGStreamer + GstRpiCamSrcをインストールし、Raspberry Piのカメラ映像をGStreamerのプラグインとして利用できるようにする。

なお、動作確認済みのカメラは次の通り。

製品名 センサー 画素数
Raspberry Pi Camera Module v1 OmniVision OV5647 5M
Raspberry Pi Camera Module v2 Sony IMX219 8M
Raspberry Pi HQ Camera Sony IMX477 12.3M

GStreamerをインストール

  1. パッケージからインストールする。

    $ sudo apt install gstreamer1.0-omx gstreamer1.0-tools gstreamer1.0-plugins-*
    

GstRpiCamSrcをインストール

ソースからビルド

  1. 関連パッケージをインストールする。

    $ sudo apt install libgstreamer1.0-dev  libgstreamer-plugins-base1.0-dev
    
  2. ソースファイルをダウンロードする。

    $ cd /usr/src
    $ sudo git clone https://github.com/thaytan/gst-rpicamsrc.git
    $ sudo chown -R pi:pi gst-rpicamsrc
    
  3. ビルドする。

    $ cd gst-rpicamsrc
    $ ./autogen.sh --prefix=/usr --libdir=/usr/lib/arm-linux-gnueabihf/
    $ make
    
  4. インストールする。

    $ sudo make install
    
  5. Element一覧に表示されることを確認する。

    $ gst-inspect-1.0 | grep rpicamsrc
    rpicamsrc:  rpicamsrcdeviceprovider (GstDeviceProviderFactory)
    rpicamsrc:  rpicamsrc: Raspberry Pi Camera Source
    
    $ gst-inspect-1.0 rpicamsrc
    

GstRpiCamSrc のパラメータ

  • 利用可能形式

    フォーマット 利用可能形式
    共通 width: [ 1, 2147483647 ]
    height: [ 1, 2147483647 ]
    framerate: [ 0/1, 2147483647/1 ]
    video/x-h264 stream-format: byte-stream
    alignment: nal
    profile: { constrained-baseline, baseline, main, high }
    image/jpeg -
    video/x-raw format: { I420, RGB, BGR, RGBA }

TS形式ファイルを比較

  1. TS形式ファイルに30秒間録画する。

    $ timeout 30 gst-launch-1.0 -e \
    videotestsrc \
    ! video/x-raw, width=1920, height=1080, framerate=30/1 \
    ! clockoverlay \
    ! omxh264enc \
    ! h264parse \
    ! queue \
    ! mpegtsmux \
    ! filesink location=videotestsrc.ts
    
  2. Raspberry Piのハードウェアエンコーダー(OpenMAX)を使用し、TS形式ファイルに30秒間録画する。

    $ timeout 30 gst-launch-1.0 -e \
    rpicamsrc preview=0 bitrate=10000000 \
    ! video/x-raw, width=1920, height=1080, framerate=30/1 \
    ! clockoverlay \
    ! omxh264enc \
    ! h264parse \
    ! queue \
    ! mpegtsmux \
    ! filesink location=rpicamsrc.ts
    
  3. 映像ファイル形式を確認する。

  • videotestsrc

    $ ls -l videotestsrc.ts
    -rw-r--r-- 1 pi pi 7000932 Feb  1 18:48 videotestsrc.ts
    
    $ gst-typefind-1.0 videotestsrc.ts
    videotestsrc.ts - video/mpegts, systemstream=(boolean)true, packetsize=(int)188
    
  • rpicamsrc

    $ ls -l rpicamsrc.ts
    -rw-r--r-- 1 pi pi 820620 Feb  1 18:49 rpicamsrc.ts
    
    $ gst-typefind-1.0 rpicamsrc.ts
    rpicamsrc.ts - video/mpegts, systemstream=(boolean)true, packetsize=(int)188
    
7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9