thumbnailer

package module
v0.0.0-...-0ff8fe6 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: MIT Imports: 15 Imported by: 0

README

Thumbnailer

Fork of https://github.com/zRedShift/thumbnailer

GoDoc

Thumbnailer provides a lightning fast and memory usage efficient image, video and audio (cover art) thumbnailer via libvips and ffmpeg C bindings, with MIME sniffing (via mimemagic), and streaming I/O support.

License

MIT License.

API

See the Godoc reference.

Dependencies

  • pkg-config
  • libvips 8.7.0+ compiled with libimagequant and all the formats required
  • ffmpeg 5.0.0+ compiled with all the formats required
  • pthread

Documentation

Overview

Package thumbnailer provides a lightning fast and memory usage efficient thumbnailer via libvips and ffmpeg C bindings, with (external) MIME sniffing, and streaming I/O support. The formats available depend on the way libvips and ffmpeg are compiled.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidData            = avErrorToThumbError(avErrInvalidData)
	ErrFileFormatNotSupported = vipsErrorToThumbError(vipsError{
		domain: "VipsForeignLoad",
		error:  "the current build does not support this file format",
	})
)

Common ThumbErrors.

Functions

func CreateThumbnail

func CreateThumbnail(file *File) error

CreateThumbnail calls CreateThumbnailWithContext with a background context.

func CreateThumbnailWithContext

func CreateThumbnailWithContext(ctx context.Context, file *File) (err error)

CreateThumbnailWithContext creates a thumbnail from the supplied file (should go through FileFromReader, FromReadSeeker or FileFromPath and then ToWriter or ToPath, or equivalent for defined behaviour) and a context for interruption. Currently it's only checked if Done() in FFmpeg before blocking operations via an interrupt callback.

func DropAllVIPSCache

func DropAllVIPSCache()

DropAllVIPSCache drops the whole operation cache. Called automatically on ShutdownVips(). Some VIPS versions can't run after this operation is performed.

func InitVIPS

func InitVIPS()

InitVIPS initializes vips explicitly.

func MallocTrim

func MallocTrim(pad int) bool

MallocTrim calls glibc's malloc_trim. Go refuses to return freed C memory to the OS otherwise for some reason.

func Mallopt

func Mallopt(param MalloptParam, value int) bool

Mallopt calls glibc's mallopt. Reducing M_TOP_PAD or M_TRIM_THRESHOLD, increasing M_MMAP_THRESHOLD, and setting M_ARENA_MAX to GOMAXPROCS (it defaults to 8 * #threads), has shown good results with regards to freed memory "leaks".

func PrintAllVIPSObjects

func PrintAllVIPSObjects()

PrintAllVIPSObjects prints all objects in vips's operation cache.

func SetFFmpegLogLevel

func SetFFmpegLogLevel(logLevel AVLogLevel)

SetFFmpegLogLevel allows you to change the log level from the default (AVLogInfo).

func SetVIPSOptions

func SetVIPSOptions(options VIPSOptions)

SetVIPSOptions initializes vips with options.

func ShutdownVIPS

func ShutdownVIPS()

ShutdownVIPS shuts vips down. It can't be used again after this.

Types

type AVLogLevel

type AVLogLevel int

AVLogLevel defines the ffmpeg threshold for dumping information to stderr.

const (
	AVLogQuiet AVLogLevel = (iota - 1) * 8
	AVLogPanic
	AVLogFatal
	AVLogError
	AVLogWarning
	AVLogInfo
	AVLogVerbose
	AVLogDebug
	AVLogTrace
)

Possible values for AVLogLevel.

type Dimensions

type Dimensions struct {
	Width, Height int
}

Dimensions stores the dimensions of the file and its thumbnail (if applicable).

type File

type File struct {
	io.Reader
	io.Seeker
	Thumbnail
	mimemagic.MediaType
	Dimensions
	Orientation                 int
	Size                        int64
	Duration                    time.Duration
	Title, Artist, Path         string
	HasVideo, HasAudio, SeekEnd bool
}

