已关闭
通过priv_data传递用户自定义数据会导致解码器打开失败 #366
沿江笑笑创建于  7月24日关闭于  7月28日
沿江笑笑
沿江笑笑
7月24日 创建

该问题是怎么引起的?

服务器信息:Kunpeng-920的CPU,Atlas 300I Duo的加速卡,Ubuntu22.04操作系统
NPU驱动版本 25.2.0,CANN版本是 8.3.RC1

ascend ffmpeg库编译方式:参照https://gitcode.com/Ascend/mindsdk-referenceapps/blob/master/VisionSDK/Ascendffmpeg/README.md

我的程序基于ascend ffmpeg库封装了一个视频解码器的类AscendVideoDecoder,在不指定device_id、channel_id时(取默认值0、0),解码器能正常运行;
但是,当我按照https://gitcode.com/Ascend/mindsdk-referenceapps/blob/master/VisionSDK/Ascendffmpeg/dec_h26x_ascend.md方式传递自定义的device_id、channel_id时,解码器打开失败,gdb错误日志在 ascend ffmpeg库内部。

传递自定义device_id、channel_id代码如下:
`AVCodecContext *codec_ctx;
codec_ctx = avcodec_alloc_context3(dec);

codec_ctx->get_format = get_hw_format;

ascend_ctx = (ASCENDContext_t*)av_malloc(sizeof(ASCENDContext_t));
ascend_ctx->device_id = device_id; // 用户可自定义修改
ascend_ctx->channel_id = channel_id // 用户可自定义修改
codec_ctx->priv_data = ascend_ctx;
hw_decoder_init(codec_ctx)

AVDictionary* opts = NULL;
av_dict_set(&opts, "extra_hw_frames", "3", 0);
avcodec_open2(codec_ctx, dec, &opts)`

重现步骤

创建解码器时,程序报段错误。

报错信息

gdb报错日志截图如下截屏2026-07-24 17.54.14.png

likedislike
xiangjie10成员
7月24日 评论:

👋 您好,感谢向 mindsdk-referenceapps 提交 Issue!
🎉 我们已收到您的反馈,感谢你对开源社区的支持!

📅 处理时效 维护团队将在工作日 24 小时内查看并回复您的问题。
🔍 自助排查(推荐优先查看) 在等待回复期间,您可以先查阅仓库README以及历史 Issue 中相似问题的解决方案,多数问题可快速解决。
💡 为了更快定位问题,请您确保 Issue 包含:

  • 清晰的问题描述
  • 可复现的操作步骤
  • 相关日志、截图或环境信息
    我们会尽快跟进,感谢您的理解与配合!
likedislike
xiangjie10成员
7月24日 评论:

/label add triaged

likedislike
ascend-robotascend-robot成员
7月24日 添加了label:triaged
沿江笑笑沿江笑笑
7月24日 修改了issue 的描述
沿江笑笑沿江笑笑
7月24日 修改了issue 的描述
沿江笑笑沿江笑笑
7月27日 修改了issue 的描述
沿江笑笑沿江笑笑
7月27日 修改了issue 的描述
沿江笑笑
沿江笑笑
7月28日 评论:

我找到解决办法了,可以通过如下方式传递自定义的device_id、channel_id

aclrtSetDevice(target_device_id);

av_dict_set(&opts, "channel_id", std::to_string(channel_id).c_str(), 0);

likedislike
蒋立成员
7月28日 评论:

/lable add resolved

likedislike
Yyihao1234成员
7月28日 issue状态由 TODO 改变为 DONE
Yyihao1234成员
7月28日 关闭了 issue