transcoding

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: AGPL-3.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package transcoding provides CloudFront signed URL generation

Package transcoding provides HLS/DASH manifest generation

Package transcoding provides AWS MediaConvert integration for video transcoding

Index

Constants

View Source
const (
	Quality4K    = "4k"
	Quality2160p = "2160p"
	Quality1080p = "1080p"
	Quality720p  = "720p"
	Quality480p  = "480p"
	Quality360p  = "360p"
	Quality240p  = "240p"
	QualityAuto  = "auto"
)

Quality level constants

Variables

View Source
var (
	// ErrInvalidPrivateKey is returned when the private key is invalid
	ErrInvalidPrivateKey = errors.New("invalid CloudFront private key")
	// ErrSigningFailed is returned when URL signing fails
	ErrSigningFailed = errors.New("failed to sign URL")
)
View Source
var (
	// ErrManifestNotFound is returned when a manifest is not found
	ErrManifestNotFound = errors.New("manifest not found")
	// ErrManifestGenerationFailed is returned when manifest generation fails
	ErrManifestGenerationFailed = errors.New("manifest generation failed")
)
View Source
var (
	// ErrInvalidRequest is returned when the transcode request is invalid
	ErrInvalidRequest = errors.New("invalid transcode request")
	// ErrJobNotFound is returned when a job is not found
	ErrJobNotFound = errors.New("transcode job not found")
	// ErrServiceUnavailable is returned when MediaConvert is unavailable
	ErrServiceUnavailable = errors.New("transcoding service unavailable")
)

Functions

func ValidateConfig

func ValidateConfig(config CloudFrontConfig) error

ValidateConfig validates the CloudFront configuration

Types

type CloudFrontConfig

type CloudFrontConfig struct {
	Domain        string        // CloudFront distribution domain
	KeyPairID     string        // CloudFront key pair ID
	PrivateKeyPEM string        // Private key in PEM format
	DefaultTTL    time.Duration // Default URL expiration time
}

CloudFrontConfig holds configuration for CloudFront service

type CloudFrontService

type CloudFrontService struct {
	// contains filtered or unexported fields
}

CloudFrontService handles CloudFront signed URL generation

func NewCloudFrontService

func NewCloudFrontService(config CloudFrontConfig, logger *zap.Logger) (*CloudFrontService, error)

NewCloudFrontService creates a new CloudFront service

func (*CloudFrontService) GetExpirationTime

func (c *CloudFrontService) GetExpirationTime(ttl time.Duration) time.Time

GetExpirationTime returns the expiration time for a given TTL

func (*CloudFrontService) SignBatchURLs

func (c *CloudFrontService) SignBatchURLs(resourcePaths []string, ttl time.Duration) (map[string]string, error)

SignBatchURLs signs multiple URLs at once (for preloading)

func (*CloudFrontService) SignStreamingURL

func (c *CloudFrontService) SignStreamingURL(mediaID, format string, quality *string, ttl time.Duration) (string, error)

SignStreamingURL generates a signed URL for streaming content

func (*CloudFrontService) SignURL

func (c *CloudFrontService) SignURL(resourcePath string, expireTime time.Time) (string, error)

SignURL generates a signed CloudFront URL with custom expiration

func (*CloudFrontService) SignURLWithDefaultTTL

func (c *CloudFrontService) SignURLWithDefaultTTL(resourcePath string) (string, error)

SignURLWithDefaultTTL generates a signed URL with the default TTL

type Config

type Config struct {
	Endpoint          string // MediaConvert endpoint
	Role              string // IAM role ARN for MediaConvert
	DestinationBucket string // S3 bucket for output
	DestinationPrefix string // S3 prefix for output
	Queue             string // MediaConvert queue ARN (optional)
}

Config holds configuration for the transcoding service

type JobStatus

type JobStatus struct {
	JobID             string
	MediaConvertJobID string
	Status            string // "SUBMITTED", "PROGRESSING", "COMPLETE", "ERROR"
	PercentComplete   int
	ErrorMessage      string
	Outputs           []OutputInfo
	CreatedAt         time.Time
	CompletedAt       *time.Time
}