File stores the io.Reader and the io.Seeker or the path to the input file (preference to the path), its dimensions after analysis (if applicable), its Media Type, resultant thumbnail, size (completely optional for FFmpeg seeking), duration and the title and artist metadata if the file is a video or audio and those exist. Setting SeekEnd to false disables FFmpeg from seeking the end, which enables partial file reading in "semi-streaming" files (incomplete files that block until more data is available but have seeking capabilities) without blocking until the file is complete. HasVideo and HasAudio indicates that the file has video and/or audio streams, but having a video stream does not guarantee a thumbnail. Orientation corresponds to the EXIF orientation of the input file.

func FileFromPath

func FileFromPath(path string) (file *File, err error)

FileFromPath takes a filepath and returns a File ready for supplying a thumbnail output via ToFile or ToPath.

func FileFromReadSeeker

func FileFromReadSeeker(r io.ReadSeeker, seekEnd bool, filename ...string) (*File, error)

FileFromReadSeeker takes an io.ReadSeeker, a boolean seekEnd, and an optional filename (for better MIME sniffing), and returns a File ready for supplying a thumbnail output via ToFile or ToPath. Setting seekEnd to false disables FFmpeg from seeking the end, which enables partial file reading in "semi-streaming" files (incomplete files that block until more data is available but have seeking capabilities) without blocking until the file is complete. Setting it to true treats the ReadSeeker like a regular file.

func FileFromReader

func FileFromReader(r io.Reader, filename ...string) (*File, error)

FileFromReader takes an io.Reader and an optional filename (for better MIME sniffing), and returns a File ready for supplying a thumbnail output via ToFile or ToPath. Without seeking, thumbnailing videos with non-sequential codecs (H.264 in some cases), will fail more than the alternatives.

func (*File) ToPath

func (f *File) ToPath(path string, size int, quality ...int) *File

ToPath directs the thumbnailer to write the resultant thumbnail to the supplied path at the target bounding box size and quality (quality corresponds to libjpeg quality for JPEG thumbnails and to libimagequant quality for PNG thumbnails).

func (*File) ToWriter

func (f *File) ToWriter(w io.Writer, size int, quality ...int) *File

ToWriter directs the thumbnailer to write the resultant thumbnail to the supplied io.Write at the target bounding box size and quality (quality corresponds to libjpeg quality for JPEG thumbnails and to libimagequant quality for PNG thumbnails).

type MalloptParam

type MalloptParam int

MalloptParam holds possible mallopt parameters.

All possible values of MalloptParam.

type ThumbError

type ThumbError struct {
	Library, Domain, Err string
	Code                 int
}

ThumbError stores the errors returned by the C Libraries used in this package.

func (*ThumbError) Error

func (t *ThumbError) Error() string

type Thumbnail

type Thumbnail struct {
	io.Writer
	Dimensions
	Quality, TargetDimensions int
	Path                      string
	HasAlpha, ThumbCreated    bool
}

Thumbnail stores the io.Writer to which to write the thumbnail, or creates it at the given path (preference to the path), its resultant dimensions, target Quality (both for JPEG and lossy PNG output), and the size of the bounding box to which the thumbnail is shrunk (TargetDimensions). HasAlpha indicates the image is a transparent PNG, JPEG if false. ThumbCreated indicates the thumbnail was created successfully.

type VIPSMemoryProfile

type VIPSMemoryProfile struct {
	Memory, MemoryHighWater int64
	Allocations, Files      int
}

VIPSMemoryProfile contains the vips memory profile.

func VIPSMemory

func VIPSMemory() VIPSMemoryProfile

VIPSMemory returns vips's internal tracked memory profile.

type VIPSOptions

type VIPSOptions struct {
	Leak                                 bool
	CacheMax, CacheMaxMem, CacheMaxFiles *int
}

VIPSOptions stores various options for vips.

Jump to

Keyboard shortcuts

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