gmf

package module
v0.0.0-...-b28a7e4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2014 License: MIT Imports: 7 Imported by: 0

README

Go FFmpeg Bindings

Status: beta

It covers very basic avformat, avcodec and swscale features.
More bindings and cool features are coming soon.

Installation

Prerequisites

Current master branch requires go 1.3. If you use older version of go, checkout go1.2 branch. (It's not recommended, because this version won't be supported)

Build

build lastest version of ffmpeg, obtained from https://github.com/FFmpeg/FFmpeg
There is one required option, which is disabled by default, you should turn on: --enable-shared

E.g.:

./configure --prefix=/usr/local/ffmpeg --enable-shared
make
make install

Add pkgconfig path:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/ffmpeg/lib/pkgconfig/

Ensure, that PKG_CONFIG_PATH contains path to ffmpeg's pkgconfig folder.

# check it by running
pkg-config --libs libavformat

It should print valid path to the avformat library.

Now, just run

go get github.com/3d0c/gmf
Other methods

This package uses pkg-config way to obtain flags, includes and libraries path, so if you have ffmpeg installed, just ensure, that your installation has them (pkgconfig/ folder with proper pc files).

Usage

Please see examples and tests.

Support and Contribution

If something doesn't work, just fix it. Do not hesitate to pull request.

Credits

I borrowed the name from project, abandoned on code.google.com/p/gmf. Original code is available here in intitial commit from 03 Apr 2013.

Documentation

Overview

Format.

Index

Constants

This section is empty.

Variables

View Source
var (
	AVMEDIA_TYPE_AUDIO int32 = C.AVMEDIA_TYPE_AUDIO
	AVMEDIA_TYPE_VIDEO int32 = C.AVMEDIA_TYPE_VIDEO

	AV_PIX_FMT_YUV420P      int32 = C.AV_PIX_FMT_YUV420P
	AV_PIX_FMT_YUVJ420P     int32 = C.AV_PIX_FMT_YUVJ420P
	AV_PIX_FMT_RGB24        int32 = C.AV_PIX_FMT_RGB24
	AV_PIX_FMT_NONE         int32 = C.AV_PIX_FMT_NONE
	FF_PROFILE_MPEG4_SIMPLE int   = C.FF_PROFILE_MPEG4_SIMPLE
	AV_NOPTS_VALUE          int   = C.AV_NOPTS_VALUE
)
View Source
var (
	AV_CODEC_ID_MPEG1VIDEO   int   = C.AV_CODEC_ID_MPEG1VIDEO
	AV_CODEC_ID_MPEG2VIDEO   int   = C.AV_CODEC_ID_MPEG2VIDEO
	AV_CODEC_ID_H264         int   = C.AV_CODEC_ID_H264
	AV_CODEC_ID_MPEG4        int   = C.AV_CODEC_ID_MPEG4
	AV_CODEC_ID_JPEG2000     int   = C.AV_CODEC_ID_JPEG2000
	CODEC_FLAG_GLOBAL_HEADER int   = C.CODEC_FLAG_GLOBAL_HEADER
	FF_MB_DECISION_SIMPLE    int   = C.FF_MB_DECISION_SIMPLE
	FF_MB_DECISION_BITS      int   = C.FF_MB_DECISION_BITS
	FF_MB_DECISION_RD        int   = C.FF_MB_DECISION_RD
	AV_SAMPLE_FMT_S16        int32 = C.AV_SAMPLE_FMT_S16
)
View Source
var (
	AVFMT_FLAG_GENPTS int = C.AVFMT_FLAG_GENPTS
	AVFMTCTX_NOHEADER int = C.AVFMTCTX_NOHEADER
)
View Source
var (
	SWS_FAST_BILINEAR int = C.SWS_FAST_BILINEAR
	SWS_BILINEAR      int = C.SWS_BILINEAR
	SWS_BICUBIC       int = C.SWS_BICUBIC
	SWS_X             int = C.SWS_X
	SWS_POINT         int = C.SWS_POINT
	SWS_AREA          int = C.SWS_AREA
	SWS_BICUBLIN      int = C.SWS_BICUBLIN
	SWS_GAUSS         int = C.SWS_GAUSS
	SWS_SINC          int = C.SWS_SINC
	SWS_LANCZOS       int = C.SWS_LANCZOS
	SWS_SPLINE        int = C.SWS_SPLINE
)
View Source
var (
	AV_TIME_BASE   int        = C.AV_TIME_BASE
	AV_TIME_BASE_Q AVRational = AVRational{1, C.int(AV_TIME_BASE)}
)
View Source
var (
	IO_BUFFER_SIZE int = 32768
)

