You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ZEGOCLOUD Express SDK自定义预处理接入美颜后预览推流全黑求助

问题排查与修复方案

从你提供的代码来看,有几个关键问题会导致预览/推流画面全黑,逐一梳理:

  1. 注解拼写错误导致回调失效
    onStop方法的注解写成了@override(小写o),Java中正确的注解是@Override(大写O)。这个错误会导致onStop无法被SDK正确回调,不仅美颜环境无法正常释放,还可能让SDK判定回调签名异常,中断整个自定义处理流程。

  2. 美颜初始化宽高硬编码不匹配
    你在onStart中硬编码了effects.initEnv(720, 1280),但实际摄像头采集的分辨率可能和这个值不匹配(比如竖屏场景下常见的1280x720)。美颜初始化的分辨率如果和采集画面不一致,会直接导致纹理处理失败,返回无效的纹理ID,最终画面全黑。

  3. 日志语法错误无法排查问题
    onCapturedUnprocessedTextureData中的Log.i调用里,tag和msg之间用了点.而非逗号,,这会导致编译错误(如果代码能运行说明是笔误),但会让你无法打印关键日志,无法确认是否进入了回调、采集到的纹理ID是否有效。

  4. 视频帧参数不完整
    你只给effectsVideoFrameParam设置了宽高,但美颜SDK通常需要更多必要参数(比如纹理类型、像素格式、旋转角度等),参数不全会导致processTexture返回无效纹理。

修复后的代码示例

express.enableCustomVideoProcessing(true, new ZegoCustomVideoProcessConfig(), ZegoPublishChannel.MAIN);
express.setCustomVideoProcessHandler(new IZegoCustomVideoProcessHandler(){
    private boolean isEffectsInited = false;

    @Override
    public void onStart(ZegoPublishChannel channel) {
        Log.i("ZEGOCLOUD", "[Express] [onStart]");
    }

    @Override
    public void onStop(ZegoPublishChannel channel) {
        Log.i("ZEGOCLOUD", "[Express] [onStop]");
        effects.uninitEnv();
        isEffectsInited = false;
    }

    @Override
    public void onCapturedUnprocessedTextureData(int textureID, int width, int height, Long referenceTimeMillisecond, ZegoPublishChannel channel) {
        Log.i("ZEGOCLOUD", "[Express] [onCapturedUnprocessedTextureData] textureID:" + textureID + " width:" + width + " height:" + height + ", ts:" + referenceTimeMillisecond);

        // 首次采集时根据实际分辨率初始化美颜环境
        if (!isEffectsInited) {
            effects.initEnv(width, height);
            isEffectsInited = true;
        }

        // 完善视频帧参数(根据美颜SDK要求调整)
        effectsVideoFrameParam.width = width;
        effectsVideoFrameParam.height = height;
        effectsVideoFrameParam.textureType = GL_TEXTURE_2D;
        effectsVideoFrameParam.pixelFormat = ZegoVideoPixelFormat.RGBA32;
        effectsVideoFrameParam.rotation = 0;

        int processedTextureID = effects.processTexture(textureID, effectsVideoFrameParam);

        // 检查处理后的纹理是否有效,无效时 fallback 原纹理避免全黑
        if (processedTextureID != 0) {
            express.sendCustomVideoProcessedTextureData(processedTextureID, width, height, referenceTimeMillisecond);
        } else {
            express.sendCustomVideoProcessedTextureData(textureID, width, height, referenceTimeMillisecond);
            Log.e("ZEGOCLOUD", "[Express] Process texture failed, send original texture");
        }
    }
});

额外排查点

  • 确认effects对象初始化正常,美颜SDK的授权/license有效,无效授权会直接导致处理失败;
  • 检查ZegoCustomVideoProcessConfig配置:确保bufferType设为TEXTURE_2D,同时开启预览和推流的自定义处理:
    ZegoCustomVideoProcessConfig config = new ZegoCustomVideoProcessConfig();
    config.setBufferType(ZegoVideoBufferType.TEXTURE_2D);
    config.setPreviewProcessed(true);
    config.setPublishProcessed(true);
    
  • 确认OpenGL环境正常:ZEGOCLOUD的回调已在GL线程执行,需确保美颜SDK的方法支持该线程调用。

内容的提问来源于stack exchange,提问作者Larry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 21:50:12