Documentation
¶
Overview ¶
包 video 提供统一的视频生成与视频理解接口,适配 Gemini、Veo 和 Runway ML 三个服务商。
概述 ¶
本包将视频处理分为两大能力维度:视频分析(理解已有视频内容)和视频生成 (从文本/图像提示创建新视频)。不同 Provider 可能仅支持其中一种能力, 上层可通过 SupportsGeneration() 进行能力探测。
典型使用场景:
- 使用 Gemini 多模态能力对视频进行内容理解与帧级分析。
- 使用 Veo 3.1 或 Runway Gen-4 从文本/图像生成短视频。
- 统一请求模型,在不同 Provider 间无缝切换。
核心接口 ¶
- Provider — 视频处理的统一抽象,包含 Analyze()、Generate()、Name()、 SupportedFormats() 与 SupportsGeneration() 方法。
- AnalyzeRequest / AnalyzeResponse — 视频分析的请求与响应模型。
- GenerateRequest / GenerateResponse — 视频生成的请求与响应模型。
- FrameAnalysis / DetectedObject — 帧级分析结果与目标检测数据。
- VideoData / VideoUsage — 生成视频元数据与用量统计。
主要能力 ¶
- Gemini 适配:GeminiProvider 支持 MP4/WebM/MOV/AVI/MKV 五种格式的 视频内容分析,基于 Gemini 多模态 API。
- Veo 适配:VeoProvider 使用 Google Veo 3.1 生成视频,支持宽高比、 负向提示、音频生成等参数。
- Runway 适配:RunwayProvider 使用 Runway Gen-4 生成视频,支持 image-to-video 与 text-to-video。
- 异步轮询:Veo 与 Runway 均内置任务状态轮询机制。
- 格式枚举:VideoFormat 常量覆盖 MP4、WebM、MOV、AVI、MKV。
Index ¶
- type AnalyzeRequest
- type AnalyzeResponse
- type BoundingBox
- type DetectedObject
- type FrameAnalysis
- type GeminiConfig
- type GeminiProvider
- func (p *GeminiProvider) Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
- func (p *GeminiProvider) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
- func (p *GeminiProvider) Name() string
- func (p *GeminiProvider) SupportedFormats() []VideoFormat
- func (p *GeminiProvider) SupportsGeneration() bool
- type GenerateRequest
- type GenerateResponse
- type Provider
- type RunwayConfig
- type RunwayProvider
- func (p *RunwayProvider) Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
- func (p *RunwayProvider) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
- func (p *RunwayProvider) Name() string
- func (p *RunwayProvider) SupportedFormats() []VideoFormat
- func (p *RunwayProvider) SupportsGeneration() bool
- type VeoConfig
- type VeoProvider
- func (p *VeoProvider) Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
- func (p *VeoProvider) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
- func (p *VeoProvider) Name() string
- func (p *VeoProvider) SupportedFormats() []VideoFormat
- func (p *VeoProvider) SupportsGeneration() bool
- type VideoData
- type VideoFormat
- type VideoUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalyzeRequest ¶
type AnalyzeRequest struct {
VideoURL string `json:"video_url,omitempty"`
VideoData string `json:"video_data,omitempty"` // Base64 encoded
VideoFormat VideoFormat `json:"video_format,omitempty"`
Prompt string `json:"prompt"`
Model string `json:"model,omitempty"`
MaxFrames int `json:"max_frames,omitempty"` // Max frames to analyze
Interval float64 `json:"interval,omitempty"` // Frame interval in seconds
StartTime float64 `json:"start_time,omitempty"` // Start time in seconds
EndTime float64 `json:"end_time,omitempty"` // End time in seconds
Metadata map[string]string `json:"metadata,omitempty"`
}
AnalyzeRequest 表示视频分析请求.
type AnalyzeResponse ¶
type AnalyzeResponse struct {
Provider string `json:"provider"`
Model string `json:"model"`
Content string `json:"content"`
Frames []FrameAnalysis `json:"frames,omitempty"`
Duration float64 `json:"duration,omitempty"`
Usage VideoUsage `json:"usage,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
AnalyzeResponse 表示视频分析的响应.
type BoundingBox ¶
type BoundingBox struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `json:"height"`
}
BoundingBox 表示帧中的对象位置.
type DetectedObject ¶
type DetectedObject struct {
Label string `json:"label"`
Confidence float64 `json:"confidence"`
BoundingBox *BoundingBox `json:"bounding_box,omitempty"`
}
DetectedObject 表示在帧中检测到的对象.
type FrameAnalysis ¶
type FrameAnalysis struct {
Timestamp float64 `json:"timestamp"`
Description string `json:"description,omitempty"`
Objects []DetectedObject `json:"objects,omitempty"`
Text string `json:"text,omitempty"` // OCR text
Metadata map[string]string `json:"metadata,omitempty"`
}
FrameAnalysis 表示单帧的分析结果.
type GeminiConfig ¶
type GeminiConfig struct {
APIKey string `json:"api_key" yaml:"api_key"`
ProjectID string `json:"project_id,omitempty" yaml:"project_id,omitempty"`
Location string `json:"location,omitempty" yaml:"location,omitempty"`
Model string `json:"model,omitempty" yaml:"model,omitempty"` // gemini-3-flash-preview, gemini-3-pro-preview
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}
GeminiConfig 配置 Google Gemini 视频理解提供者.
func DefaultGeminiConfig ¶
func DefaultGeminiConfig() GeminiConfig
DefaultGeminiConfig 返回默认 Gemini 视频配置.
type GeminiProvider ¶
type GeminiProvider struct {
// contains filtered or unexported fields
}
GeminiProvider 使用 Google Gemini 执行视频分析.
func NewGeminiProvider ¶
func NewGeminiProvider(cfg GeminiConfig) *GeminiProvider
NewGeminiProvider 创建新的 Gemini 视频提供者.
func (*GeminiProvider) Analyze ¶
func (p *GeminiProvider) Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
Analyze 利用 Gemini 多模态能力分析视频内容.
func (*GeminiProvider) Generate ¶
func (p *GeminiProvider) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
Generate 不被 Gemini 视频提供者支持.
func (*GeminiProvider) Name ¶
func (p *GeminiProvider) Name() string
func (*GeminiProvider) SupportedFormats ¶
func (p *GeminiProvider) SupportedFormats() []VideoFormat
func (*GeminiProvider) SupportsGeneration ¶
func (p *GeminiProvider) SupportsGeneration() bool
type GenerateRequest ¶
type GenerateRequest struct {
Prompt string `json:"prompt"`
NegativePrompt string `json:"negative_prompt,omitempty"`
Model string `json:"model,omitempty"`
Duration float64 `json:"duration,omitempty"` // Duration in seconds
AspectRatio string `json:"aspect_ratio,omitempty"` // 16:9, 9:16, 1:1
Resolution string `json:"resolution,omitempty"` // 720p, 1080p
FPS int `json:"fps,omitempty"`
Seed int64 `json:"seed,omitempty"`
Image string `json:"image,omitempty"` // Image-to-video base64
ImageURL string `json:"image_url,omitempty"` // Image-to-video URL
ResponseFormat string `json:"response_format,omitempty"` // url, b64_json
Metadata map[string]string `json:"metadata,omitempty"`
}
GenerateRequest 表示视频生成请求.
type GenerateResponse ¶
type GenerateResponse struct {
Provider string `json:"provider"`
Model string `json:"model"`
Videos []VideoData `json:"videos"`
Usage VideoUsage `json:"usage,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
GenerateResponse 表示视频生成响应.
type Provider ¶
type Provider interface {
// Analyze 处理和理解视频内容.
Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
// Generate 从文本/图像提示生成视频.
Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
// Name 返回提供者名称.
Name() string
// SupportedFormats 返回支持用于分析的视频格式.
SupportedFormats() []VideoFormat
// SupportsGeneration 返回提供者是否支持视频生成.
SupportsGeneration() bool
}
Provider 定义视频处理提供者接口.
type RunwayConfig ¶
type RunwayConfig struct {
APIKey string `json:"api_key" yaml:"api_key"`
BaseURL string `json:"base_url" yaml:"base_url"`
Model string `json:"model,omitempty" yaml:"model,omitempty"` // gen-4, gen-4.5
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}
RunwayConfig 配置 Runway ML 视频生成提供者.
func DefaultRunwayConfig ¶
func DefaultRunwayConfig() RunwayConfig
DefaultRunwayConfig 返回默认 Runway 配置.
type RunwayProvider ¶
type RunwayProvider struct {
// contains filtered or unexported fields
}
Runway Provider执行视频生成,使用Runway ML Gen-4. API 文件: https://docs.dev.runwayml.com/api/
func NewRunwayProvider ¶
func NewRunwayProvider(cfg RunwayConfig) *RunwayProvider
NewRunway Provider创建了新的跑道视频提供商.
func (*RunwayProvider) Analyze ¶
func (p *RunwayProvider) Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
分析不由跑道支持.
func (*RunwayProvider) Generate ¶
func (p *RunwayProvider) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
利用跑道Gen-4生成视频. 终点: POST /v1/image to video Auth: 熊克令牌 + X- Runway-Version 信头
func (*RunwayProvider) Name ¶
func (p *RunwayProvider) Name() string
func (*RunwayProvider) SupportedFormats ¶
func (p *RunwayProvider) SupportedFormats() []VideoFormat
func (*RunwayProvider) SupportsGeneration ¶
func (p *RunwayProvider) SupportsGeneration() bool
type VeoConfig ¶
type VeoConfig struct {
APIKey string `json:"api_key" yaml:"api_key"`
Model string `json:"model,omitempty" yaml:"model,omitempty"` // veo-3.1-generate-preview
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}
VeoConfig 配置 Google Veo 视频生成提供者.
type VeoProvider ¶
type VeoProvider struct {
// contains filtered or unexported fields
}
VeoProvider使用Google Veo 3.1执行视频生成.
func NewVeoProvider ¶
func NewVeoProvider(cfg VeoConfig) *VeoProvider
NewVeoProvider创建了一个新的Veo视频提供商.
func (*VeoProvider) Analyze ¶
func (p *VeoProvider) Analyze(ctx context.Context, req *AnalyzeRequest) (*AnalyzeResponse, error)
Veo不支持分析。
func (*VeoProvider) Generate ¶
func (p *VeoProvider) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error)
生成视频使用Veo 3.1.
func (*VeoProvider) Name ¶
func (p *VeoProvider) Name() string
func (*VeoProvider) SupportedFormats ¶
func (p *VeoProvider) SupportedFormats() []VideoFormat
func (*VeoProvider) SupportsGeneration ¶
func (p *VeoProvider) SupportsGeneration() bool
type VideoData ¶
type VideoData struct {
URL string `json:"url,omitempty"`
B64JSON string `json:"b64_json,omitempty"`
Duration float64 `json:"duration,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
RevisedPrompt string `json:"revised_prompt,omitempty"`
}
VideoData 表示一个已生成的视频.
type VideoFormat ¶
type VideoFormat string
VideoFormat 表示支持的视频格式.
const ( VideoFormatMP4 VideoFormat = "mp4" VideoFormatWebM VideoFormat = "webm" VideoFormatMOV VideoFormat = "mov" VideoFormatAVI VideoFormat = "avi" VideoFormatMKV VideoFormat = "mkv" )
type VideoUsage ¶
type VideoUsage struct {
VideosGenerated int `json:"videos_generated"`
DurationSeconds float64 `json:"duration_seconds"`
Cost float64 `json:"cost,omitempty"`
}
VideoUsage 表示使用统计.