media

package
v0.0.0-...-31ec8e6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Audio codecs.
	CodecOpus AudioCodec = "opus"
	CodecAAC  AudioCodec = "aac"

	// Video codecs.
	CodecH264 VideoCodec = "h264"
)

Variables

This section is empty.

Functions

func Convert

func Convert(ctx context.Context, data []byte, spec *Spec) ([]byte, error)

Convert processes the given data, assumed to represent a media file, according to the target specification given. For information on how these definitions affect media conversions, see the documentation for the Spec type.

func GetThumbnail

func GetThumbnail(ctx context.Context, data []byte, width, height int) ([]byte, error)

GetThumbnail returns a static JPEG image for the first frame of the given video data. If both width and height dimensions are given, the thumbnail will be resized to exactly those pixel values. If either dimension is given, the thumbnail will be resized while retaining aspect ratio. If no value is given (i.e. if both values are zero), then the thumbnail dimensions will follow input video dimensions.

func GetWaveform

func GetWaveform(ctx context.Context, data []byte, spec *Spec, maxSamples int) ([]byte, error)

GetWaveform returns a list of samples, scaled from 0 to 100, representing linear loudness values.

An error will be returned if the Spec given has no sample-rate or duration corresponding to the data given, as both these values are necessary for deriving the number of samples.

The number of samples returned will be equal to the given maximum number provided, and will be padded with 0 values if necessary.

func SetTempDirectory

func SetTempDirectory(path string) error

SetTempDirectory sets the global temporary directory used internally by media conversion commands.

Types

type AudioCodec

type AudioCodec string

AudioCodec represents the encoding method used for an audio stream.

type MIMEType

type MIMEType string

MIMEType represents a the media type for a data buffer. In general, values given concrete MIMEType identities are meant to be handled as targets for conversion and metadata extraction -- all other formats are handled on a best-case basis.

const (
	// Audio formats.
	TypeM4A MIMEType = "audio/mp4"
	TypeOgg MIMEType = "audio/ogg"

	// Video formats.
	TypeMP4 MIMEType = "video/mp4"

	// Image formats.
	TypeJPEG MIMEType = "image/jpeg"
	TypePNG  MIMEType = "image/png"
)

func (MIMEType) BaseMediaType

func (t MIMEType) BaseMediaType() MIMEType

BaseMediaType returns the media type without any additional parameters.

type Spec

type Spec struct {
	// Required parameters.
	MIME MIMEType // The MIME type for the target media.

	// Optional parameters.
	AudioCodec      AudioCodec // The codec to use for the audio stream, must be correct for the MIME type given.
	AudioChannels   int        // The number of channels for the audio stream, 1 for mono, 2 for stereo.
	AudioBitRate    int        // The bit rate for the audio stream, in kBit/second.
	AudioSampleRate int        // The sample-rate frequency for the audio stream, common values are 44100, 48000.

	VideoCodec       VideoCodec // The codec to use for the video stream, must be correct for the MIME type given.
	VideoPixelFormat string     // The pixel format used for video stream, typically 'yub420p' for MP4.
	VideoFrameRate   int        // The frame rate for the video stream, in frames/second.
	VideoWidth       int        // The width of the video stream, in pixels.
	VideoHeight      int        // The height of the video stream, in pixels.
	VideoFilter      string     // A complex filter to apply to the video stream.

	ImageWidth     int // The width of the image, in pixels.
	ImageHeight    int // The height of the image, in pixels.
	ImageQuality   int // Image quality for lossy image formats, typically a value from 1 to 100.
	ImageFrameRate int // The frame-rate for animated images.

	Duration      time.Duration // The duration of the audio or video stream.
	StripMetadata bool          // Whether or not to remove any container-level metadata present in the stream.
}

Spec represents the description of a target media file; depending on platform support and media conversion intricacies, source media files can be of any type, even types that aren't represented here. Nevertheless, it is intended that media types and codecs represented here are valid as both input and output formats.

func GetSpec

func GetSpec(ctx context.Context, data []byte) (*Spec, error)

GetSpec returns a media specification corresponding to the data given. The Spec value returned will only have its fields partially populated, as not all values can be derived accurately.

type VideoCodec

type VideoCodec string

VideoCodec represents the encoding method used for a video stream.

Jump to

Keyboard shortcuts

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