[视频编码]rkmpp 实现硬件编码

mpi_enc_test的命令参数描述说明

命令参数的描述说明如下:

命令参数

描述说明

-i

输入的图像文件。

-o

输出的码流文件。

-w

图像宽度,单位为像素。

-h

图像高度,单位为像素。

-hstride

垂直方向相邻两行之间的距离,单位为byte。

-vstride

图像分量之间的以行数间隔数,单位为1。

-f

图像色彩空间格式以及内存排布方式,默认为NV12。

-t

码流文件的协议类型。

-tsrc

源码流格式,仅在测试整体编解码性能时使用。

-n

最大解码帧数。测试时若码流较长,可仅输出前n帧。

-g

gop参考模式,对应不同的TSVC码流。

-rc

码率控制模式。0:VBR; 1:CBR; 2:FIXQP; 3:AVBR。

-bps

码率约束参数。命令格式:bps_target:bps_min:bps_max。

-fps

输入/输出帧率控制,默认为30。该命令参数仅说明输入帧率和输出帧率之间的比例关系,与实际帧率无关。

-qc

质量控制。

-s

MPP实例数,默认为1。

-v

日志选项:q为静默标志;f为fps显示标志。

-ini

额外的编码配置文件ini(暂未生效)。

-slt

输出码流对应的校验文件。

查看摄像头的图片格式


cat@lubancat:~/test/mpp/build/linux/aarch64/test$ v4l2-ctl -d /dev/video1 --all
Driver Info:
        Driver name      : uvcvideo
        Card type        : YJX-YL7: YJX-YL7
        Bus info         : usb-xhci-hcd.9.auto-1
        Driver version   : 5.10.160
        Capabilities     : 0x84a00001
                Video Capture
                Metadata Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Media Driver Info:
        Driver name      : uvcvideo
        Model            : YJX-YL7: YJX-YL7
        Serial           : 20240514001
        Bus info         : usb-xhci-hcd.9.auto-1
        Media version    : 5.10.160
        Hardware revision: 0x00000001 (1)
        Driver version   : 5.10.160
Interface Info:
        ID               : 0x03000002
        Type             : V4L Video
Entity Info:
        ID               : 0x00000001 (1)
        Name             : YJX-YL7: YJX-YL7
        Function         : V4L2 I/O
        Flags         : default
        Pad 0x01000007   : 0: Sink
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
        Width/Height      : 1280/720
        Pixel Format      : 'YUYV' (YUYV 4:2:2)
        Field             : None
        Bytes per Line    : 2560
        Size Image        : 1843200
        Colorspace        : sRGB
        Transfer Function : Rec. 709
        YCbCr/HSV Encoding: ITU-R 601
        Quantization      : Default (maps to Limited Range)
        Flags             : 
Crop Capability Video Capture:
        Bounds      : Left 0, Top 0, Width 1280, Height 720
        Default     : Left 0, Top 0, Width 1280, Height 720
        Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 1280, Height 720, Flags: 
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1280, Height 720, Flags: 
Streaming Parameters Video Capture:
        Capabilities     : timeperframe
        Frames per second: 10.000 (10/1)
        Read buffers     : 0
                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=45 value=45
                     saturation 0x00980902 (int)    : min=0 max=100 step=1 default=70 value=70
                            hue 0x00980903 (int)    : min=-180 max=180 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=90 max=150 step=1 default=120 value=120
                           gain 0x00980913 (int)    : min=0 max=128 step=1 default=75 value=75
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1
                                0: Disabled
                                1: 50 Hz
                                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=10 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=7 step=1 default=6 value=6
         backlight_compensation 0x0098091c (int)    : min=0 max=2 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
                                1: Manual Mode
                                3: Aperture Priority Mode
              exposure_absolute 0x009a0902 (int)    : min=2 max=1250 step=1 default=156 value=156 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=1

捕获为h264

cat@lubancat:~/test/mpp/build/linux/aarch64/test$ mpi_enc_test -w 1280 -h 720 -t 7 -f 8  -fps 15 -i /dev/video1 -o ./out.h624
注意这里命令-i是可以输入文件,或者是摄像头结点的。很多文章没有说明

    if (cmd->file_input) {
        if (!strncmp(cmd->file_input, "/dev/video", 10)) {
            mpp_log("open camera device");
            p->cam_ctx = camera_source_init(cmd->file_input, 4, p->width, p->height, p->fmt);
            mpp_log("new framecap ok");
            if (p->cam_ctx == NULL)
                mpp_err("open %s fail", cmd->file_input);
        } else {
            p->fp_input = fopen(cmd->file_input, "rb");
            if (NULL == p->fp_input) {
                mpp_err("failed to open input file %s\n", cmd->file_input);
                mpp_err("create default yuv image for test\n");
            }
        }
    }

查看rkmpp日志

cat@lubancat:~$ sudo tail -f /var/log/syslog

