gifski

package module
v0.0.0-...-1e54b04 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

README

gif.ski

Highest-quality GIF encoder based on pngquant.

gifski converts video frames to GIF animations using pngquant's fancy features for efficient cross-frame palettes and temporal dithering. It produces animated GIFs that use thousands of colors per frame.

It's a CLI tool, but it can also be compiled as a C library for seamless use in other apps.

Download and install

See releases page for executables.

If you have Rust 1.42+, you can also get it with cargo install gifski. Run cargo build --release --features=openmp or cargo build --release --features=video,openmp to build from source.

If you have Homebrew, you can also get it with brew install gifski.

Usage

gifski is a command-line tool. There is no GUI for Windows or Linux (there is one for macOS).

The recommended way is to first export video as PNG frames. If you have ffmpeg installed, you can run in terminal:

ffmpeg -i video.webm frame%04d.png

and then make the GIF from the frames:

gifski -o anim.gif frame*.png

You can also resize frames (with -W <width in pixels> option). If the input was ever encoded using a lossy video codec it's recommended to at least halve size of the frames to hide compression artefacts and counter chroma subsampling that was done by the video codec.

See gifski -h for more options.

Building

  1. Install Rust via rustup or run rustup update. This project only supports up-to-date versions of Rust. You may get compile errors, warnings about "unstable edition", etc. if you don't run rustup update regularly.
  2. Clone the repository: git clone https://github.com/ImageOptim/gifski
  3. In the cloned directory, run: cargo build --release

Enable OpenMP by adding --features=openmp to Cargo build flags (supported on macOS and Linux with GCC). It makes encoding more than twice as fast.

Using from C

See gifski.h for the API. To build the library, run:

cargo build --release

and link with target/release/libgifski.a. Please observe the LICENSE.

License

AGPL 3 or later. Let me know if you'd like to use it in a product incompatible with this license. I can offer alternative licensing options, including commercial licenses.

With built-in video support

The tool optionally supports decoding video directly, but unfortunately it relies on ffmpeg 4.x, which may be very hard to get working, so it's not enabled by default.

You must have ffmpeg and libclang installed, both with their C headers intalled in default system include paths. Details depend on the platform and version, but you usually need to install packages such as libavformat-dev, libavfilter-dev, libavdevice-dev, libclang-dev, clang. Please note that installation of these dependencies may be quite difficult. Especially on macOS and Windows it takes expert knowledge to just get them installed without wasting several hours on endless stupid installation and compilation errors, which I can't help with.

Once you have dependencies installed, compile with cargo build --release --features=video,openmp or cargo build --release --features=video-static.

When compiled with video support ffmpeg licenses apply. You may need to have a patent license to use H.264/H.265 video (I recommend using VP9/WebM instead).

gifski -o out.gif video.mp4

Cross-compilation for iOS

Make sure you have Rust installed via rustup. Run once:

rustup target add aarch64-apple-ios

and then to build the library:

cargo build --lib --release --target=aarch64-apple-ios

The build will print "dropping unsupported crate type cdylib". This is normal and expected.

This will create a static library in ./target/aarch64-apple-ios/release/libgifski.a. You can add this library to your Xcode project. See gifski.app for an example how to use libgifski from Swift.

You can also use cargo lipo command to integrate with Xcode project to have it built automatically.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code ErrorCode
}

Error is a gifski specific error

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode is a gifski internal error code

const (
	// Ok is the success error code
	Ok ErrorCode = iota
	// NullArg one of input arguments was NULL
	NullArg
	// InvalidState a one-time function was called twice, or functions were called in wrong order
	InvalidState
	// Quant internal error related to palette quantization
	Quant
	// GIF internal error related to gif composing
	GIF
	// ThreadLost internal error related to multithreading
	ThreadLost
	// NotFound I/O error: file or directory not found
	NotFound
	// PermissionDenied I/O error: permission denied
	PermissionDenied
	// AlreadyExists I/O error: file already exists
	AlreadyExists
	// InvalidInput invalid arguments passed to function
	InvalidInput
	// TimedOut misc I/O error
	TimedOut
	// WriteZero misc I/O error
	WriteZero
	// Interrupted misc I/O error
	Interrupted
	// UnexpectedEOF misc I/O error
	UnexpectedEOF
	// Aborted progress callback returned 0, writing aborted
	Aborted
	// Other should not happen, file a bug
	Other
)

type Gifski

type Gifski struct {
	// contains filtered or unexported fields
}

Gifski abstracts the gifski API

func NewGifski

func NewGifski(settings *Settings, writer io.Writer) (*Gifski, error)

NewGifski creates a new instance of gifski with the specified settings

func (*Gifski) AddFrame

func (g *Gifski) AddFrame(frameNumber uint, width uint, height uint, pixels []byte, presentationTimeStamp float64) error

AddFrame adds a frame to the animation. This function is asynchronous.

func (*Gifski) Finish

func (g *Gifski) Finish() error

Finish returns final status of write operations.

func (*Gifski) Progress

func (g *Gifski) Progress() chan uint

Progress gets the progress channel which reports the frame index

type Settings

type Settings struct {
	// Resize to max this width if non-0
	Width uint
	// Resize to max this height if width is non-0. Note that aspect ratio is not preserved.
	Height uint
	// 1-100, but useful range is 50-100. Recommended to set to 100.
	Quality uint
	// If true, looping is disabled. Recommended false (looping on).
	Once bool
	// Lower quality, but faster encode.
	Fast bool
	// should we report progress (if so, then the progress channel must be consumed)
	ReportProgress bool
}

Settings controls the operation of gifski

Jump to

Keyboard shortcuts

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