Documentation ¶
Overview ¶
Package thumbnailer provides a more efficient media thumbnailer than \ available with native Go processing libraries through ffmpeg bindings.
Index ¶
- Variables
- func DetectMIME(rs io.ReadSeeker, accepted map[string]bool) (mime, ext string, err error)
- func GetZipReader(rs io.ReadSeeker) (zr *zipReader, err error)
- func RegisterMatcher(m Matcher)
- func RegisterProcessor(mime string, fn Processor)
- type AVError
- type Dims
- type ErrArchive
- type ErrCoverArt
- type ErrInvalidImage
- type ErrUnsupportedMIME
- type FFContext
- func (c *FFContext) Close()
- func (c *FFContext) CodecName(typ FFMediaType) (codec string, err error)
- func (c *FFContext) CoverArt() []byte
- func (c *FFContext) Dims() (dims Dims, err error)
- func (c *FFContext) HasCoverArt() bool
- func (c *FFContext) HasStream(typ FFMediaType) (bool, error)
- func (c *FFContext) Length() time.Duration
- func (c *FFContext) Meta() (m Meta)
- func (c *FFContext) Thumbnail(dims Dims) (thumb image.Image, err error)
- type FFMediaType
- type Matcher
- type MatcherFunc
- type Meta
- type Options
- type Processor
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( ErrTooWide = ErrInvalidImage("image too wide") ErrTooTall = ErrInvalidImage("image too tall") ErrThumbnailingUnknown = errors.New("unknown thumbnailing error") // ErrCantThumbnail denotes the input file was valid but no thumbnail could // be generated for it (example: audio file with no cover art). ErrCantThumbnail = errors.New("thumbnail can't be generated") // ErrGetFrame denotes an unknown failure to retrieve a video frame ErrGetFrame = errors.New("failed to get frame") // ErrStreamNotFound denotes no steam of this media type was found ErrStreamNotFound = errors.New("no stream of this type found") )
Thumbnailing errors
Functions ¶
func DetectMIME ¶
DetectMIME detects the MIME typ of the rs.
accepted: if not nil, specifies MIME types to not reject with ErrUnsupportedMIME
func GetZipReader ¶
func GetZipReader(rs io.ReadSeeker) (zr *zipReader, err error)
Obtain io.ReaderAt and find out the size of the file
func RegisterMatcher ¶
func RegisterMatcher(m Matcher)
RegisterMatcher adds an extra magic prefix-based MIME type matcher to the default set with an included canonical file extension.
Not safe to use concurrently with file processing.
func RegisterProcessor ¶
RegisterProcessor registers a file processor for a specific MIME type. Can be used to add support for additional MIME types or as an override.
Not safe to use concurrently with file processing.
Types ¶
type AVError ¶
AVError converts an FFmpeg error code to a Go error with a human-readable error message
type ErrArchive ¶
type ErrArchive struct {
Err error
}
ErrArchive wraps an error that happened during thumbnailing a file in zip archive
func (ErrArchive) Error ¶
func (e ErrArchive) Error() string
type ErrCoverArt ¶
type ErrCoverArt struct {
Err error
}
ErrorCovert wraps an error that happened during cover art thumbnailing
func (ErrCoverArt) Error ¶
func (e ErrCoverArt) Error() string
type ErrInvalidImage ¶
type ErrInvalidImage string
Indicates and invalid image has been passed for processing
func (ErrInvalidImage) Error ¶
func (e ErrInvalidImage) Error() string
type ErrUnsupportedMIME ¶
type ErrUnsupportedMIME string
Indicates the MIME type of the file could not be detected as a supported type or was not in the AcceptedMimeTypes list, if defined.
func (ErrUnsupportedMIME) Error ¶
func (e ErrUnsupportedMIME) Error() string
type FFContext ¶
type FFContext struct {
// contains filtered or unexported fields
}
FFContext is a wrapper for passing Go I/O interfaces to C
func NewFFContext ¶
func NewFFContext(rs io.ReadSeeker) (*FFContext, error)
NewFFContext constructs a new AVIOContext and AVFormatContext. It is the responsibility of the caller to call Close() after finishing using the context.
func (*FFContext) Close ¶
func (c *FFContext) Close()
Close closes and frees memory allocated for c. c should not be used after this point.
func (*FFContext) CodecName ¶
func (c *FFContext) CodecName(typ FFMediaType) (codec string, err error)
CodecName returns the codec name of the best stream of type typ
func (*FFContext) HasCoverArt ¶
HasCoverArt return whether file has cover art in it
func (*FFContext) HasStream ¶
func (c *FFContext) HasStream(typ FFMediaType) (bool, error)
HasStream returns, if the file has a decodeable stream of the passed type
type FFMediaType ¶
type FFMediaType int8
FFMediaType correspond to the AVMediaType enum in ffmpeg
const ( FFUnknown FFMediaType = iota - 1 FFVideo FFAudio )
Correspond to the AVMediaType enum in ffmpeg
type Matcher ¶
Matcher takes up to the first 4 KB of a file and returns the MIME type and canonical extension, that were matched. Empty string indicates no match.
type MatcherFunc ¶
MatcherFunc is an adapter that allows using functions as Matcher
type Options ¶
type Options struct { // Maximum source image dimensions. Any image exceeding either will be // rejected and return with ErrTooTall or ErrTooWide. // If not set, all image processing will not be restricted by that // dimension. MaxSourceDims Dims // Target Maximum dimensions for the thumbnail. // // This defines the bounding box of the thumbnail. The thumbnail will be // scaled down until both dimensions fit the bounding box. // To scale only by one dimension, specify the other as math.MaxUint32. // // Defaults to 150x150, if unset. ThumbDims Dims // MIME types to accept for thumbnailing. // If nil, all MIME types will be processed. // // To process MIME types that are a subset of archive files, like // "application/x-cbz", "application/x-cbr", "application/x-cb7" and // "application/x-cbt", you must accept the corresponding archive type // such as "application/zip" or leave this nil. AcceptedMimeTypes map[string]bool }
Options suplied to the Thumbnail function
type Processor ¶
Processor is a specialized file processor for a specific file type. Returns thumbnail and error.
io.ReadSeeker is the start position, when passed to Processor.
type Source ¶
type Source struct {
// Some containers may or may not have either
HasAudio, HasVideo bool
// Length of the stream. Applies to audio and video files.
Length time.Duration
// Source dimensions, if file is image or video
Dims
// Mime type of the source file
Mime string
// Canonical file extension
Extension string
// Codec of the source file when applicable
Codec string
// Optional metadata
Meta
}
Source stores information about the source file