Functions

func AvError

func AvError(averr int) error

func GenSyntVideo

func GenSyntVideo(w, h int, fmt int32) chan *Frame

Synthetic video generator. It produces 25 iteratable frames. Used for tests.

func GetSampleFmtName

func GetSampleFmtName(fmt int32) string

func InitDesc

func InitDesc()

func NewSample

func NewSample(nbSamples, nbChannels int, format SampleFmt) error

func Rescale

func Rescale(a, b, c int) int

func RescaleDelta

func RescaleDelta(inTb AVRational, inTs int, fsTb AVRational, duration int, last *int, outTb AVRational) int

func RescaleQ

func RescaleQ(a int, encBase AVRational, stBase AVRational) int

Types

type AVIOContext

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

func NewAVIOContext

func NewAVIOContext(ctx *FmtCtx, handlers *AVIOHandlers) (*AVIOContext, error)

AVIOContext constructor. Use it only if You need custom IO behaviour!

func (*AVIOContext) Free

func (this *AVIOContext) Free()

type AVIOHandlers

type AVIOHandlers struct {
	ReadPacket  func() ([]byte, int)
	WritePacket func([]byte)
	Seek        func(int64, int) int64
}

Functions prototypes for custom IO. Implement necessary prototypes and pass instance pointer to NewAVIOContext.

E.g.:

func gridFsReader() ([]byte, int) {
	... implementation ...
	return data, length
}

avoictx := NewAVIOContext(ctx, &AVIOHandlers{ReadPacket: gridFsReader})

type AVR

type AVR struct {
	Num int
	Den int
}

func (AVR) AVRational

func (this AVR) AVRational() AVRational

type AVRational

type AVRational C.struct_AVRational

func (AVRational) AVR

func (this AVRational) AVR() AVR

type Codec

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

func NewDecoder

func NewDecoder(i interface{}) (*Codec, error)

func NewEncoder

func NewEncoder(i interface{}) (*Codec, error)

func (*Codec) Id

func (this *Codec) Id() int

func (*Codec) IsExperimental

func (this *Codec) IsExperimental() bool

func (*Codec) LongName

func (this *Codec) LongName() string

func (*Codec) Name

func (this *Codec) Name() string

func (*Codec) Type

func (this *Codec) Type() int

type CodecCtx

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

func NewCodecCtx

func NewCodecCtx(codec *Codec, options ...[]*Option) *CodecCtx

func (*CodecCtx) BitRate

func (this *CodecCtx) BitRate() int

func (*CodecCtx) ChannelLayout

func (this *CodecCtx) ChannelLayout() int

func (*CodecCtx) Channels

func (this *CodecCtx) Channels() int

func (*CodecCtx) Close

func (this *CodecCtx) Close()

func (*CodecCtx) CopyBasic

func (this *CodecCtx) CopyBasic(ist *Stream) *CodecCtx

func (*CodecCtx) CopyExtra

func (this *CodecCtx) CopyExtra(ist *Stream) *CodecCtx

func (*CodecCtx) Dump

func (this *CodecCtx) Dump()

func (*CodecCtx) FlushBuffers

func (this *CodecCtx) FlushBuffers()

func (*CodecCtx) FrameSize

func (this *CodecCtx) FrameSize() int

func (*CodecCtx) Free

func (this *CodecCtx) Free()

func (*CodecCtx) Height

func (this *CodecCtx) Height() int

func (*CodecCtx) Id

func (this *CodecCtx) Id() int

func (*CodecCtx) IsOpen

func (this *CodecCtx) IsOpen() bool

func (*CodecCtx) Open

func (this *CodecCtx) Open(dict *Dict) error

func (*CodecCtx) PixFmt

func (this *CodecCtx) PixFmt() int32

func (*CodecCtx) Profile

func (this *CodecCtx) Profile() int

func (*CodecCtx) Release

func (this *CodecCtx) Release()

