You need to enable JavaScript to run this app.
导航
画质超分
最近更新时间:2025.03.17 10:50:49首次发布时间:2022.02.25 17:16:51
我的收藏
有用
有用
无用
无用
简介

超分,目前超分指在原来基础上宽和高同时扩张两倍。
注意:iOS11以下机器不支持除插帧外画质相关的算法。
iOS端模型依赖:videovrsr.bundle

技术规格
支持平台Android、iOS
支持分辨率目前需要分辨率小于720p
ios平台依赖需要ios 11及以上的版本, 支持iPhone7以上的设备
android平台依赖设备支持高通660及以上处理器,也支持 mail g51及以上处理器
ios 支持输入格式PixelBuffer输入,支持yuv420p 和yuv420f, (未来支持metal texture)
android 支持输入格式纹理输入
检测速度32ms(测试处理器高通660 oppo r11 720p 输入)
C接口说明

详解接口文档, bef_ai_image_quality_enhancement_video_sr.h

1.创建超分句柄

/**
 * @brief Create effect handle.
 * @param handle      handle that will be created.
 * @return            If succeed return BEF_EFFECT_RESULT_SUC, other value please see bef_effect_ai_public_define.h.
 */
BEF_SDK_API bef_effect_result_t 
bef_ai_image_quality_enhancement_video_sr_create(bef_image_quality_enhancement_handle* handle, const char* dir);

参数说明

参数名参数类型参数说明
handlebef_image_quality_enhancement_handle创建超分的句柄
dirchar*android 下为可读写的路径,保存初始化的内容

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

2.设置输入的属性

/**
 *  set the input property 
 * @param handle
 * @param width Input width of the  buffer or texture
 * @param height Input height of the  buffer or texture
 * @return If succeed return BEF_EFFECT_RESULT_SUC, other value please see bef_effect_ai_public_define.h.
 */
BEF_SDK_API bef_effect_result_t
bef_ai_image_quality_enhancement_video_sr_set_width_and_height(bef_image_quality_enhancement_handle handle, int width , int height);

参数说明

参数名参数类型参数说明
handlebef_image_quality_enhancement_handle超分的句柄
widthint输入的宽
heightint输入的高

3.检测画质超分授权

/**
 * @param handle Created effect detect handle
 *                   已创建的句柄
 * @param license_path licese path under the dircetory
 *                  license 在文件系统中的绝对路径
 * @param result If succeed return BEF_EFFECT_RESULT_SUC, other value please see bef_effect_ai_public_define.h.
 *
 */
BEF_SDK_API bef_effect_result_t 
bef_ai_image_quality_enhancement_video_sr_check_license(bef_image_quality_enhancement_handle handle, const char* license_path);

参数说明

参数名参数类型参数说明
handlebef_image_quality_enhancement_handle画质的句柄
licensePathconst char *授权文件字符串

返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

4.检测画质超分授权

/**
 * process the input and get the resoult
 * @param handle
 * @param input input infomation of texture or pixelbuffer 
 *              Android的输入只支持texture2D纹理, 需要传入纹理的宽高,纹理需要放在input->data.texture[0]
 *              ios 目前只支持yuv420p, 420f 的pixelbuffer输入,输出为对应格式pixelbuffer 无需手动释放, pixelbuffer 放在input->data.buffer 处
 * @param output output infomation of texture or pixelbuffer
 *              Android的输出只支持texture2D纹理,返回纹理的宽和高,纹理结果放在output->data.texture[0]
 *              ios 的输出为pixelbuffer,  pixelbuffer 放在output->data.buffer 处
 * @return If succeed return BEF_EFFECT_RESULT_SUC, other value please see bef_effect_ai_public_define.h.
 */
BEF_SDK_API bef_effect_result_t
bef_ai_image_quality_enhancement_video_sr_process(bef_image_quality_enhancement_handle handle, const bef_ai_video_sr_input* input, bef_ai_video_sr_output *output);

参数说明

参数名参数类型参数说明
handlebef_image_quality_enhancement_handle画质的句柄
inputef_ai_video_sr_input *授权文件字符串
outputbef_ai_video_sr_output *授权文件字符串

