VideoLingo API文档详解:RESTful接口使用指南

VideoLingo API文档详解:RESTful接口使用指南

【免费下载链接】VideoLingo Netflix级字幕切割、翻译、对齐、甚至加上配音,一键全自动视频搬运AI字幕组 【免费下载链接】VideoLingo 项目地址: https://gitcode.com/GitHub_Trending/vi/VideoLingo

概述

VideoLingo是一个专业的视频字幕处理平台,提供Netflix级的字幕切割、翻译、对齐和配音功能。本文档详细介绍了VideoLingo的RESTful API接口,帮助开发者通过编程方式集成视频处理能力。

快速开始

基础URL

https://api.videolingo.io/v1

认证方式

所有API请求都需要在Header中包含API密钥:

Authorization: Bearer YOUR_API_KEY

响应格式

所有API响应都采用JSON格式,包含以下字段:

字段名类型描述
codeinteger状态码(200表示成功)
messagestring状态消息
dataobject响应数据
timestampstring时间戳

核心API接口

1. 视频上传接口

POST /videos/upload
Content-Type: multipart/form-data

请求参数:

  • file (required): 视频文件
  • source_language (optional): 源语言代码(默认:en)
  • target_language (optional): 目标语言代码(默认:zh-CN)

响应示例:

{
  "code": 200,
  "message": "Video uploaded successfully",
  "data": {
    "video_id": "vid_1234567890",
    "filename": "demo.mp4",
    "duration": 120.5,
    "resolution": "1920x1080"
  },
  "timestamp": "2024-01-15T10:30:00Z"
}

2. 字幕处理接口

POST /videos/{video_id}/subtitles/process

请求体:

{
  "process_type": "full", // full, translation_only, alignment_only
  "whisper_model": "large-v3",
  "demucs_separation": true,
  "max_subtitle_length": 75,
  "custom_terminology": {
    "AI": "人工智能",
    "ML": "机器学习"
  }
}

处理状态流程图: mermaid

3. 配音处理接口

POST /videos/{video_id}/dubbing/process

请求体:

{
  "tts_method": "azure_tts",
  "voice_config": {
    "voice": "zh-CN-YunfengNeural",
    "speed": 1.0,
    "pitch": 0
  },
  "audio_quality": "high"
}

支持的TTS方法对比:

方法质量延迟成本适用场景
azure_tts⭐⭐⭐⭐⭐中等中等商业应用
openai_tts⭐⭐⭐⭐高质量需求
edge_tts⭐⭐⭐免费测试和演示
fish_tts⭐⭐⭐⭐中等中文优化
voice_replication⭐⭐⭐⭐⭐声音复刻

4. 任务状态查询接口

GET /tasks/{task_id}

响应示例:

{
  "code": 200,
  "message": "Task status retrieved",
  "data": {
    "task_id": "task_123456",
    "video_id": "vid_1234567890",
    "type": "subtitle_processing",
    "status": "processing",
    "progress": 65,
    "current_step": "translation",
    "estimated_time_remaining": "00:05:30",
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:35:30Z"
  },
  "timestamp": "2024-01-15T10:35:30Z"
}

5. 结果下载接口

GET /videos/{video_id}/results

查询参数:

  • type: subtitle(字幕文件)、dubbed_video(配音视频)、original_subtitles(原始字幕)

响应示例:

{
  "code": 200,
  "message": "Results retrieved",
  "data": {
    "subtitle_files": [
      {
        "language": "zh-CN",
        "format": "srt",
        "download_url": "https://api.videolingo.io/download/sub_123.srt",
        "size": "15.2KB"
      }
    ],
    "processed_videos": [
      {
        "type": "dubbed",
        "format": "mp4",
        "resolution": "1920x1080",
        "download_url": "https://api.videolingo.io/download/vid_123_dubbed.mp4",
        "size": "125.7MB"
      }
    ]
  },
  "timestamp": "2024-01-15T10:40:00Z"
}

高级功能API

批量处理接口

POST /batch/process
Content-Type: application/json

请求体:

