You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
视频内容安全
视频风险识别
复制全文
视频风险识别

算子介绍

基于业务风险识别产品-视频风险识别-视频点播服务进行视频风险识别。

注意与前提
  • 依赖的产品:算子使用前置条件:开通业务风险识别产品-视频风险识别-视频点播服务:产品链接
  • 其他:

细分项

注意与前提

费用

调用算子前,您需先了解使用算子时的模型调用费用,详情请参见大模型调用计费

鉴权(API Key)

调用算子前,您需要先生成算子调用的API Key,并建议将API Key配置为环境变量,便于更安全地调用算子,详情请参见获取 API Key 并配置

BaseURL

调用算子前,您需要先根据您当前使用的LAS服务所在地域,了解算子调用的BaseURL,用于配置算子调用路径参数取值。
详情请参见获取 Base URL,下文中的调用示例仅作为参考,实际调用时需替换为您对应地域的路径取值。

Daft 调用

算子参数

输入

输入列名

说明

data_id

输入视频唯一标志列

url

视频内容所在的列,支持可直接访问的 url 地址

title

(可选)视频标题列

account_id

(可选)视频发送者的ID列

operate_time

(可选)用户发送视频的秒级时间戳列

video_type

(可选)视频类型列,AIGC对话场景下必传,列值为 prompt 表示用户输入视频,列值为 response 表示模型生成视频;空字符串主要作用于非AIGC对话场景

session_id

(可选)对话轮次列,AIGC对话场景下必传,用于表示该视频在对话中的轮次

输出

一个结构体,包含风险识别结果

  • VideoDecision: 视频判定结果 (PASS, BLOCK, REVIEW)
  • VideoDecisionDetail: 视频判定详情
  • AudioDecision: 音频判定结果 (PASS, BLOCK, REVIEW)
  • AudioDecisionDetail: 音频判定详情
  • Message: 服务端返回信息
  • risk_result: 完整的 JSON 格式检测结果

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

app_id

int

必填,在业务风险识别产品中开通的应用ID

biztype

str

必填,在业务风险识别产品中配置的视频风险识别场景

result_type

int

0

切片内容类型
0 表示仅返回违规的视频切片
1 表示返回所有切片检测结果
可选值:[0, 1]
默认值:0

interval

int

2

截帧频率,单位(s)
截帧频率,未传入或传入为空或者传值为0时,默认为2s一帧,最低为1s一帧
默认值:2

timeout

int

120

超时时间设置,单位(s)
设置从发送请求到接收到结果的超时设置,如果是离线任务,为了防止数据处理阻塞,可以适当的增加该值
默认值:120

poll_interval

int

10

轮询间隔设置,单位(s)
调用主动查询接口时,设置的轮询间隔,请根据主动查询接口QPS以及性能需求来设置
默认值:10

num_coroutines

int

5

并发协程数量
默认值:5

调用示例

下面的代码展示了如何使用 Daft(适用于分布式)运行算子进行视频内容风险识别。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.udf import las_udf
from daft.las.functions.video.video_risk_rec import VideoRiskRec

if __name__ == "__main__":
    """
    算子使用前置条件:开通业务风险识别产品-文本风险识别,产品链接见:https://www.volcengine.com/product/business-security
    app_id: 在业务风险识别产品中开通的应用ID
    biztype: 在业务风险识别产品中配置的场景
    还需要设置 ACCESS_KEY,SECRET_KEY 用来鉴权
    """
    app_id = int(os.getenv("APP_ID", "0"))
    biztype = os.getenv("BIZTYPE", "test_biztype")

    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.set_runner_ray()

    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    # 使用环境变量构建URL
    tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com")
    samples = {
        "video_id": ["8"],  # 视频风险识别服务会记录视频 id,同一个 id 会返回已经执行的缓存的结果
        "video_url": [
            f"https://{tos_dir_url}/public/shared_video_dataset/music_sample.mp4"
        ],
        "title": ["测试视频1"],
        "account_id": ["user001"],
    }

    constructor_kwargs = {
        "app_id": app_id,
        "biztype": biztype,
        "result_type": 0,
        "interval": 2,
        "timeout": 300,
        "poll_interval": 3,
    }

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "result",
        las_udf(
            VideoRiskRec,
            construct_args=constructor_kwargs,
            concurrency=1,
            batch_size=1,
        )(col("video_id"), col("video_url"), title_col=col("title"), account_id_col=col("account_id")),
    )

    # 提取结果字段
    ds = ds.with_column("VideoDecision", col("result")["VideoDecision"])
    ds = ds.with_column("VideoDecisionDetail", col("result")["VideoDecisionDetail"])
    ds = ds.with_column("AudioDecision", col("result")["AudioDecision"])
    ds = ds.with_column("AudioDecisionDetail", col("result")["AudioDecisionDetail"])
    ds = ds.with_column("Message", col("result")["Message"])
    ds = ds.with_column("risk_result", col("result")["risk_result"])

    ds.show()

    # 示例输出:
    # ╭──────────┬────────────────────────────────┬───────────┬────────────┬──────────────────────────┬───────────────┬─────────────────────┬───────────────┬─────────────────────┬─────────┬──────────────────────────╮
    # │ video_id ┆ video_url                      ┆ title     ┆ account_id ┆ result                   ┆ VideoDecision ┆ VideoDecisionDetail ┆ AudioDecision ┆ AudioDecisionDetail ┆ Message ┆ risk_result              │
    # │ ---      ┆ ---                            ┆ ---       ┆ ---        ┆ ---                      ┆ ---           ┆ ---                 ┆ ---           ┆ ---                 ┆ ---     ┆ ---                      │
    # │ String   ┆ String                         ┆ String    ┆ String     ┆ Struct[VideoDecision:    ┆ String        ┆ String              ┆ String        ┆ String              ┆ String  ┆ String                   │
    # │          ┆                                ┆           ┆            ┆ String,                  ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # │          ┆                                ┆           ┆            ┆ VideoDecisionDetail:     ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # │          ┆                                ┆           ┆            ┆ String, AudioDecision:   ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # │          ┆                                ┆           ┆            ┆ String,                  ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # │          ┆                                ┆           ┆            ┆ AudioDecisionDetail:     ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # │          ┆                                ┆           ┆            ┆ String, Message: String, ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # │          ┆                                ┆           ┆            ┆ risk_result: String]     ┆               ┆                     ┆               ┆                     ┆         ┆                          │
    # ╞══════════╪════════════════════════════════╪═══════════╪════════════╪══════════════════════════╪═══════════════╪═════════════════════╪═══════════════╪═════════════════════╪═════════╪══════════════════════════╡
    # │ 8        ┆ https://las-ai-qa-online.tos-… ┆ 测试视频1 ┆ user001    ┆ {VideoDecision: PASS,    ┆ PASS          ┆                     ┆ PASS          ┆                     ┆ success ┆ {"Result": {"RequestId": │
    # │          ┆                                ┆           ┆            ┆ VideoDe…                 ┆               ┆                     ┆               ┆                     ┆         ┆ "202…                    │
    # ╰──────────┴────────────────────────────────┴───────────┴────────────┴──────────────────────────┴───────────────┴─────────────────────┴───────────────┴─────────────────────┴─────────┴──────────────────────────╯
最近更新时间:2026.02.10 15:51:19
这个页面对您有帮助吗?
有用
有用
无用
无用