input input information of texture or pixelbuffer
Android的输入只支持texture2D纹理, 需要传入纹理的宽高,纹理需要放在input->data.texture[0]
ios 目前只支持yuv420p, 420f 的pixelbuffer输入, pixelbuffer 放在input->data.buffer 处
output output information of texture or pixelbuffer
Android的输出只支持texture2D纹理,返回纹理的宽和高,纹理结果放在output->data.texture[0]
ios 的输出为pixelbuffer, pixelbuffer 放在output->data.buffer 处,输出为对应格式pixelbuffer 无需手动释放,拿到buffer后需要先对buffer进行retain,防止内部的内存是对pixelbuffer 进行回收
返回值
成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h

5.画质超分句柄的释放

/**
 * @param handle    handle that will  destroy
 */
BEF_SDK_API bef_effect_result_t 
bef_ai_image_quality_enhancement_vidoe_sr_destory(bef_image_quality_enhancement_handle handle);

参数说明

参数名参数类型参数说明
handlebef_image_quality_enhancement_handle创建的画质句柄

6.参数说明

typedef struct bef_ai_video_sr_init_config
{
    const char* model_path;     // 模型文件的路径,详细说明请查看附录算法模型的说明部分
    int model_data_length;      // 目前不需要传入
    const char* metal_path;     // 目前不需要传入
    bool enable_mem_pool;       // 是否使用内存池,短视频场景下使用
    bef_ai_lens_data_type input_type;   // 输入目前只有pixelbuffer格式
    bef_ai_lens_data_type output_type;  // 输出为pixelbuffer和 metal texture两种
    float float_thresh;         // 暂时不用设置
    int srType;            // 1.5x 用15表示,2.0x 用 20表示
}bef_ai_video_sr_init_config;
Java 接口

1. 创建画质超分句柄

创建画质超分的句柄

public int init(String rwDir, String licensePath){
        int ret = nativeCreate(rwDir, licensePath);
        if (ret != BytedEffectConstants.BytedResultCode.BEF_RESULT_SUC){
            mInited = false;
            return ret;
        }
        mInited = true;
        return ret;
    }

参数说明

参数名参数类型参数说明
rwDirString可读写的路径
licensePathString授权文件路径

返回值
成功返回BEF_RESULT_SUC,否则返回对应的错误码

2. 创建进行超分处理

public BefVideoSRInfo process(int srcTextureId ,int width, int height){
        if (!mInited){
            return null;
        }

        BefVideoSRInfo srInfo  =  new BefVideoSRInfo();
        int ret = nativeProcess(srcTextureId, width, height, srInfo);
        if (ret != BytedEffectConstants.BytedResultCode.BEF_RESULT_SUC) {
            Log.e(BytedEffectConstants.TAG, "nativeVideoSrProcess " + ret);
            return null;
        }
        return srInfo;
    }

参数说明

参数名参数类型参数说明
srcTextureIdint源纹理
widthint输入纹理宽度
heightint输入纹理高度

返回值
成功返回超分的结果,否则返回空

3. 释放超分的资源

public void release() {
        if (mInited){
            nativeRelease();
        }
        mInited = false;
    }

4. 超分倍数

public static enum LensVideoAlgType {
        SR_R_TYPE(0),  // 2x超分
        SR_A_TYPE(1),
        SR_G_TYPE(2),
        SR_N_TYPE(3),
        SR_R15_TYPE(4),  // 1.5x超分
        SR_U_UNKNOW(5);
关于画质超分的算法模型的说明

安卓与iOS因为实现方式不同的原因,安卓无需使用算法模型iOS必须使用算法模型

算法模型-iOS特有

Sample写法 超分算法依赖了videovrsr.bundle文件,需要把bundle文件放在主工程下,从而拷贝到安装app的根目录中。 直接用sample中的core文件来initTask,并且不做任何其他修改的话,就需要在mainBundle下默认找模型文件,无需传入路径,但必须放置在这里。 如图:

C接口
如果想要自己传入路径,除去使用sample中的core文件外,可以修改模型路径参数。 440及以上版本的超分,可以通过修改BEVideoSRTask.m文件中bef_ai_video_sr_init_config.model_path来传路径参数。
如图:

FAQ

1.如果出现任何异常,请查看是否有以下类型日志

答:建议首先查看以下tag输出Error类型的日志:
bef_effect_ai 和SMASH_E_LOG 以及 EffectSDK

2. 如果没有结果,或者结果不正确

答:android 下面检测OpenGL环境是否正确,且输入纹理是否正确 ios,xcode查看pixelbuffer的返回结果是否正确