Charley王大王

Charley王大王

0个粉丝

3

问答

0

专栏

0

资料

Charley王大王  发布于  2026-01-16 19:29:07
采纳率 0%
3个问答
93

调用ss_mpi_venc_create_chn接口,报错0xa0088007。参数非法

   
#include <stdio.h>
#include <string.h>
#include "ot_common.h"
#include "ot_common_venc.h"
#include "ss_mpi_vb.h"
#include "ss_mpi_sys.h"
#include "ss_mpi_venc.h"

#define OT_ALIGN_UP(x, a)           ((((x) + ((a) - 1)) / (a)) * (a))

// 创建1920x1080 H264编码通道的示例
int create_1080p_h264_venc_channel(void)
{
    td_s32 ret;

    printf("=== 1920x1080 H264 VENC Channel Creation ===\n");

    // 1. 初始化VB (Video Buffer) - 1920x1080需要更大的buffer
    printf("Step 1: Initialize VB...\n");
    ot_vb_cfg vb_cfg = {0};
    vb_cfg.max_pool_cnt = 1;

    // 计算1920x1080 YUV420一帧的大小: 1920*1080*1.5 = 3,110,400字节 ≈ 3.1MB
    // 建议设置稍大一些,比如4MB,并增加块数量
    vb_cfg.common_pool[0].blk_size = 1920 * 1080 * 3 / 2 * 3 / 2;  // 约4.5MB
    vb_cfg.common_pool[0].blk_cnt = 4;  // 4个块

    ret = ss_mpi_vb_set_cfg(&vb_cfg);
    if (ret != TD_SUCCESS) {
        printf("VB SetCfg failed: 0x%x\n", ret);
        return ret;
    }

    ret = ss_mpi_vb_init();
    if (ret != TD_SUCCESS) {
        printf("VB Init failed: 0x%x\n", ret);
        return ret;
    }

    // 2. 初始化系统
    printf("Step 2: Initialize SYS...\n");
    ret = ss_mpi_sys_init();
    if (ret != TD_SUCCESS) {
        printf("SYS Init failed: 0x%x\n", ret);
        ss_mpi_vb_exit();
        return ret;
    }

    // 3. 配置编码通道属性
    printf("Step 3: Configure channel attributes...\n");
    ot_venc_chn_attr chn_attr = {0};

    // 3.1 设置编码基本属性
    chn_attr.venc_attr.type = OT_PT_H264;            // H.264编码
    chn_attr.venc_attr.max_pic_width = 1920;         // 最大宽度
    chn_attr.venc_attr.max_pic_height = 1080;        // 最大高度
    chn_attr.venc_attr.pic_width = 1920;             // 实际宽度
    chn_attr.venc_attr.pic_height = 1080;            // 实际高度
    chn_attr.venc_attr.is_by_frame = TD_TRUE;


    // 计算缓冲区大小 (YUV420: width * height * 1.5)
    // 对于1920x1080: 1920*1080*1.5 = 3,110,400字节
    // 建议设置稍大一些,并考虑编码开销
    chn_attr.venc_attr.buf_size = OT_ALIGN_UP(1920 * 1080 * 3 / 4, 64);

    // 设置profile (0: baseline, 1: main, 2: high)
    // 1080p通常使用main或high profile
    chn_attr.venc_attr.profile = 1;  // main profile

    // 按帧获取码流
    chn_attr.venc_attr.is_by_frame = TD_TRUE;

    // 设置H.264特有属性
    chn_attr.venc_attr.h264_attr.rcn_ref_share_buf_en = TD_FALSE;  // 不启用共享缓冲区
    chn_attr.venc_attr.h264_attr.frame_buf_ratio = 70;              // 使用默认值

    // 3.2 设置码率控制属性 - CBR模式
    chn_attr.rc_attr.rc_mode = OT_VENC_RC_MODE_H264_CBR;
    // 填充CBR参数
    chn_attr.rc_attr.h264_cbr.gop = 30;               // I帧间隔 (30帧一个I帧)
    chn_attr.rc_attr.h264_cbr.stats_time = 1;         // 统计时间(秒)
    chn_attr.rc_attr.h264_cbr.src_frame_rate = 30;    // 输入帧率
    chn_attr.rc_attr.h264_cbr.dst_frame_rate = 30;    // 输出帧率
    chn_attr.rc_attr.h264_cbr.bit_rate = 4000;        // 码率 4Mbps (对于1080p30比较合理)

    // 3.3 设置GOP属性 - NORMAL_P模式
    chn_attr.gop_attr.gop_mode = OT_VENC_GOP_MODE_NORMAL_P;
    chn_attr.gop_attr.normal_p.ip_qp_delta = -2;      // I帧QP比P帧小2 (I帧质量更好)

    // 打印配置信息
    printf("\nChannel Configuration:\n");
    printf("  Resolution:     %dx%d\n", chn_attr.venc_attr.pic_width, chn_attr.venc_attr.pic_height);
    printf("  Codec:          H.264\n");
    printf("  Profile:        %s\n", chn_attr.venc_attr.profile == 0 ? "Baseline" : 
                                     chn_attr.venc_attr.profile == 1 ? "Main" : "High");
    printf("  Bitrate:        %d Kbps\n", chn_attr.rc_attr.h264_cbr.bit_rate);
    printf("  Frame rate:     %d fps\n", chn_attr.rc_attr.h264_cbr.dst_frame_rate);
    printf("  GOP:            %d\n", chn_attr.rc_attr.h264_cbr.gop);
    printf("  GOP Mode:       NORMAL_P\n");
    printf("  I/P QP Delta:   %d\n", chn_attr.gop_attr.normal_p.ip_qp_delta);
    printf("  Buffer Size:    %u bytes\n", chn_attr.venc_attr.buf_size);

    // 4. 创建编码通道 (通道号0)
    printf("\nStep 4: Creating VENC channel 0...\n");
    ret = ss_mpi_venc_create_chn(0, &chn_attr);

    if (ret == TD_SUCCESS) {
        printf("✓ SUCCESS: VENC channel 0 created successfully!\n");

        // 5. 这里可以进行编码操作...
        printf("  Channel is ready for encoding\n");
        printf("  You can now send frames and get encoded streams\n");

        // 示例:保持通道一段时间,然后销毁
        printf("\nWaiting 2 seconds (simulating encoding)...\n");
        sleep(2);

        // 6. 销毁通道
        printf("Step 5: Destroying channel...\n");
        ss_mpi_venc_destroy_chn(0);
        printf("✓ Channel destroyed\n");
    } else {
        printf("✗ FAILED: VENC create failed with error: 0x%x\n", ret);

        // 错误码解析
        if (ret == 0xa0088007) {
            printf("  Error: OT_ERR_VENC_ILLEGAL_PARAM (Illegal parameter)\n");
            printf("  Possible issues:\n");
            printf("    1. Buffer size too small for 1080p\n");
            printf("    2. Unsupported resolution or profile\n");
            printf("    3. Invalid bitrate value\n");
        }
    }

    // 7. 清理系统资源
    printf("\nStep 6: Cleaning up system resources...\n");
    ss_mpi_sys_exit();
    ss_mpi_vb_exit();
    printf("✓ System resources released\n");

    return ret;
}


int main(int argc, char *argv[])
{
    printf("=== H264 1080p Encoder Test ===\n");

    // 运行示例
    td_s32 ret = create_1080p_h264_venc_channel();

    if (ret == TD_SUCCESS) {
        printf("\n=== TEST PASSED ===\n");
    } else {
        printf("\n=== TEST FAILED ===\n");
    }

    return (ret == TD_SUCCESS) ? 0 : 1;
}

请帮忙看看

我来回答
回答3个
时间排序
认可量排序

UncleRoderick

61个粉丝

18

问答

4

专栏

20

资料

UncleRoderick 2026-01-18 14:26:32
认可1

cat /dev/logmpp看看报错信息

Charley王大王
Charley王大王   回复   UncleRoderick  2026-01-19 16:18:49
0

上面这份代码是可以运行的,出错的原因很可能是跟别的程序起了冲突。

UncleRoderick
UncleRoderick   回复   Charley王大王  2026-01-19 17:14:08
1

那你也要发/dev/logmpp的信息才能分析呀

或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
相关问答
无更多相似问答 去提问
举报反馈

举报类型

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

详细说明

易百纳技术社区