ffmpeg

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MetaArtwork = "artwork" // Metadata key for artwork, set the value as []byte
)

Variables

This section is empty.

Functions

func NewPacketDecoder

func NewPacketDecoder(codec *ff.AVCodecContext, stream int) (*decoder, error)

func NewResampler

func NewResampler(format ff.AVSampleFormat, opt ...Opt) (*resampler, error)

Create a new audio resampler which will resample the input frame to the specified channel layout, sample rate and sample format.

func NewRescaler

func NewRescaler(format ff.AVPixelFormat, opt ...Opt) (*rescaler, error)

Create a new rescaler which will rescale the input frame to the specified format, width and height.

Types

type DecodeFn

type DecodeFn func(int, *ff.AVFrame) error

DecodeFn is a function which is called for each frame decoded with the stream id of the packet. It should return nil to continue decoding or io.EOF to stop decoding.

type Encoder

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

func NewEncoder

func NewEncoder(ctx *ff.AVFormatContext, stream int, par *Par) (*Encoder, error)

Create an encoder with the given parameters

func (*Encoder) Close

func (encoder *Encoder) Close() error

func (*Encoder) Encode

func (e *Encoder) Encode(frame *ff.AVFrame, fn EncoderPacketFn) error

Encode a frame and pass packets to the EncoderPacketFn. If the frame is nil, then the encoder will flush any remaining packets. If io.EOF is returned then it indicates that the encoder has ended prematurely.

func (*Encoder) MarshalJSON

func (e *Encoder) MarshalJSON() ([]byte, error)

func (*Encoder) Par

func (e *Encoder) Par() *Par

Return the codec parameters

func (*Encoder) String

func (e *Encoder) String() string

type EncoderFrameFn

type EncoderFrameFn func(int) (*ff.AVFrame, error)

EncoderFrameFn is a function which is called to receive a frame to encode. It should return nil to continue encoding or io.EOF to stop encoding.

type EncoderPacketFn

type EncoderPacketFn func(*ff.AVPacket, *ff.AVRational) error

EncoderPacketFn is a function which is called for each packet encoded, with the stream timebase.

type Frame

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

func NewFrame

func NewFrame(ctx *ff.AVFrame, stream int) *Frame

func (*Frame) AVFrame

func (frame *Frame) AVFrame() *ff.AVFrame

Return the context

func (*Frame) Bytes

func (frame *Frame) Bytes(plane int) []byte

Return the byte data for a plane

func (*Frame) ChannelLayout

func (frame *Frame) ChannelLayout() string

Return channel layout

func (*Frame) Height

func (frame *Frame) Height() int

Return the height of the video frame

func (*Frame) Id

func (frame *Frame) Id() int

Return the stream

func (*Frame) Image

func (frame *Frame) Image() (image.Image, error)

Convert a frame into an image

func (*Frame) Int16

func (frame *Frame) Int16(plane int) []int16

Return the int16 data for a plane

func (*Frame) MarshalJSON

func (frame *Frame) MarshalJSON() ([]byte, error)

func (*Frame) NumPlanes

func (frame *Frame) NumPlanes() int

Return the number of planes for a specific PixelFormat or SampleFormat and ChannelLayout combination

func (*Frame) NumSamples

func (frame *Frame) NumSamples() int

Return number of samples

func (*Frame) PixelFormat

func (frame *Frame) PixelFormat() string

Return the pixel format

func (*Frame) SampleFormat

func (frame *Frame) SampleFormat() string

Return the sample format

func (*Frame) Samplerate

func (frame *Frame) Samplerate() int

Return the sample rate (Hz)

func (*Frame) Stride

func (frame *Frame) Stride(plane int) int

Return the number of bytes in a single row of the video frame

func (*Frame) String

func (frame *Frame) String() string

func (*Frame) Time

func (frame *Frame) Time() time.Duration

Return the timestamp as a duration, or minus one if not set

func (*Frame) Type

func (frame *Frame) Type() media.MediaType

Return the media type (AUDIO, VIDEO)

func (*Frame) Width

func (frame *Frame) Width() int

Return the width of the video frame

type Metadata

type Metadata struct {
	Key   string `json:"key" writer:",width:30"`
	Value any    `json:"value,omitempty" writer:",wrap,width:50"`
}

func NewMetadata

func NewMetadata(key string, value any) *Metadata

func (*Metadata) String

func (m *Metadata) String() string

type Opt

type Opt func(*opts) error

func OptChannelLayout

func OptChannelLayout(layout string) Opt

Channel layout

func OptChannels

func OptChannels(num int) Opt

Nuumber of channels

func OptForce

func OptForce() Opt

Force resampling and resizing on decode, even if the input and output parameters are the same

func OptFrameSize

func OptFrameSize(size string) Opt

Frame size

func OptMetadata

func OptMetadata(entry ...*Metadata) Opt

Append metadata to the output file, including artwork

func OptOutputFormat

func OptOutputFormat(name string) Opt

Output format from name or url

func OptPixFormat

func OptPixFormat(format string) Opt

Pixel format of the output frame

func OptSampleFormat

func OptSampleFormat(format string) Opt

Sample format

func OptSampleRate

func OptSampleRate(rate int) Opt

Sample Rate

func OptStream

func OptStream(stream int, par *Par) Opt

New stream with parameters

func OptWidthHeight

func OptWidthHeight(w, h int) Opt

Width and height of the output frame

type Par

type Par struct {
	ff.AVCodecParameters
}

func AudioPar

func AudioPar(samplefmt string, channellayout string, samplerate int) *Par

func NewAudioPar

func NewAudioPar(samplefmt string, channellayout string, samplerate int) (*Par, error)

func NewVideoPar

func NewVideoPar(pixfmt string, size string, framerate float64) (*Par, error)

func VideoPar

func VideoPar(pixfmt string, size string, framerate float64) *Par

func (*Par) CopyToCodec

func (ctx *Par) CopyToCodec(codec *ff.AVCodecContext) error

func (*Par) MarshalJSON

func (ctx *Par) MarshalJSON() ([]byte, error)

func (*Par) String

func (ctx *Par) String() string

func (*Par) ValidateFromCodec

func (ctx *Par) ValidateFromCodec(codec *ff.AVCodecContext) error

type Writer

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

Create media from io.Writer

func Create

func Create(url string, opt ...Opt) (*Writer, error)

Create a new writer with a URL and options

func NewWriter

func NewWriter(w io.Writer, opt ...Opt) (*Writer, error)

Create a new writer with an io.Writer and options

func (*Writer) Close

func (w *Writer) Close() error

Close a writer and release resources

func (*Writer) Encode

func (w *Writer) Encode(in EncoderFrameFn, out EncoderPacketFn) error

Encode frames from all encoders, calling the callback function to encode the frame. If the callback function returns io.EOF then the encoding for that encoder is stopped after flushing. If the second callback is nil, then packets are written to the output.

func (*Writer) Stream

func (w *Writer) Stream(stream int) *Encoder

Return a "stream" for encoding

func (*Writer) Write

func (w *Writer) Write(packet *ff.AVPacket) error

Write a packet to the output. If you intercept the packets in the Encode method, then you can use this method to write packets to the output.

Jump to

Keyboard shortcuts

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