func (*CodecCtx) SampleFmt

func (this *CodecCtx) SampleFmt() int32

func (*CodecCtx) SampleRate

func (this *CodecCtx) SampleRate() int

func (*CodecCtx) SelectChannelLayout

func (this *CodecCtx) SelectChannelLayout() int

func (*CodecCtx) SelectSampleRate

func (this *CodecCtx) SelectSampleRate() int

func (*CodecCtx) SetBitRate

func (this *CodecCtx) SetBitRate(val int) *CodecCtx

func (*CodecCtx) SetChannels

func (this *CodecCtx) SetChannels(val int) *CodecCtx

func (*CodecCtx) SetDimension

func (this *CodecCtx) SetDimension(w, h int) *CodecCtx

func (*CodecCtx) SetFlag

func (this *CodecCtx) SetFlag(flag int) *CodecCtx

func (*CodecCtx) SetGopSize

func (this *CodecCtx) SetGopSize(val int) *CodecCtx

func (*CodecCtx) SetHasBframes

func (this *CodecCtx) SetHasBframes(val int) *CodecCtx

func (*CodecCtx) SetHeight

func (this *CodecCtx) SetHeight(val int) *CodecCtx

func (*CodecCtx) SetMaxBFrames

func (this *CodecCtx) SetMaxBFrames(val int) *CodecCtx

func (*CodecCtx) SetMbDecision

func (this *CodecCtx) SetMbDecision(val int) *CodecCtx

func (*CodecCtx) SetOpt

func (this *CodecCtx) SetOpt()

@todo

func (*CodecCtx) SetPixFmt

func (this *CodecCtx) SetPixFmt(val int32) *CodecCtx

func (*CodecCtx) SetProfile

func (this *CodecCtx) SetProfile(profile int) *CodecCtx

func (*CodecCtx) SetSampleFmt

func (this *CodecCtx) SetSampleFmt(val int32) *CodecCtx

func (*CodecCtx) SetSampleRate

func (this *CodecCtx) SetSampleRate(val int) *CodecCtx

func (*CodecCtx) SetStrictCompliance

func (this *CodecCtx) SetStrictCompliance(val int) *CodecCtx

func (*CodecCtx) SetTimeBase

func (this *CodecCtx) SetTimeBase(val AVR) *CodecCtx

func (*CodecCtx) SetWidth

func (this *CodecCtx) SetWidth(val int) *CodecCtx

func (*CodecCtx) TimeBase

func (this *CodecCtx) TimeBase() AVRational

func (*CodecCtx) Type

func (this *CodecCtx) Type() int32

func (*CodecCtx) Width

func (this *CodecCtx) Width() int

type CodecDescriptor

type CodecDescriptor struct {
	IsEncoder bool
	// contains filtered or unexported fields
}

func (*CodecDescriptor) Id

func (this *CodecDescriptor) Id() int

func (*CodecDescriptor) LongName

func (this *CodecDescriptor) LongName() string

func (*CodecDescriptor) Name

func (this *CodecDescriptor) Name() string

func (*CodecDescriptor) Props

func (this *CodecDescriptor) Props() int

func (*CodecDescriptor) Type

func (this *CodecDescriptor) Type() int

type Dict

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

func NewDict

func NewDict(pairs []Pair) *Dict

type FmtCtx

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

func NewCtx

func NewCtx() *FmtCtx

@todo return error if avCtx is null @todo start_time is it needed?

func NewInputCtx

func NewInputCtx(filename string) (*FmtCtx, error)

Just a helper for NewCtx().OpenInput()

func NewOutputCtx

func NewOutputCtx(i interface{}) (*FmtCtx, error)

func (*FmtCtx) CloseInput

func (this *FmtCtx) CloseInput()

func (*FmtCtx) CloseOutput

func (this *FmtCtx) CloseOutput()

func (*FmtCtx) Dump

func (this *FmtCtx) Dump()

func (*FmtCtx) DumpAv

func (this *FmtCtx) DumpAv()

func (*FmtCtx) Duration

func (this *FmtCtx) Duration() int

func (*FmtCtx) FindStreamInfo

func (this *FmtCtx) FindStreamInfo() error

func (*FmtCtx) Free

func (this *FmtCtx) Free()

func (*FmtCtx) GetBestStream

