progress

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package progress reports ffmpeg encode completion from stderr.

Index

Constants

View Source
const (

	// TailSize is how much of ffmpeg's standard error a Writer keeps.
	TailSize = 64 << 10
)

Variables

This section is empty.

Functions

func From

func From(ctx context.Context) func(float64)

From returns the progress callback stored on ctx, if any.

Parameters:

Returns:

  • fn: The callback, or nil when none is stored.

func WithProgress

func WithProgress(ctx context.Context, fn func(percent float64)) context.Context

WithProgress attaches a progress callback to the context.

Parameters:

  • ctx: Parent context.
  • fn: Callback that receives the percent complete, from 0 to 99 and not rounded, so a slow encode still reports each step it takes.

Returns:

  • ctx: A child context that carries fn.

Types

type Writer

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

Writer parses ffmpeg stderr and reports percent complete.

It keeps only the tail of what it was written, for error logs, and parses each write once, so a long encode costs the same per write as a short one.

func NewWriter

func NewWriter(duration time.Duration, on func(float64)) *Writer

NewWriter returns a stderr writer that reports encode progress.

Parameters:

  • duration: Clip duration used to compute percent.
  • on: Optional callback invoked with the percent complete, from 0 to 99.

Returns:

  • writer: A writer that implements io.Writer and parses ffmpeg time= lines.

func (*Writer) Len

func (writer *Writer) Len() int

Len returns how many bytes were written, including any no longer kept.

Returns:

  • n: The total written.

func (*Writer) String

func (writer *Writer) String() string

String returns the kept tail of standard error.

Returns:

  • text: The last TailSize bytes written.

func (*Writer) Write

func (writer *Writer) Write(chunk []byte) (int, error)

Write implements io.Writer and reports ffmpeg time= progress.

Parameters:

  • chunk: Chunk of ffmpeg standard error.

Returns:

  • written: Always len(chunk).
  • err: Always nil.

Jump to

Keyboard shortcuts

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