Documentation
¶
Overview ¶
Package creatomate provides a Go SDK for the Creatomate API.
Creatomate is a video generation API that allows you to create videos programmatically. This SDK provides a type-safe interface to the Creatomate API with full support for all elements, animations, and properties.
Basic Usage ¶
client := creatomate.NewClient("your-api-key")
source := creatomate.NewSource(creatomate.SourceProperties{
OutputFormat: properties.OutputFormatMP4,
Width: 1920,
Height: 1080,
Duration: 10,
Elements: []interface{}{
elements.NewVideo(elements.VideoProperties{
Source: "https://example.com/video.mp4",
}),
},
})
renders, err := client.Render(context.Background(), creatomate.RenderOptions{
Source: source,
}, 5*time.Minute)
JSON Compatibility ¶
This package is designed to produce JSON output that is 100% compatible with the official Creatomate Node.js SDK. All property names are automatically converted to snake_case, and special types like Font and TextBackground are expanded into their constituent properties.
Elements ¶
The package supports all Creatomate elements:
- Video
- Image
- Text
- Audio
- Shape (Rectangle, Ellipse)
- Composition
Each element type has its own properties and can be animated using keyframes or animation presets.
Animations ¶
Animations can be applied to elements using:
- Enter animations (played when element appears)
- Exit animations (played when element disappears)
- Keyframe animations (custom property animations over time)
- Text-specific animations (typewriter, slide, reveal, etc.)
Error Handling ¶
The SDK provides typed errors for all API error conditions:
- BadRequestError
- InvalidApiKeyError
- InsufficientCreditsError
- RateLimitExceededError
- ConnectionError
- TimeoutError
Index ¶
- Constants
- func DebugJSON(name string, value interface{})
- type BadRequestError
- type Client
- type ConnectionError
- type CreatomateError
- type Font
- type InsufficientCreditsError
- type InvalidApiKeyError
- type Keyframe
- type RateLimitExceededError
- type Render
- type RenderOptions
- type RenderOutputFormat
- type RenderStatus
- type Source
- type SourceProperties
- type TextBackground
- type TextSlide
- type TimeoutError
- type ValueOrKeyframes
Constants ¶
const ( ClientVersion = "1.0.0" BaseURL = "https://api.creatomate.com/v1" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BadRequestError ¶
type BadRequestError struct {
CreatomateError
}
func NewBadRequestError ¶
func NewBadRequestError(hint string) *BadRequestError
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) FetchRender ¶
FetchRender fetches the status of the render.
func (*Client) Render ¶
func (c *Client) Render(ctx context.Context, options RenderOptions, timeout time.Duration) ([]Render, error)
Render starts a new render and awaits its completion.
func (*Client) StartRender ¶
StartRender starts a render, but doesn't wait for it to finish.
type ConnectionError ¶
type ConnectionError struct {
CreatomateError
}
func NewConnectionError ¶
func NewConnectionError() *ConnectionError
type CreatomateError ¶
type CreatomateError struct {
Message string
}
func NewCreatomateError ¶
func NewCreatomateError(message string) *CreatomateError
func (*CreatomateError) Error ¶
func (e *CreatomateError) Error() string
type Font ¶
type Font struct {
Family string `json:"family"`
Weight *int `json:"weight,omitempty"`
Style *string `json:"style,omitempty"`
Size interface{} `json:"size,omitempty"` // number or string
Minimum interface{} `json:"minimum,omitempty"` // number or string
Maximum interface{} `json:"maximum,omitempty"` // number or string
}
Font represents font properties that get expanded in JSON
type InsufficientCreditsError ¶
type InsufficientCreditsError struct {
CreatomateError
}
func NewInsufficientCreditsError ¶
func NewInsufficientCreditsError() *InsufficientCreditsError
type InvalidApiKeyError ¶
type InvalidApiKeyError struct {
CreatomateError
}
func NewInvalidApiKeyError ¶
func NewInvalidApiKeyError() *InvalidApiKeyError
type Keyframe ¶
type Keyframe[T any] struct { Time float64 `json:"time"` Value T `json:"value"` Easing properties.Easing `json:"easing,omitempty"` }
Keyframe represents an animation keyframe
func NewKeyframe ¶
NewKeyframe creates a new keyframe with time and value
func NewKeyframeWithEasing ¶
func NewKeyframeWithEasing[T any](value T, time float64, easing properties.Easing) *Keyframe[T]
NewKeyframeWithEasing creates a new keyframe with time, value, and easing
type RateLimitExceededError ¶
type RateLimitExceededError struct {
CreatomateError
}
func NewRateLimitExceededError ¶
func NewRateLimitExceededError() *RateLimitExceededError
type Render ¶
type Render struct {
ID string `json:"id"`
Status RenderStatus `json:"status"`
ErrorMessage string `json:"error_message,omitempty"`
URL string `json:"url"`
SnapshotURL string `json:"snapshot_url,omitempty"`
TemplateID string `json:"template_id,omitempty"`
TemplateName string `json:"template_name,omitempty"`
TemplateTags []string `json:"template_tags,omitempty"`
OutputFormat string `json:"output_format"`
RenderScale float64 `json:"render_scale"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
FrameRate float64 `json:"frame_rate,omitempty"`
Duration float64 `json:"duration,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
Modifications map[string]interface{} `json:"modifications,omitempty"`
WebhookURL string `json:"webhook_url,omitempty"`
Metadata string `json:"metadata,omitempty"`
}
type RenderOptions ¶
type RenderOptions struct {
OutputFormat RenderOutputFormat `json:"output_format,omitempty"`
FrameRate float64 `json:"frame_rate,omitempty"`
RenderScale float64 `json:"render_scale,omitempty"`
MaxWidth int `json:"max_width,omitempty"`
MaxHeight int `json:"max_height,omitempty"`
TemplateID string `json:"template_id,omitempty"`
Tags []string `json:"tags,omitempty"`
Source interface{} `json:"source,omitempty"` // Can be *Source or map[string]interface{}
Modifications map[string]interface{} `json:"modifications,omitempty"`
WebhookURL string `json:"webhook_url,omitempty"`
Metadata string `json:"metadata,omitempty"`
}
type RenderOutputFormat ¶
type RenderOutputFormat string
const ( RenderOutputFormatJPG RenderOutputFormat = "jpg" RenderOutputFormatPNG RenderOutputFormat = "png" RenderOutputFormatGIF RenderOutputFormat = "gif" RenderOutputFormatMP4 RenderOutputFormat = "mp4" )
type RenderStatus ¶
type RenderStatus string
const ( RenderStatusPlanned RenderStatus = "planned" RenderStatusWaiting RenderStatus = "waiting" RenderStatusTranscribing RenderStatus = "transcribing" RenderStatusRendering RenderStatus = "rendering" RenderStatusSucceeded RenderStatus = "succeeded" RenderStatusFailed RenderStatus = "failed" )
type Source ¶
type Source struct {
Properties SourceProperties
}
func NewSource ¶
func NewSource(properties SourceProperties) *Source
type SourceProperties ¶
type SourceProperties struct {
// The output format of the render, which can be jpg, png, gif, or mp4.
OutputFormat properties.OutputFormat `json:"output_format"`
// Only for MP4 renders. Sets the constant rate factor (CRF) ranging from 17 to 51.
CRF int `json:"crf,omitempty"`
// Only for GIF renders. With 'best', the GIF generation takes much longer.
GifQuality properties.GifQuality `json:"gif_quality,omitempty"`
// Only for GIF renders. A number ranging from 0 to 200 indicating the compression level.
GifCompression int `json:"gif_compression,omitempty"`
// The width of the output in pixels.
Width int `json:"width,omitempty"`
// The height of the output in pixels.
Height int `json:"height,omitempty"`
// The frame rate of the rendered video.
FrameRate float64 `json:"frame_rate,omitempty"`
// The duration of the output in seconds.
Duration float64 `json:"duration,omitempty"`
// Only for GIF renders. Set to true to make the GIF repeat.
Loop bool `json:"loop,omitempty"`
// If a snapshot image is desired, specify the time in seconds.
SnapshotTime float64 `json:"snapshot_time,omitempty"`
// The style of the Emojis used in text elements.
EmojiStyle properties.EmojiStyle `json:"emoji_style,omitempty"`
// The background fill.
Fill ValueOrKeyframes[*properties.Fill] `json:"fill,omitempty"`
// The background fill color.
FillColor ValueOrKeyframes[string] `json:"fill_color,omitempty"`
// The fill method used: solid, linear, and radial.
FillMode ValueOrKeyframes[string] `json:"fill_mode,omitempty"`
// The start position of the gradient on the x-axis.
FillX0 ValueOrKeyframes[interface{}] `json:"fill_x0,omitempty"`
// The start position of the gradient on the y-axis.
FillY0 ValueOrKeyframes[interface{}] `json:"fill_y0,omitempty"`
// The end position of the gradient on the x-axis.
FillX1 ValueOrKeyframes[interface{}] `json:"fill_x1,omitempty"`
// The end position of the gradient on the y-axis.
FillY1 ValueOrKeyframes[interface{}] `json:"fill_y1,omitempty"`
// The radius of the radial gradient.
FillRadius ValueOrKeyframes[interface{}] `json:"fill_radius,omitempty"`
// Custom fonts array.
Fonts []properties.FontDefinition `json:"fonts,omitempty"`
// Elements that make up the render.
Elements []interface{} `json:"elements,omitempty"`
}
type TextBackground ¶
type TextBackground struct {
Color string `json:"color"`
XPadding interface{} `json:"x_padding,omitempty"` // number or string
YPadding interface{} `json:"y_padding,omitempty"` // number or string
BorderRadius interface{} `json:"border_radius,omitempty"` // number or string
AlignThreshold interface{} `json:"align_threshold,omitempty"` // number or string
}
TextBackground represents text background properties that get expanded in JSON
func NewTextBackground ¶
func NewTextBackground(color string, xPadding, yPadding, borderRadius, alignThreshold interface{}) *TextBackground
NewTextBackground creates a new TextBackground
func (*TextBackground) ToMap ¶
func (tb *TextBackground) ToMap() map[string]interface{}
ToMap expands text background properties for JSON serialization
type TextSlide ¶
type TextSlide struct {
Duration float64 `json:"duration,omitempty"`
Easing string `json:"easing,omitempty"`
Split string `json:"split,omitempty"` // "letter", "word", "line"
Scope string `json:"scope,omitempty"` // "element", "text"
BackgroundEffect string `json:"background_effect,omitempty"` // "scaling-clip", etc.
}
TextSlide represents a text slide animation
func NewTextSlide ¶
NewTextSlide creates a new text slide animation
type TimeoutError ¶
type TimeoutError struct {
CreatomateError
}
func NewTimeoutError ¶
func NewTimeoutError() *TimeoutError
type ValueOrKeyframes ¶
type ValueOrKeyframes[T any] interface{}