mediaprocessor

package
v0.0.0-...-0728cc5 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var STARTEDLIBVIPS bool

Functions

This section is empty.

Types

type CustomOptions

type CustomOptions struct {
	Pass        *int    `flag:"-pass"`
	PassLogFile *string `flag:"-passlogfile"`
	Crf         *int    `flag:"-crf"`      // Work around bug with *uint32 in ffmpeg.Options
	CpuUsed     *int    `flag:"-cpu-used"` // Used with AV1 codec
	QScaleVideo *int    `flag:"-qscale:v"` // Used for thumbnails
}

TODO: Submit PR

func (CustomOptions) GetStrArguments

func (opts CustomOptions) GetStrArguments() []string

type FSConfig

type FSConfig struct {
	InputDir       string
	OutputDir      string
	MoveProcessed  bool
	ProcessedDir   string
	Watch          bool
	Workers        int
	DebugFilenames bool
}

FSConfig contains the filesystem-related parameters used when processing media

type FileOutputType

type FileOutputType string

FileOutputType is the file extension of the output media file. For images, this represents the image format. For videos, this represents the container format.

const (
	JPG  FileOutputType = "jpg"
	WebP FileOutputType = "webp"
	MP4  FileOutputType = "mp4"
	WebM FileOutputType = "webm"
)

func (FileOutputType) GetMediaType

func (f FileOutputType) GetMediaType() MediaType

GetMediaType returns the MediaType of a given FileOutputType

type ImageBasic

type ImageBasic struct{}

ImageBasic is an ImageProcessor which uses a mix of Go image generation libraries

func (*ImageBasic) Resize

func (i *ImageBasic) Resize(m *MediaJob) (filenames []string, err error)

ProcessImage processes a single image

type ImageConfiguration

type ImageConfiguration struct {
	MaxWidth int
	Quality  int
	FileType FileOutputType
}

ImageConfiguration describes output size, quality, and format for an output image file

func (*ImageConfiguration) OutputFileSuffix

func (i *ImageConfiguration) OutputFileSuffix(debugFilename bool) string

func (*ImageConfiguration) Validate

func (i *ImageConfiguration) Validate() error

type ImageProcessor

type ImageProcessor interface {
	Resize(*MediaJob) ([]string, error)
}

ImageProcessor is an interface for types which can process images

type ImageVips

type ImageVips struct{}

ImageVips is an ImageProcessor which uses libvips

func (*ImageVips) Resize

func (i *ImageVips) Resize(m *MediaJob) (filenames []string, err error)

type MediaConfig

type MediaConfig struct {
	ImageConfigurations []*ImageConfiguration
	VideoConfigurations []*VideoConfiguration
}

MediaConfig contains the image and video output parameters used when encoding media

type MediaConfiguration

type MediaConfiguration interface {
	Validate() error              // Return an error if the supplied media configuration is invalid
	OutputFileSuffix(bool) string // Return the file suffix for a given media configuration. e.g. -100px.jpg
}

type MediaJob

type MediaJob struct {
	MediaConfig    *MediaConfig
	FSConfig       *FSConfig
	S3Client       *s3.S3Client
	InputFile      *pixelio.InputFile
	MediaProcessor *MediaProcessor
}

MediaJob represents an encoding job to perform, and contains types representing the target file, where the files should be written, encoding settings, and which processor to use.

func (*MediaJob) CheckOutputDir

func (m *MediaJob) CheckOutputDir()

CheckOutputDir ensures that a job's output subdirectory exists

func (*MediaJob) OutputPath

func (m *MediaJob) OutputPath(mediaConfiguration MediaConfiguration) string

OutputPath returns the full output path for a MediaJob with a specific MediaConfiguration e.g. output/subdir1/sunset-x100.jpg

func (*MediaJob) ProcessImage

func (m *MediaJob) ProcessImage() (filenames []string, err error)

ProcessImage dispatches an image resize job to the configured ImageProcessor

func (*MediaJob) ProcessVideo

func (m *MediaJob) ProcessVideo() (filenames []string, errs error)

ProcessVideo dispatchse a video resize job to the configured VideoProcessor

type MediaProcessor

type MediaProcessor struct {
	Image ImageProcessor
	Video VideoProcessor
}

func New

func New() (mediaProcessor *MediaProcessor)

type MediaType

type MediaType string

MediaType is the type of a piece of media - Image, Video, etc

const (
	Image   MediaType = "image"
	Video   MediaType = "video"
	Unknown MediaType = "unknown"
)

type VideoCodec

type VideoCodec string

VideoCodec represents the codec used to encode a video file, as part of a VideoConfiguration

const (
	H264 VideoCodec = "h264"
	H265 VideoCodec = "h265"
	VP9  VideoCodec = "vp9"
	AV1  VideoCodec = "av1"
)

func (VideoCodec) Validate

func (c VideoCodec) Validate() error

type VideoConfiguration

type VideoConfiguration struct {
	MaxWidth int
	Quality  int
	Preset   string
	FileType FileOutputType
	Codec    VideoCodec
}

VideoConfiguration describes output size, quality, format, and other information for an encoded output video file

func (*VideoConfiguration) OutputFileSuffix

func (v *VideoConfiguration) OutputFileSuffix(debugFilename bool) string

func (*VideoConfiguration) Validate

func (v *VideoConfiguration) Validate() error

Validate validates a VideoConfiguration

type VideoGoffmpeg

type VideoGoffmpeg struct{}

VideoGoffmpeg is based on github.com/xfrr/goffmpeg. This library is fairly robust, but doesn't allow custom flags to be passed.

func (*VideoGoffmpeg) Thumbnail

func (v *VideoGoffmpeg) Thumbnail(m *MediaJob, videoConfig *VideoConfiguration) (err error)

func (*VideoGoffmpeg) Transcode

func (v *VideoGoffmpeg) Transcode(m *MediaJob, videoConfig *VideoConfiguration) (err error)

type VideoGotranscoder

type VideoGotranscoder struct{}

VideoGotranscoder is based on github.com/floostack/transcoder. This library allows custom ffmpeg commands to be passed, which permits two-pass codecs such as VP9.

func (*VideoGotranscoder) Thumbnail

func (v *VideoGotranscoder) Thumbnail(m *MediaJob, videoConfig *VideoConfiguration) (err error)

func (*VideoGotranscoder) Transcode

func (v *VideoGotranscoder) Transcode(m *MediaJob, videoConfig *VideoConfiguration) (err error)

type VideoProcessor

type VideoProcessor interface {
	Thumbnail(*MediaJob, *VideoConfiguration) error
	Transcode(*MediaJob, *VideoConfiguration) error
}

VideoProcessor is an interface for types which can process videos

Jump to

Keyboard shortcuts

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