JobStatus represents the status of a transcoding job

type ManifestConfig

type ManifestConfig struct {
	Bucket    string // S3 bucket for manifests
	CDNDomain string // CloudFront domain (optional)
}

ManifestConfig holds configuration for manifest service

type ManifestInfo

type ManifestInfo struct {
	MediaID         string
	HLSMasterURL    string
	DASHManifestURL string
	Variants        []VariantInfo
	ThumbnailURLs   []string
	GeneratedAt     time.Time
}

ManifestInfo contains information about generated manifests

type ManifestService

type ManifestService struct {
	// contains filtered or unexported fields
}

ManifestService handles HLS and DASH manifest operations

func NewManifestService

func NewManifestService(s3Client s3API, config ManifestConfig, logger *zap.Logger) *ManifestService

NewManifestService creates a new manifest service

func (*ManifestService) GenerateDASHManifest

func (m *ManifestService) GenerateDASHManifest(ctx context.Context, mediaID string, outputPrefix string, variants []VariantInfo, duration int) error

GenerateDASHManifest generates a DASH manifest from variants

func (*ManifestService) GenerateHLSMasterPlaylist

func (m *ManifestService) GenerateHLSMasterPlaylist(ctx context.Context, mediaID string, outputPrefix string, variants []VariantInfo) error

GenerateHLSMasterPlaylist generates an HLS master playlist from variants

func (*ManifestService) GetManifestInfo

func (m *ManifestService) GetManifestInfo(ctx context.Context, mediaID string, outputPrefix string) (*ManifestInfo, error)

GetManifestInfo retrieves manifest information for a media item

func (*ManifestService) PreloadManifests

func (m *ManifestService) PreloadManifests(ctx context.Context, mediaIDs []string) error

PreloadManifests downloads manifests to warm up CDN cache

type OutputInfo

type OutputInfo struct {
	Quality     string
	Format      string
	S3Key       string
	Width       int
	Height      int
	Bitrate     int
	FileSize    int64
	ManifestURL string
}

OutputInfo contains information about a transcoded output

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides AWS MediaConvert transcoding operations

func NewService

func NewService(awsConfig aws.Config, config Config, logger *zap.Logger) (*Service, error)

NewService creates a new transcoding service

func (*Service) CancelJob

func (s *Service) CancelJob(ctx context.Context, mediaConvertJobID string) error

CancelJob cancels a transcoding job

func (*Service) ConvertToTranscodingJob

func (s *Service) ConvertToTranscodingJob(req *TranscodeRequest, result *TranscodeResult) *models.TranscodingJob

ConvertToTranscodingJob converts a transcode result to a storage model

func (*Service) GetJobStatus

func (s *Service) GetJobStatus(ctx context.Context, mediaConvertJobID string) (*JobStatus, error)

GetJobStatus retrieves the status of a transcoding job

func (*Service) SubmitJob

func (s *Service) SubmitJob(ctx context.Context, req *TranscodeRequest) (*TranscodeResult, error)

SubmitJob submits a transcoding job to AWS MediaConvert

type TranscodeRequest

type TranscodeRequest struct {
	MediaID        string
	UserID         string
	Username       string
	SourceBucket   string
	SourceKey      string
	ContentType    string
	Duration       int
	Width          int
	Height         int
	QualityLevels  []string // ["480p", "720p", "1080p"]
	GenerateHLS    bool
	GenerateDASH   bool
	ThumbnailCount int
}

TranscodeRequest represents a request to transcode media

type TranscodeResult

type TranscodeResult struct {
	JobID             string
	MediaConvertJobID string
	OutputBucket      string
	OutputPrefix      string
	EstimatedCostUSD  float64
	EstimatedDuration time.Duration
	QualityLevels     []string
	Status            string
}

TranscodeResult contains the results of a transcode job submission

type VariantInfo

type VariantInfo struct {
	Quality        string
	Width          int
	Height         int
	Bitrate        int
	Codec          string
	HLSPlaylistURL string
	DASHSegmentURL string
}

VariantInfo contains information about a specific quality variant

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL