在rk3588平台快速使用硬件编解码功能

在rk3588平台快速使用硬件编解码功能 毛巾卷 2023-12-28 08:37:46 2470

在rv1126/rv1109等平台,rk提供的是使用rkmedia来进行视频硬件编解码的功能,它会使用到底层的rkmpp和rga来实现对硬件编解码加速,而在rk3588平台(rk3568应该也支持)则没有这个rkmedia这套框架,如果我们要使用硬件编解码、图像处理加速等功能就需要从rkmpp、rga等来实现,对于不熟悉这一套的人来说会比较麻烦,学习成本也比较高,好在rk原厂在ffmpeg和gstreamer这两个上面做了支持,我们可以通过这两个开源的音视频处理库来实现对硬件编解码的调用,今天我要介绍的就是在rk3588平台通过gstreamer来实现硬件编解码的使用。

GStreamer是一个开源的多媒体框架,用于构建流媒体应用程序和处理音频、视频、图像和其他媒体数据。它提供了一组库和插件,可以用来创建、编辑、播放和流式传输多媒体内容。GStreamer支持多种编解码器、容器格式和协议,可以在不同的平台上运行,包括Linux、Windows和macOS。它是一个灵活且功能丰富的工具,被广泛用于视频编辑、音频处理、流媒体服务器和嵌入式设备等领域。

rk官方也提供了参考文档, 《Rockchip_User_Guide_Linux_Gstreamer_CN.pdf》

关于rv平台没有对gstreamer支持我个人感觉可能是gstreamer的包本身比较大吧,在rv平台本身更精简一点,所以直接用了rkmedia这一套来讲效率更高,而rk3588平台cpu足够强悍,这点问题来讲就不是问题了,也方便用户快速验证开发,有需要的再转到mpp去,减少调用。

一般我们拿到手的rk3588板子里面文件系统就已经预装了gstreamer以及rk的插件的,没有的话可以去sdk里面找,这一部分rk也开源了源码在sdk里面有。

rk3588平台在gstreamer上面主要做了如下几个插件。

orangepi@orangepi5:~$ 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+

我们通过 gst-inspect-1.0 命令来查阅使用手册

orangepi@orangepi5:~$ gst-inspect-1.0 mpph264enc
mpp_info: mpp version: unknown mpp version for missing VCS info
mpp_info: mpp version: unknown mpp version for missing VCS info
mpp_info: mpp version: unknown mpp version for missing VCS info
mpp_info: mpp version: unknown mpp version for missing VCS info
Factory Details:
  Rank                     primary + 1 (257)
  Long-name                Rockchip Mpp H264 Encoder
  Klass                    Codec/Encoder/Video
  Description              Encode video streams via Rockchip Mpp
  Author                   Randy Li <randy.li@rock-chips.com>, Jeffy Chen <jeffy.chen@rock-chips.com>

Plugin Details:
  Name                     rockchipmpp
  Description              Rockchip Mpp Video Plugin
  Filename                 /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstrockchipmpp.so
  Version                  1.14.4
  License                  LGPL
  Source module            gst-rockchip
  Binary package           GStreamer Rockchip Plug-ins
  Origin URL               Unknown package origin

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstVideoEncoder
                         +----GstMppEnc
                               +----GstMppH264Enc

Implemented Interfaces:
  GstPreset

Pad Templates:
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      video/x-raw
                 format: { (string)NV12, (string)I420, (string)YUY2, (string)UYVY, (string)BGR16, (string)RGB16, (string)ABGR, (string)ARGB, (string)BGRA, (string)RGBA, (string)xBGR, (string)xRGB, (string)BGRx, (string)RGBx, (string)NV12, (string)NV21, (string)I420, (string)YV12, (string)NV16, (string)NV61, (string)BGR16, (string)RGB, (string)BGR, (string)RGBA, (string)BGRA, (string)RGBx, (string)BGRx }
                  width: [ 96, 2147483647 ]
                 height: [ 64, 2147483647 ]

  SRC template: 'src'
    Availability: Always
    Capabilities:
      video/x-h264
                  width: [ 96, 2147483647 ]
                 height: [ 64, 2147483647 ]
          stream-format: { (string)byte-stream }
              alignment: { (string)au }
                profile: { (string)baseline, (string)main, (string)high }

