🏎️

NanoPC-T6のUbuntu 22.04でgstreamerでハードウェアエンコードを試す

2023/06/12に公開

これの続き。
https://zenn.dev/tetsu_koba/articles/76f7bdb3f36200

バージョンの確認

カーネルとUbuntuのバージョン。

$ cat /proc/version 
Linux version 5.10.110 (root@jensen) (aarch64-linux-gcc (ctng-1.25.0-119g-FA) 11.3.0, GNU ld (GNU Binutils) 2.38) #15 SMP Fri May 26 10:44:08 CST 2023
$ cat /etc/issue
Ubuntu 22.04.2 LTS \n \l

gstreamerのバージョン

$ gst-inspect-1.0 --version
gst-inspect-1.0 version 1.20.3
GStreamer 1.20.3
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0

Rockchipのライブラリをインストール

参考にしたページ
https://forum.radxa.com/t/introduction-to-rockchip-multimedia-ppa-for-ubuntu-jammy/14537

$ sudo add-apt-repository ppa:liujianfeng1994/rockchip-multimedia
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install rockchip-multimedia-config
$ sudo apt install gstreamer1.0-rockchip1 
$ gst-inspect-1.0 |grep -i rockchip
rkisp:  rkisp: Gstreamer Plugin For Rockchip ISP Source
rockchipmpp:  mpph264enc: Rockchip Mpp H264 Encoder
rockchipmpp:  mpph265enc: Rockchip Mpp H265 Encoder
rockchipmpp:  mppjpegdec: Rockchip's MPP JPEG image decoder
rockchipmpp:  mppjpegenc: Rockchip Mpp JPEG Encoder
rockchipmpp:  mppvideodec: Rockchip's MPP video decoder
rockchipmpp:  mppvpxalphadecodebin: VP8/VP9 Alpha Decoder

USBカメラの映像をH.265で録画

rec0.sh
#!/bin/sh -xue

gst-launch-1.0 -e v4l2src device="/dev/video0" ! \
    'image/jpeg, width=1280, height=720, framerate=30/1' ! \
    jpegdec ! \
    videoconvert ! 'video/x-raw, format=(string)I420' ! \
    mpph265enc gop=60 bps=1000000 ! \
    queue ! \
    h265parse ! mpegtsmux alignment=7 ! \
    filesink location=out.m2ts

$ ./rec0.sh

^Cで止める

$ ffprobe out.m2ts
...
Input #0, mpegts, from 'out.m2ts':
  Duration: 00:00:16.82, start: 3600.647256, bitrate: 1089 kb/s
  Program 1 
  Stream #0:0[0x41]: Video: hevc (Main) ([36][0][0][0] / 0x0024), yuv420p(tv), 1280x720, 30 fps, 30 tbr, 90k tbn, 30 tbc

JPEGのデコードもハードウェアで行う

入力するビデオのサイズも4Kにする。

rec1.sh
#!/bin/sh -xue

gst-launch-1.0 -e v4l2src device="/dev/video0" ! \
    'image/jpeg, width=3840, height=2160, framerate=30/1' ! \
    mppjpegdec ! 'video/x-raw, format=(string)NV12' ! \
    mpph265enc gop=60 bps=8000000 ! \
    queue ! \
    h265parse ! mpegtsmux alignment=7 ! \
    filesink location=out.m2ts
$ ./rec1.sh

^Cで止める

$ ffprobe out.m2ts
...
Input #0, mpegts, from 'out.m2ts':
  Duration: 00:00:21.94, start: 3600.696578, bitrate: 14145 kb/s
  Program 1 
  Stream #0:0[0x41]: Video: hevc (Main) ([36][0][0][0] / 0x0024), yuv420p(tv), 3840x2160, 30 fps, 30 tbr, 90k tbn, 30 tbc

関連

https://zenn.dev/tetsu_koba/articles/76f7bdb3f36200
https://zenn.dev/tetsu_koba/articles/8c22466ce57498

Discussion