convert

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransformResolutionAuto = -1
)

Variables

This section is empty.

Functions

func InitializeFFMPEG

func InitializeFFMPEG() (string, error)

Extracts FFMPEG executable and dependencies from cache. Returns FFMPEG executable path

Types

type Converter

type Converter struct {
	InputFormat FFMPEGFormat

	// Transformation to be applied. map[ uniqueTransformationID ] *Transformation
	Transform map[string]*Transformation
}

func FromContentType

func FromContentType(contentType string) (*Converter, error)

Create a converter according to a content type.

func NewConverter

func NewConverter() *Converter

func NewImageConverter

func NewImageConverter() *Converter

func (*Converter) AddTransformation

func (cnv *Converter) AddTransformation(t *Transformation) string

Add transformation to the converter. Returns a unique transformation ID.

func (*Converter) Convert

func (cnv *Converter) Convert(input []byte, endtask chan bool) ConvertionResult

type ConvertionResult

type ConvertionResult struct {
	Success bool
	Error   error

	TransformedResults map[string]*TransformationResult
}

func (*ConvertionResult) UnifyDuplicates

func (cres *ConvertionResult) UnifyDuplicates()

type FFMPEGCodec

type FFMPEGCodec string
const (
	FFMPEGCodecNone FFMPEGCodec = ""
	FFMPEGCodecWebp FFMPEGCodec = "webp"
	FFMPEGCodecPng  FFMPEGCodec = "png"
	FFMPEGCodecJpg  FFMPEGCodec = "mjpeg"
)

func (FFMPEGCodec) ContentType

func (codec FFMPEGCodec) ContentType() string

func (FFMPEGCodec) FileExtension

func (codec FFMPEGCodec) FileExtension() string

type FFMPEGCodecType

type FFMPEGCodecType string
const (
	FFMPEGCodecTypeVideo FFMPEGCodecType = "v"
	FFMPEGCodecTypeAudio FFMPEGCodecType = "a"
)

type FFMPEGFormat

type FFMPEGFormat string
const (
	FFMPEGFormatNone      FFMPEGFormat = ""
	FFMPEGFormatImagePipe FFMPEGFormat = "image2pipe"
	FFMPEGFormatImageFile FFMPEGFormat = "image2"
)

func FormatFromContentType

func FormatFromContentType(contentType string) FFMPEGFormat

Detect the processing format from the content type. This is only used to detect input file format. Detected format wont work for output file formats.

Returns FFMPEGFormat in pipe mode. Use FFMPEGFormat.ToFile() to get the corresponding file mode.

func (FFMPEGFormat) ToFile

func (fm FFMPEGFormat) ToFile() FFMPEGFormat

func (FFMPEGFormat) ToPipe

func (fm FFMPEGFormat) ToPipe() FFMPEGFormat

type TransformQuality added in v0.1.1

type TransformQuality int

Image / Audio / Video quality parameter for FFMPEG. Must be in range of 0 to 100, where 0 is lowest and 100 is highest quality.

FFMPEGQualityHigh (80) is the default value.

const (
	TransformQualityNone  TransformQuality = 0
	TransformQualityLow   TransformQuality = 55
	TransformQualityMid   TransformQuality = 70
	TransformQualityHigh  TransformQuality = 80
	TransformQualityExtra TransformQuality = 90
)

func (TransformQuality) To100Scale added in v0.1.1

func (ql TransformQuality) To100Scale() string

Returns the quality parameter for FFMPEG in 0 to 100 scale. Useful for formats like WEBP

func (TransformQuality) ToArgs added in v0.1.1

func (ql TransformQuality) ToArgs(codec FFMPEGCodec, codecType FFMPEGCodecType) []string

Returns the quality, compression selection command line arguments for FFMPEG, depending on the FFMPEG Codec.

Examples:

for MP4, the return value could be [ -qscale:v 3 ]

for WEBP, the return value could be [ -quality 80 -compression_level 6 ]

func (TransformQuality) ToQScale added in v0.1.1

func (ql TransformQuality) ToQScale() string

Returns the quality parameter for FFMPEG Q-Scale. Value ranges from 0 to 31, where 31 is the lowest quality.

type TransformResolution added in v0.1.1

type TransformResolution struct {
	Width  int
	Height int
}

type Transformation

type Transformation struct {
	Format     FFMPEGFormat
	VideoCodec FFMPEGCodec
	AudioCodec FFMPEGCodec
	Resolution *TransformResolution
	Quality    TransformQuality
	// contains filtered or unexported fields
}

func NewTransformation

func NewTransformation() *Transformation

func (*Transformation) ContentType

func (tr *Transformation) ContentType(contentType string) *Transformation

Set the content type for transformation

func (*Transformation) GetContentType added in v0.1.1

func (tr *Transformation) GetContentType() string

func (*Transformation) GetFileExtention

func (tr *Transformation) GetFileExtention() string

func (*Transformation) NoScaling

func (tr *Transformation) NoScaling() *Transformation

func (*Transformation) ResolutionByHeight added in v0.1.1

func (tr *Transformation) ResolutionByHeight(height int) *Transformation

func (*Transformation) ResolutionByWidth added in v0.1.1

func (tr *Transformation) ResolutionByWidth(width int) *Transformation

func (*Transformation) SetQuality

func (tr *Transformation) SetQuality(quality TransformQuality) *Transformation

type TransformationResult

type TransformationResult struct {
	Transformation
	FileExtension string
	Data          *[]byte
}

Jump to

Keyboard shortcuts

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