Mar  8 23:37:58 lubancat mpp[136462]: mpp_opt: setup:real node 67:71 info 22:22
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: cmd parse result:
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: input  file name: /dev/video1
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: output file name: ./out.h624
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: width      : 1280
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: height     : 720
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: format     : 8
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_utils: type       : 7
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_test: mpi_enc_test start
Mar  8 23:37:58 lubancat mpp[136462]: mpi_enc_test: open camera device
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: input devices:Camera 1
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: fmt name: [Motion-JPEG]
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: fmt pixelformat: 'MJPG', description = 'Motion-JPEG'
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: fmt name: [YUYV 4:2:2]
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: fmt pixelformat: 'YUYV', description = 'YUYV 4:2:2'
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: get width 1280 height 720
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: get dma buf(0)-fd: 13
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: get dma buf(1)-fd: 14
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: get dma buf(2)-fd: 15
Mar  8 23:37:59 lubancat mpp[136462]: camera_source: get dma buf(3)-fd: 16
Mar  8 23:37:59 lubancat mpp[136462]: mpi_enc_test: new framecap ok
Mar  8 23:37:59 lubancat mpp[136462]: mpp_info: mpp version: ed377c99 author: Herman Chen   2023-12-14 fix[hal_enc]: Add encoder internal buffer sync
Mar  8 23:37:59 lubancat mpp[136462]: mpi_enc_test: 0x7f84002580 encoder test start w 1280 h 720 type 7
Mar  8 23:37:59 lubancat mpp[136462]: mpp_enc: MPP_ENC_SET_RC_CFG bps 1728000 [108000 : 1836000] fps [15:15] gop 30
Mar  8 23:37:59 lubancat mpp[136462]: h264e_api_v2: MPP_ENC_SET_PREP_CFG w:h [1280:720] stride [2560:720]
Mar  8 23:37:59 lubancat mpp[136462]: mpp_enc: mode vbr bps [108000:1728000:1836000] fps fix [15/1] -> fix [15/1] gop i [30] v [0]
Mar  8 23:38:04 lubancat kernel: [ 2463.954669] mpp_rkvenc2 fdbd0000.rkvenc-core: can not activate fdbd0000.rkvenc-core -> fdbd0000.rkvenc-core
Mar  8 23:38:04 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 0    size 54707   qp 23
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 1    size 12631   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 2    size 13025   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 3    size 12888   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 4    size 11955   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 5    size 11493   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 6    size 11581   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 7    size 11782   qp 26
Mar  8 23:38:05 lubancat mpp[136462]: mpi_enc_test: chn 0 encoded frame 8    size 12097   qp 26

播放h264的命令


root@lubancat:/home/cat# mpv out.h624 
[lavf] This format is marked by FFmpeg as having no timestamps!
[lavf] FFmpeg will likely make up its own broken timestamps. For
[lavf] video streams you can correct this with:
[lavf]     --no-correct-pts --fps=VALUE
[lavf] with VALUE being the real framerate of the stream. You can
[lavf] expect seeking and buffering estimation to be generally
[lavf] broken as well.
 (+) Video --vid=1 (h264 1280x720 15.000fps)
[vo/xv] Warning: this legacy VO has bad quality and performance, and will in particular result in blurry OSD and subtitles. You should fix your graphics drivers, or not force the xv VO.
Using hardware decoding (rkmpp).
No video PTS! Making something up. Using 15.000000 FPS.
[autoconvert] HW-downloading from drm_prime
[autoconvert] Converting nv12 -> yuv420p
No video PTS! Making something up. Using 15.000000 FPS.
Ignoring further missing PTS warnings.
VO: [xv] 1280x720 yuv420p
V: 00:00:03 / unknown (98%)


Exiting... (End of file)

### H264_RKMPP 编码使用方法 对于H264_RKMPP编码器,在Rockchip平台上的实现主要依赖于硬件加速特性来提升视频压缩效率和性能。该编解码库提供了简单易用的应用编程接口(API),允许开发者通过调用特定函数完成初始化设置、帧数据输入以及获取已编码比特流等功能[^1]。 具体来说,为了启动编码过程,应用程序需先创建并配置编码上下文对象,指定目标分辨率、帧率等参数;之后循环向此实例提交待处理图像直至结束;最后释放资源以终止会话。下面给出一段Python伪代码用于演示基本流程: ```python import rkmpp # 假设存在这样一个封装模块 def encode_video(input_frames, output_file='output.h264'): encoder = rkmpp.Encoder() config = { 'width': input_frames.width, 'height': input_frames.height, 'framerate': 30, 'bitrate': 8 * 1024 * 1024 # 8 Mbps } encoder.configure(config) with open(output_file, 'wb') as f: for frame in input_frames: encoded_data = encoder.encode(frame) f.write(encoded_data) encoder.finish() # Flush remaining frames and close the stream properly. ``` ### 常见问题解决方案 当遇到与H264_RKMPP有关的问题时,可以考虑以下几个方面来进行排查和修复: - **设备兼容性**:确认所使用的SoC型号支持RKMPP API版本,并安装了最新的固件更新。 - **环境变量缺失**:确保设置了必要的环境变量指向正确的驱动路径和其他依赖项位置。 - **内存不足错误**:适当调整分配给编码任务的工作缓冲区大小或者降低视频质量设定以减少所需空间占用量。 - **同步机制失效**:检查程序逻辑是否存在竞态条件或死锁现象影响到多线程间协作正常运作的情况发生。 - **日志记录不充分**:增强调试信息输出级别以便更好地理解内部状态变化原因所在,从而快速定位潜在缺陷根源所在之处。 以上措施有助于提高开发过程中解决问题的能力,同时也促进了更稳定高效的多媒体应用构建工作进展顺利进行下去[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值