Element has no clocking capabilities.
Element has no URI handling capabilities.

Pads:
  SINK: 'sink'
    Pad Template: 'sink'
  SRC: 'src'
    Pad Template: 'src'

Element Properties:
  bps                 : Target BPS (0 = auto calculate)
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 2147483647 Default: 0
  bps-max             : Max BPS (0 = auto calculate)
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 2147483647 Default: 0
  bps-min             : Min BPS (0 = auto calculate)
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 2147483647 Default: 0
  gop                 : Group of pictures starting with I frame (-1 = FPS, 1 = all I frames)
                        flags: readable, writable
                        Integer. Range: -1 - 2147483647 Default: -1
  header-mode         : Header mode
                        flags: readable, writable
                        Enum "MppEncHeaderMode" Default: 0, "first-frame"
                           (0): first-frame      - Only in the first frame
                           (1): each-idr         - In every IDR frames
  level               : H264 level (40~41 = 1080p@30fps, 42 = 1080p60fps, 50~52 = 4K@30fps)
                        flags: readable, writable
                        Enum "GstMppH264Level" Default: 40, "4"
                           (10): 1                - 1
                           (99): 1b               - 1b
                           (11): 1.1              - 1.1
                           (12): 1.2              - 1.2
                           (13): 1.3              - 1.3
                           (20): 2                - 2
                           (21): 2.1              - 2.1
                           (22): 2.2              - 2.2
                           (30): 3                - 3
                           (31): 3.1              - 3.1
                           (32): 3.2              - 3.2
                           (40): 4                - 4
                           (41): 4.1              - 4.1
                           (42): 4.2              - 4.2
                           (50): 5                - 5
                           (51): 5.1              - 5.1
                           (52): 5.2              - 5.2
                           (60): 6                - 6
                           (61): 6.1              - 6.1
                           (62): 6.2              - 6.2
  max-reenc           : Max re-encode times for one frame
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 3 Default: 1
  name                : The name of the object
                        flags: readable, writable
                        String. Default: "mpph264enc0"
  parent              : The parent of the object
                        flags: readable, writable
                        Object of type "GstObject"
  profile             : H264 profile
                        flags: readable, writable
                        Enum "GstMppH264Profile" Default: 100, "high"
                           (66): baseline         - Baseline
                           (77): main             - Main
                           (100): high             - High
  qos                 : Handle Quality-of-Service events from downstream
                        flags: readable, writable
                        Boolean. Default: false
  qp-init             : Initial QP (lower value means higher quality)
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 51 Default: 26
  qp-max              : Max QP (0 = default)
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 51 Default: 0
  qp-max-step         : Max delta QP step between two frames (-1 = default)
                        flags: readable, writable
                        Integer. Range: -1 - 51 Default: -1
  qp-min              : Min QP (0 = default)
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 51 Default: 0
  rc-mode             : RC mode
                        flags: readable, writable
                        Enum "GstMppEncRcMode" Default: 1, "cbr"
                           (0): vbr              - Variable bitrate
                           (1): cbr              - Constant bitrate
                           (2): fixqp            - Fixed QP
  sei-mode            : SEI mode
                        flags: readable, writable
                        Enum "GstMppEncSeiMode" Default: 0, "disable"
                           (0): disable          - SEI disabled
                           (1): one-seq          - One SEI per sequence
                           (2): one-frame        - One SEI per frame(if changed)
  zero-copy-pkt       : Zero-copy encoded packet
                        flags: readable, writable
                        Boolean. Default: true

接下来演示一下如何使用。

gst-launch-1.0 videotestsrc ! x264enc ! filesink location=2.h264
gst-launch-1.0 videotestsrc ! mpph264enc ! filesink location=1.h264

可以看到,我们使用mpph264enc来进行硬件编码时会比使用x264enc软件编码时对cpu的占用率低很多。

好啦,这篇就讲到这里,点到即止,更多的使用方法大家可以看rk的文档还有gstreamer官方的教程。

gstreamer官方教程:https://gstreamer.freedesktop.org/documentation/tutorials/index.html?gi-language=c

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 3 1 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
毛巾卷
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区