{
  "tasks": [
    {
      "video_url": "https://example.com/video1.mp4",
      "source_language": "en",
      "target_language": "zh-CN",
      "process_subtitles": true,
      "process_dubbing": false
    },
    {
      "video_url": "https://example.com/video2.mp4",
      "source_language": "ja",
      "target_language": "en",
      "process_subtitles": true,
      "process_dubbing": true,
      "tts_config": {
        "method": "azure_tts",
        "voice": "en-US-JennyNeural"
      }
    }
  ],
  "callback_url": "https://your-app.com/webhook/videolingo"
}

自定义术语管理

POST /terminology
Content-Type: application/json

请求体:

{
  "domain": "technology",
  "terms": {
    "API": "应用程序接口",
    "SDK": "软件开发工具包",
    "Framework": "框架",
    "Containerization": "容器化"
  }
}

错误处理

常见错误码

错误码描述解决方案
400请求参数错误检查请求体格式和参数
401认证失败检查API密钥是否正确
403权限不足检查API密钥权限
404资源不存在检查视频ID或任务ID
429请求频率限制降低请求频率
500服务器内部错误联系技术支持

错误响应示例

{
  "code": 429,
  "message": "Rate limit exceeded",
  "data": {
    "retry_after": 60,
    "limit": 100,
    "remaining": 0
  },
  "timestamp": "2024-01-15T10:30:00Z"
}

最佳实践

1. 异步处理模式

import requests
import time

def process_video_async(video_file, api_key):
    # 上传视频
    upload_response = requests.post(
        "https://api.videolingo.io/v1/videos/upload",
        files={"file": video_file},
        headers={"Authorization": f"Bearer {api_key}"}
    )
    
    video_id = upload_response.json()["data"]["video_id"]
    
    # 启动字幕处理
    subtitle_task = requests.post(
        f"https://api.videolingo.io/v1/videos/{video_id}/subtitles/process",
        json={"process_type": "full"},
        headers={"Authorization": f"Bearer {api_key}"}
    )
    
    task_id = subtitle_task.json()["data"]["task_id"]
    
    # 轮询任务状态
    while True:
        status_response = requests.get(
            f"https://api.videolingo.io/v1/tasks/{task_id}",
            headers={"Authorization": f"Bearer {api_key}"}
        )
        
        status = status_response.json()["data"]["status"]
        
        if status == "completed":
            break
        elif status == "failed":
            raise Exception("Processing failed")
        
        time.sleep(10)  # 每10秒检查一次
    
    # 获取结果
    results = requests.get(
        f"https://api.videolingo.io/v1/videos/{video_id}/results",
        headers={"Authorization": f"Bearer {api_key}"}
    )
    
    return results.json()

2. Webhook集成

from flask import Flask, request

app = Flask(__name__)

@app.route('/webhook/videolingo', methods=['POST'])
def videolingo_webhook():
    data = request.json
    
    if data['event'] == 'task_completed':
        video_id = data['video_id']
        task_type = data['task_type']
        
        # 处理完成通知
        if task_type == 'subtitle_processing':
            print(f"字幕处理完成: {video_id}")
        elif task_type == 'dubbing_processing':
            print(f"配音处理完成: {video_id}")
    
    return {'status': 'ok'}

if __name__ == '__main__':
    app.run(port=5000)

性能优化建议

1. 并发处理限制

mermaid

2. 缓存策略

缓存类型有效期适用场景
视频元数据24小时频繁查询的视频信息
处理配置1小时常用处理配置模板
术语库7天领域特定术语翻译
任务状态5分钟实时状态查询

总结

VideoLingo API提供了一套完整的视频字幕处理和配音解决方案,支持从简单的字幕翻译到复杂的多语言配音工作流。通过合理的API设计和错误处理机制,开发者可以轻松地将专业的视频处理能力集成到自己的应用中。

关键特性包括:

  • 完整的异步处理流水线
  • 多TTS引擎支持
  • 批量处理能力
  • Webhook事件通知
  • 详细的进度跟踪

建议开发者根据实际业务需求选择合适的处理配置,并合理使用缓存和并发控制来优化性能。

【免费下载链接】VideoLingo Netflix级字幕切割、翻译、对齐、甚至加上配音,一键全自动视频搬运AI字幕组 【免费下载链接】VideoLingo 项目地址: https://gitcode.com/GitHub_Trending/vi/VideoLingo

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值