func (this *FmtCtx) GetBestStream(typ int32) (*Stream, error)

func (*FmtCtx) GetStream

func (this *FmtCtx) GetStream(idx int) (*Stream, error)

func (*FmtCtx) IsGlobalHeader

func (this *FmtCtx) IsGlobalHeader() bool

func (*FmtCtx) IsNoFile

func (this *FmtCtx) IsNoFile() bool

func (*FmtCtx) NewStream

func (this *FmtCtx) NewStream(c *Codec) *Stream

func (*FmtCtx) OpenInput

func (this *FmtCtx) OpenInput(filename string) error

func (*FmtCtx) Packets

func (this *FmtCtx) Packets() chan *Packet

func (*FmtCtx) SeekFile

func (this *FmtCtx) SeekFile(ist *Stream, minTs, maxTs int, flag int) error

func (*FmtCtx) SeekFrameAt

func (this *FmtCtx) SeekFrameAt(sec int, streamIndex int) error

func (*FmtCtx) SetDebug

func (this *FmtCtx) SetDebug(val int) *FmtCtx

func (*FmtCtx) SetFlag

func (this *FmtCtx) SetFlag(flag int) *FmtCtx

func (*FmtCtx) SetInputFormat

func (this *FmtCtx) SetInputFormat(name string) error

func (*FmtCtx) SetOformat

func (this *FmtCtx) SetOformat(ofmt *OutputFmt) error

func (*FmtCtx) SetPb

func (this *FmtCtx) SetPb(val *AVIOContext) *FmtCtx

func (*FmtCtx) SetStartTime

func (this *FmtCtx) SetStartTime(val int) *FmtCtx

func (*FmtCtx) StartTime

func (this *FmtCtx) StartTime() int

func (*FmtCtx) StreamsCnt

func (this *FmtCtx) StreamsCnt() int

Original structure member is called instead of len(this.streams) because there is no initialized Stream wrappers in input context.

func (*FmtCtx) TsOffset

func (this *FmtCtx) TsOffset(stime int) int

func (*FmtCtx) WriteHeader

func (this *FmtCtx) WriteHeader() error

func (*FmtCtx) WritePacket

func (this *FmtCtx) WritePacket(p *Packet) error

func (*FmtCtx) WriteTrailer

func (this *FmtCtx) WriteTrailer()

type Frame

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

func NewFrame

func NewFrame() *Frame

func (*Frame) Channels

func (this *Frame) Channels() int

func (*Frame) Clone

func (this *Frame) Clone() *Frame

func (*Frame) Encode

func (this *Frame) Encode(cc *CodecCtx) (*Packet, bool, error)

func (*Frame) Flush

func (this *Frame) Flush(cc *CodecCtx) (*Packet, bool, error)

func (*Frame) Format

func (this *Frame) Format() int

AVPixelFormat for video frames, AVSampleFormat for audio

func (*Frame) Free

func (this *Frame) Free()

func (*Frame) Height

func (this *Frame) Height() int

func (*Frame) ImgAlloc

func (this *Frame) ImgAlloc() error

func (*Frame) KeyFrame

func (this *Frame) KeyFrame() int

func (*Frame) LineSize

func (this *Frame) LineSize(idx int) int

func (*Frame) NbSamples

func (this *Frame) NbSamples() int

func (*Frame) PktDts

func (this *Frame) PktDts() int

func (*Frame) PktDuration

func (this *Frame) PktDuration() int

func (*Frame) PktPos

func (this *Frame) PktPos() int

func (*Frame) PktPts

func (this *Frame) PktPts() int

func (*Frame) Pts

func (this *Frame) Pts() int

func (*Frame) SetBestPts

func (this *Frame) SetBestPts()

func (*Frame) SetChannelLayout

func (this *Frame) SetChannelLayout(val int) *Frame

func (*Frame) SetChannels

func (this *Frame) SetChannels(val int) *Frame

func (*Frame) SetData

func (this *Frame) SetData(idx int, lineSize int, data int) *Frame

func (*Frame) SetFormat

func (this *Frame) SetFormat(val int32) *Frame

func (*Frame) SetHeight

func (this *Frame) SetHeight(val int) *Frame

func (*Frame) SetNbSamples

func (this *Frame) SetNbSamples(val int) *Frame

