SuperAPI AI Directory

byted-las-video-resize

Design & creation

View repository

Updated 10-15 17:30

About this skill

LAS Video Resolution Adjustment (las_video_resize)

Adjust videos to a specified resolution range, supporting aspect ratio preservation strategies and GPU NVENC encoding.

Design Pattern

This skill mainly adopts:

  • Tool Wrapper: encapsulates the lasutil CLI call
  • Pipeline: includes a sequential workflow from Step 0 → Step N

Core API and Configuration

  • Operator ID: las_video_resize
  • API: asynchronous (submit → poll)
  • Environment Variable: LAS_API_KEY (required)

For detailed parameters and interface definitions, see references/api.md。

Gotchas

  • Force Fixed Size: requires setting min_width=max_width and min_height=max_height, and set force_original_aspect_ratio_type=disable。
  • Key Security: if the chat box blocks the key, have the user create env.sh in the current directory and write export LAS_API_KEY="...", and the SDK will read it automatically.
  • Disclaimer: the final reply result must include: "本方式的计费均为预估计费,与实际费用有差距,实际费用以运行后火山产生的账单为准。计费说明请参考 Volcengine LAS Pricing.", and it is prohibited to use the words "actual cost" to describe the estimated price.

Workflow (execute strictly step by step)

Copy this checklist and track progress:

执行进度:
- [ ] Step 0: 前置检查
- [ ] Step 1: 初始化与准备
- [ ] Step 2: 预估价格
- [ ] Step 3: 提交任务
- [ ] Step 4: 异步查询
- [ ] Step 5: 结果呈现

Step 0: Pre-checks (⚠️ must be completed in the first round of dialogue)

After accepting the user's task,do not start executing immediately, and the following environment checks must first be performed:

  1. Check LAS_API_KEY and LAS_REGION: confirm whether they are already configured in the environment variables or .env .
    • If not, you must immediately ask the user for it (hint:LAS_REGION is commonly cn-beijing)。
    • Note:LAS_REGION must be completely consistent with the region where your API Key and TOS Bucket are located. If the user switches Region midway, you must remind the user that their TOS Bucket also needs to be changed accordingly, otherwise it will cause permission exceptions or upload failures.
  2. Check Input Path:
    • If what the user requests to process is alocal file, it needs to first be uploaded to TOS via the File API (only LAS_API_KEYis needed, no additional TOS credentials are required).
    • If the operator'soutput resultis stored on TOS, and the user needs to download it back locally, then VOLCENGINE_ACCESS_KEY and VOLCENGINE_SECRET_KEYare required. For theonly need to upload the input filescenario, TOS credentials areno longer required。
  3. Check Output Path:
    • output_tos_dir is a required parameter and must be provided by the useras a TOS directory path they can write to(format:tos://bucket/output_dir/)。
    • The server needs to write the scaled video into this directory.
  4. After confirming everything is correct: only then can you proceed to the next step.

Step 1: Initialization and Preparation

Environment Initialization (mandatory for the Agent):

# 执行统一的环境初始化与更新脚本(会自动创建/激活虚拟环境,并检查更新)
source "$(dirname "$0")/scripts/env_init.sh" las_video_resize
workdir=$LAS_WORKDIR

If network issues cause the update to fail, the script will skip the check and continue execution using the locally installed SDK.

  • When processing local files: use the File API to upload (only LAS_API_KEYis needed, no TOS credentials or Bucket required):
    lasutil file-upload <local_path>
    
    After a successful upload, JSON is returned; extract the presigned_url(HTTPS presigned download link, valid for 24 hours) and pass it to the operator as the input URL.

Step 2: Estimate price (⚠️ user confirmation is required)

  1. Read references/prices.md to obtain the latest billing rates.
  2. Obtain video information (duration, encoding, resolution):
    lasutil media-duration <video_url>
    
  3. Calculate the total price by looking up the tier table,inform the user of both the billing unit price and the estimated total price and forcibly pause execution, and explicitly wait for the user to reply with confirmation. Before the user explicitly replies with an approval instruction such as "continue" or "confirm",it is absolutely forbiddento proceed to the next step (execution/submitting the task). Note: the estimate is for reference only; the actual amount is subject to the Volcengine bill. For billing details, refer to Volcengine LAS Pricing。

Step 3: Submit task (Submit)

Construct the base data.json:

{
  "video_path": "<presigned_url>",
  "output_tos_dir": "tos://<your-bucket>/output_dir/",
  "output_file_name": "resized.mp4",
  "min_width": 1280, "max_width": 2560,
  "min_height": 720, "max_height": 1440,
  "force_original_aspect_ratio_type": "increase"
}

Important note: output_tos_dir must be provided by the user, and a writable TOS directory under the user's own account must be filled in (the server will write the scaled video into this directory).

Single-file submission:

data=$(cat "$workdir/data.json")
lasutil submit las_video_resize "$data" > "$workdir/submit.json"

⚠️ Mandatory feedback: After the task is submitted successfully,the generated task_idmust be returned to the user immediately, so that the user can track progress or manually query it if necessary.

Step 4: Asynchronous polling (Poll)

⚠️ Constraints for asynchronous tasks and background polling:

  • If your current environmentsupports background tasks/asynchronous long-running execution: you may use the background capabilities provided by the environment (for example, launch a background polling task), and proactively return the result to the user after the task completes.
  • If your current environmentdoes not supportlong-running background tasks (such as an ordinary single-turn conversation sandbox), and directly sleep looping would cause a timeout crash:It is absolutely forbidden to execute an infinite wait loop in the code! In this case, you must immediately output the Task ID to the user and end the current turn, telling the user: "The task has been submitted; please ask me for progress later."

Single-task query:

lasutil poll las_video_resize {task_id}
  • COMPLETED → return the output video path result.data.output_path。
  • RUNNING/PENDING → retry later.

Step 5: Result presentation

Processing result:

# 获取缩放后的视频 URL
resized_url=$(cat "./output/{task_id}/result.json" | jq -r '.data.output_path')
echo "缩放后的视频: $resized_url"

Video file:

  • The scaled video has been saved to TOS; directly return the presigned URL
  • No need to upload again

Show to the user:

  1. Download link for the scaled video
  2. Output resolution and encoding information
  3. Local result path:./output/{task_id}/
  4. Billing statement

Review criteria

After execution is complete, the Agent should self-check:

  1. Whether the environment variables are configured correctly
  2. Whether the input file was uploaded successfully
  3. Whether the output result is correctly presented to the user
  4. Whether the billing statement is included