Ubuntu 20.04.6 LTS - gstreamer HW encoding

Hi,
I’m having issues trying to h264/h265 HW encode with gtreamer (rtsp-server).
Ubuntu 20.04.6 LTS on ROCK 5B

Software encoding works fine with “videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96”

I should use this for hardware encoding :
“videotestsrc ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! videoconvert ! mpph264enc ! rtph264pay name=pay0 pt=96”
But mpph264enc is missing

I’ve installed mpp (https://wiki.radxa.com/Rock5/guide/rockchip-mpp) and gstreamer1.0-rockchip1-extra.

I tried to install gstreamer1.0-rockchip1 from focal testing (https://wiki.radxa.com/Template:Rockpi_apt), but i’m getting :
The following packages have unmet dependencies:
gstreamer1.0-rockchip1 : Depends: librockchip-mpp1 but it is not installable

I’m stuck on this, should I manualy build something ? or switch to another ubuntu image version ?

Thanks

Build and install: (https://github.com/JeffyCN/mirrors/tree/gstreamer-rockchip)

1 Like

Hello,

I builded and installed gstreamer-rockship but still no encoder, Am I missing something ?

rock@rock-5b:~/mirrors$ meson build_dir
The Meson build system
Version: 1.1.0
Source dir: /home/rock/mirrors
Build dir: /home/rock/mirrors/build_dir
Build type: native build
Project name: gst-plugins-bad
Project version: 1.14.4
C compiler for the host machine: cc (gcc 9.4.0 "cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0")
C linker for the host machine: cc ld.bfd 2.34
Host machine cpu family: aarch64
Host machine cpu: aarch64
Compiler for C supports arguments -fvisibility=hidden: YES
Compiler for C supports arguments -fno-strict-aliasing: YES
Message: Disabling GLib cast checks
Message: Disabling deprecated GLib API
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Run-time dependency gstreamer-1.0 found: YES 1.16.3
Run-time dependency gstreamer-base-1.0 found: YES 1.16.3
Run-time dependency gstreamer-allocators-1.0 found: YES 1.16.3
Run-time dependency gstreamer-video-1.0 found: YES 1.16.3
Run-time dependency gstreamer-pbutils-1.0 found: YES 1.16.3
Run-time dependency glib-2.0 found: YES 2.64.6
Run-time dependency x11 found: YES 1.6.9
Run-time dependency libdrm found: YES 2.4.107
Run-time dependency rockchip_mpp found: YES 1.3.8
Found CMake: /usr/bin/cmake (3.16.3)
DEPRECATION: CMake support for versions <3.17 is deprecated since Meson 0.62.0.
|
|   However, Meson was only able to find CMake 3.16.3.
|
|   Support for all CMake versions below 3.17.0 will be removed once
|   newer CMake versions are more widely adopted. If you encounter
|   any errors please try upgrading CMake to a newer version first.

Run-time dependency librga found: NO (tried pkgconfig and cmake)
Header "gst/video/video-format.h" has symbol "GST_VIDEO_FORMAT_NV12_10LE40" with dependency gstreamer-video-1.0: YES
meson.build:107: DEPRECATION: configuration_data.set10 with number. the `set10` method should only be used with booleans
Configuring config.h using configuration
Program python3 found: YES (/usr/bin/python3)
WARNING: You should add the boolean check kwarg to the run_command call.
         It currently defaults to false,
         but it will default to true in future releases of meson.
         See also: https://github.com/mesonbuild/meson/issues/9300
Build targets in project: 3

Found ninja-1.10.0 at /usr/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
rock@rock-5b:~/mirrors$ cd build_dir/
rock@rock-5b:~/mirrors/build_dir$ ninja
[2/18] Compiling C object gst/rkximage/libgstrkximage.so.p/gstkmsutils.c.o
../gst/rkximage/gstkmsutils.c: In function 'gst_video_format_from_drm':
../gst/rkximage/gstkmsutils.c:79:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
   79 |   for (i = 0; i < G_N_ELEMENTS (format_map); i++) {
      |                 ^
../gst/rkximage/gstkmsutils.c: In function 'gst_drm_format_from_video':
../gst/rkximage/gstkmsutils.c:92:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
   92 |   for (i = 0; i < G_N_ELEMENTS (format_map); i++) {
      |                 ^
../gst/rkximage/gstkmsutils.c: In function 'gst_kms_sink_caps_template_fill':
../gst/rkximage/gstkmsutils.c:178:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
  178 |   for (i = 0; i < G_N_ELEMENTS (format_map); i++) {
      |                 ^
../gst/rkximage/gstkmsutils.c: In function 'gst_video_calculate_device_ratio':
../gst/rkximage/gstkmsutils.c:224:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
  224 |   for (i = 1; i < G_N_ELEMENTS (device_par_map); i++) {
      |                 ^
[7/18] Compiling C object gst/rkximage/libgstrkximage.so.p/gstkmsbufferpool.c.o
../gst/rkximage/gstkmsbufferpool.c: In function 'gst_kms_buffer_pool_get_options':
../gst/rkximage/gstkmsbufferpool.c:53:50: warning: unused parameter 'pool' [-Wunused-parameter]
   53 | gst_kms_buffer_pool_get_options (GstBufferPool * pool)
      |                                  ~~~~~~~~~~~~~~~~^~~~
../gst/rkximage/gstkmsbufferpool.c: In function 'gst_kms_buffer_pool_alloc_buffer':
../gst/rkximage/gstkmsbufferpool.c:134:34: warning: unused parameter 'params' [-Wunused-parameter]
  134 |     GstBufferPoolAcquireParams * params)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
[13/18] Compiling C object gst/rkximage/libgstrkximage.so.p/gstkmsallocator.c.o
../gst/rkximage/gstkmsallocator.c: In function 'gst_kms_memory_map':
../gst/rkximage/gstkmsallocator.c:347:44: warning: unused parameter 'maxsize' [-Wunused-parameter]
  347 | gst_kms_memory_map (GstMemory * mem, gsize maxsize, GstMapFlags flags)
      |                                      ~~~~~~^~~~~~~
../gst/rkximage/gstkmsallocator.c:347:65: warning: unused parameter 'flags' [-Wunused-parameter]
  347 | gst_kms_memory_map (GstMemory * mem, gsize maxsize, GstMapFlags flags)
      |                                                     ~~~~~~~~~~~~^~~~~
../gst/rkximage/gstkmsallocator.c: In function 'gst_kms_allocator_dmabuf_import':
../gst/rkximage/gstkmsallocator.c:605:12: warning: missing initializer for field 'pad' of 'struct drm_gem_close' [-Wmissing-field-initializers]
  605 |     struct drm_gem_close arg = { kmsmem->gem_handle[i], };
      |            ^~~~~~~~~~~~~
In file included from /usr/include/xf86drm.h:40,
                 from ../gst/rkximage/gstkmsallocator.c:31:
/usr/include/libdrm/drm.h:599:8: note: 'pad' declared here
  599 |  __u32 pad;
      |        ^~~
[17/18] Compiling C object gst/rkximage/libgstrkximage.so.p/ximagesink.c.o
../gst/rkximage/ximagesink.c: In function 'drm_plane_get_type':
../gst/rkximage/ximagesink.c:129:17: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  129 |   for (i = 0; i < props->count_props; i++) {
      |                 ^
../gst/rkximage/ximagesink.c: In function 'drm_find_plane_for_crtc_by_type':
../gst/rkximage/ximagesink.c:147:17: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  147 |     if (crtc_id == res->crtcs[i]) {
      |                 ^~
../gst/rkximage/ximagesink.c:156:17: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  156 |   for (i = 0; i < pres->count_planes; i++) {
      |                 ^
../gst/rkximage/ximagesink.c: In function 'drm_find_crtc_for_connector':
../gst/rkximage/ximagesink.c:200:19: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  200 |       if (crtc_id == crtc->crtc_id) {
      |                   ^~
../gst/rkximage/ximagesink.c: In function 'drm_find_used_connector_by_type':
../gst/rkximage/ximagesink.c:238:33: warning: comparison of integer expressions of different signedness: 'uint32_t' {aka 'unsigned int'} and 'int' [-Wsign-compare]
  238 |       if ((conn->connector_type == type)
      |                                 ^~
../gst/rkximage/ximagesink.c: In function 'drm_find_main_monitor':
../gst/rkximage/ximagesink.c:278:26: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
  278 |   for (i = 0; !conn && i < G_N_ELEMENTS (priority); i++)
      |                          ^
../gst/rkximage/ximagesink.c: In function 'check_afbc':
../gst/rkximage/ximagesink.c:377:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  377 |   for (i = 0; i < props->count_props && !value; i++) {
      |                 ^
../gst/rkximage/ximagesink.c:406:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and '__u32' {aka 'unsigned int'} [-Wsign-compare]
  406 |   for (i = 0; i < header->count_formats; i++) {
      |                 ^
../gst/rkximage/ximagesink.c:410:19: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and '__u32' {aka 'unsigned int'} [-Wsign-compare]
  410 |     for (j = 0; j < header->count_modifiers; j++) {
      |                   ^
../gst/rkximage/ximagesink.c:413:14: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and '__u32' {aka 'unsigned int'} [-Wsign-compare]
  413 |       if ((i < mod->offset) || (i > mod->offset + 63))
      |              ^
../gst/rkximage/ximagesink.c:413:35: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and '__u32' {aka 'unsigned int'} [-Wsign-compare]
  413 |       if ((i < mod->offset) || (i > mod->offset + 63))
      |                                   ^
../gst/rkximage/ximagesink.c: In function 'drm_ensure_allowed_caps':
../gst/rkximage/ximagesink.c:444:17: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  444 |   for (i = 0; i < plane->count_formats; i++) {
      |                 ^
../gst/rkximage/ximagesink.c: In function 'drm_plane_set_property':
../gst/rkximage/ximagesink.c:508:17: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
  508 |   for (i = 0; i < props->count_props; i++) {
      |                 ^
../gst/rkximage/ximagesink.c: In function 'sync_handler':
../gst/rkximage/ximagesink.c:882:20: warning: unused parameter 'fd' [-Wunused-parameter]
  882 | sync_handler (gint fd, guint frame, guint sec, guint usec, gpointer data)
      |               ~~~~~^~
../gst/rkximage/ximagesink.c:882:30: warning: unused parameter 'frame' [-Wunused-parameter]
  882 | sync_handler (gint fd, guint frame, guint sec, guint usec, gpointer data)
      |                        ~~~~~~^~~~~
../gst/rkximage/ximagesink.c:882:43: warning: unused parameter 'sec' [-Wunused-parameter]
  882 | sync_handler (gint fd, guint frame, guint sec, guint usec, gpointer data)
      |                                     ~~~~~~^~~
../gst/rkximage/ximagesink.c:882:54: warning: unused parameter 'usec' [-Wunused-parameter]
  882 | sync_handler (gint fd, guint frame, guint sec, guint usec, gpointer data)
      |                                                ~~~~~~^~~~
[18/18] Linking target gst/rkximage/libgstrkximage.so

reinstalling meson with sudo here to be able to install as sudo

rock@rock-5b:~/mirrors/build_dir$ sudo pip3 install meson
Collecting meson
  Downloading meson-1.1.0-py3-none-any.whl (916 kB)
     |████████████████████████████████| 916 kB 2.4 MB/s
Installing collected packages: meson
Successfully installed meson-1.1.0

rock@rock-5b:~/mirrors/build_dir$ sudo meson install
Dropping privileges to 'rock' before running ninja...
ninja: Entering directory `/home/rock/mirrors/build_dir'
ninja: no work to do.
Installing gst/rkximage/libgstrkximage.so to /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0
Installing gst/rockchipmpp/libgstrockchipmpp.so to /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0
Installing gst/kmssrc/libgstkmssrc.so to /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0

testing

rock@rock-5b:~/mirrors/build_dir$ gst-inspect-1.0| grep mpp
typefindfunctions: audio/x-musepack: mpc, mpp, mp+

Maybe /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0 is a wrong path ? there is only gstreamer-rockship libs there after the install.

Thanks

Path: /usr/lib/aarch64-linux-gnu/gstreamer-1.0/

1 Like

Thanks

Moving libs :

rock@rock-5b:~/gst-rtsp-server/examples$ sudo cp -r /usr/local/lib/aarch64-linux-gnu/* /usr/lib/aarch64-linux-gnu/

testing :

rock@rock-5b:~/gst-rtsp-server/examples$ gst-inspect-1.0| grep mpp              rockchipmpp:  mppjpegdec: Rockchip's MPP JPEG image decoder
rockchipmpp:  mppvideodec: Rockchip's MPP video decoder
rockchipmpp:  mppjpegenc: Rockchip Mpp JPEG Encoder
rockchipmpp:  mppvp8enc: Rockchip Mpp VP8 Encoder
rockchipmpp:  mpph265enc: Rockchip Mpp H265 Encoder
rockchipmpp:  mpph264enc: Rockchip Mpp H264 Encoder
typefindfunctions: audio/x-musepack: mpc, mpp, mp+

Encoder is now found, but :

rock@rock-5b:~/gst-rtsp-server/examples$ gst-launch-1.0 --verbose  videotestsrc ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! videoconvert ! mpph264enc ! fakesink sync=false
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = video/x-raw, format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = video/x-raw, format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = video/x-raw, format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
Caught SIGSEGV
/GstPipeline:pipeline0/GstMppH264Enc:mpph264enc0.GstPad:src: caps = video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)High, level=(string)4, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)High, level=(string)4, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-site=(string)mpeg2, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono
/GstPipeline:pipeline0/GstMppH264Enc:mpph264enc0.GstPad:sink: caps = video/x-raw, format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = video/x-raw, format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = video/x-raw, format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
exec gdb failed: No such file or directory
Segmentation fault

Any idea ? Could it be “Run-time dependency librga found: NO (tried pkgconfig and cmake)” shown on meson build dir ?

thanks

Yes.
BTW you don’t need videoconvert (it is implicit).

gst-launch-1.0 --verbose videotestsrc ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! mpph264enc ! fakesink sync=false

Good luck.

Update:
You you want to go this route, read here what you need:
(IMX415 + NPU demo on ROCK 5B)
, or use Jiangfeng Liu’s ppa on Ubuntu 22.04, but i think only Wayland.

1 Like

Thanks,

I was trying to install librga by copying libs found in https://github.com/airockchip/librga/tree/main/libs/Linux/gcc-aarch64 to different directories (/libs, /usr/libs etc) but it’s still not found at meson build dir (Run-time dependency librga found: NO (tried pkgconfig and cmake))
Do you know where I should copy them ?

If I still can install them this way I will test your link tomorow, thanks.

Hi

Using your link IMX415 + NPU demo on ROCK 5B and some additional install from https://ubuntu.pkgs.org/20.04/ubuntu-updates-main-arm64/ I managed to make it work. (was not so easy…)
I can now use hardware encoding on gstreamer.

Thanks for your help !

Hi,

I’m glad to hear that you’ve successfully resolved the hardware encoding issue and got it working with GStreamer. Hardware encoding can significantly improve video processing performance and make video stream processing more efficient.

Based on your description, it sounds like you managed to solve the problem by installing the IMX415 + NPU demo and some additional packages from the Ubuntu software repository. This likely involves certain libraries and tools related to GStreamer and hardware acceleration. However, since the information you provided is relatively limited, I’m unable to provide a more detailed solution.

If you’re interested, you could provide more specific steps, package names, or details about the installation process. This would help other users reference and solve similar issues more effectively.

In any case, I’m glad you’ve successfully resolved the problem. If you have any further questions or need more assistance, feel free to ask.