func (*Frame) SetPktDts

func (this *Frame) SetPktDts(val int)

func (*Frame) SetPktPts

func (this *Frame) SetPktPts(val int)

func (*Frame) SetPts

func (this *Frame) SetPts(val int)

func (*Frame) SetQuality

func (this *Frame) SetQuality(val int) *Frame

func (*Frame) SetWidth

func (this *Frame) SetWidth(val int) *Frame

func (*Frame) TimeStamp

func (this *Frame) TimeStamp() int

func (*Frame) Unref

func (this *Frame) Unref()

func (*Frame) Width

func (this *Frame) Width() int

type Image

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

func NewImage

func NewImage(w, h int, pixFmt int32, align int) (*Image, error)

@todo find better way to do allocation

func (*Image) Copy

func (this *Image) Copy(frame *Frame)

func (*Image) Free

func (this *Image) Free()

type Option

type Option struct {
	Key string
	Val interface{}
}

func (*Option) Set

func (this *Option) Set(ctx interface{})

type Options

type Options struct{}

@todo remove from code

type OutputFmt

type OutputFmt struct {
	Filename string
	// contains filtered or unexported fields
}

func NewOutputFmt

func NewOutputFmt(format string, filename string, mime string) *OutputFmt

func (*OutputFmt) Name

func (this *OutputFmt) Name() string

type Packet

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

func NewPacket

func NewPacket() *Packet

func (*Packet) Data

func (this *Packet) Data() []byte

func (*Packet) Decode

func (this *Packet) Decode(cc *CodecCtx) (*Frame, bool, int, error)

@todo should be private

func (*Packet) Dts

func (this *Packet) Dts() int

func (*Packet) Dump

func (this *Packet) Dump()

func (*Packet) Duration

func (this *Packet) Duration() int

func (*Packet) Frames

func (this *Packet) Frames(cc *CodecCtx) chan *Frame

func (*Packet) Free

func (this *Packet) Free()

func (*Packet) Pos

func (this *Packet) Pos() int

func (*Packet) Pts

func (this *Packet) Pts() int

func (*Packet) SetDts

func (this *Packet) SetDts(val int)

func (*Packet) SetDuration

func (this *Packet) SetDuration(duration int)

func (*Packet) SetPts

func (this *Packet) SetPts(pts int)

func (*Packet) SetStreamIndex

func (this *Packet) SetStreamIndex(val int) *Packet

func (*Packet) Size

func (this *Packet) Size() int

func (*Packet) StreamIndex

func (this *Packet) StreamIndex() int

type Pair

type Pair struct {
	Key string
	Val string
}

type Sample

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

func (*Sample) SampleRealloc

func (this *Sample) SampleRealloc(nbSamples, nbChannels int) error

type SampleFmt

type SampleFmt int

type Stream

type Stream struct {
	Pts int
	// contains filtered or unexported fields
}

func (*Stream) CodecCtx

func (this *Stream) CodecCtx() *CodecCtx

func (*Stream) Duration

func (this *Stream) Duration() int64

func (*Stream) Id

func (this *Stream) Id() int

func (*Stream) Index

func (this *Stream) Index() int

func (*Stream) IsAudio

func (this *Stream) IsAudio() bool

func (*Stream) IsCodecCtxSet

func (this *Stream) IsCodecCtxSet() bool

func (*Stream) IsVideo

func (this *Stream) IsVideo() bool

func (*Stream) NbFrames

func (this *Stream) NbFrames() int

func (*Stream) SetCodecCtx

func (this *Stream) SetCodecCtx(cc *CodecCtx)

func (*Stream) TimeBase

func (this *Stream) TimeBase() AVRational

func (*Stream) Type

func (this *Stream) Type() int32

type SwrCtx

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

func NewSwrCtx

func NewSwrCtx(options []*Option, cc *CodecCtx) *SwrCtx

func (*SwrCtx) Convert

func (this *SwrCtx) Convert(input *Frame) *Frame

func (*SwrCtx) Free

func (this *SwrCtx) Free()

type SwsCtx

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

func NewSwsCtx

func NewSwsCtx(src *CodecCtx, dst *CodecCtx, method int) *SwsCtx

func (*SwsCtx) Scale

func (this *SwsCtx) Scale(src *Frame, dst *Frame)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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