Go's standard library supports image processing only. It can decode, transform and encode PNG, JPEG and GIF files, but it has no audio or video codecs. For audio and video analysis you use third-party packages, bindings to FFmpeg, or an external process, and use Go's concurrency to run the work in parallel.
This article separates what is built in from what needs libraries, and shows a concurrent pipeline for batch media jobs.
| Media type | Standard library | Typical addition |
|---|---|---|
| Images (PNG, JPEG, GIF) | image, image/png, image/jpeg, image/gif, image/draw | golang.org/x/image for WebP, TIFF, BMP and scaling |
| Audio | none (only encoding/binary for parsing raw bytes) | github.com/go-audio/wav, github.com/gopxl/beep |
| Video | none | FFmpeg through os/exec, or bindings such as goav |
| Metadata | none beyond reading bytes | EXIF and tag libraries |
This function decodes any registered format, converts it to grayscale and writes a PNG. It uses image/color to compute luminance for each pixel.
Note that the loop starts at b.Min, not zero, because image bounds do not always begin at the origin.
Analysis means extracting information from media rather than changing it. A histogram of brightness values is a simple example.
For heavy analysis such as feature detection or face recognition, use a computer vision library (for example GoCV, which binds to OpenCV) or call an ML service.
Go cannot decode audio natively, but github.com/go-audio/wav reads WAV files into PCM buffers that you can analyse.
Decoding the whole file into memory is fine for short clips. For long audio, read in chunks with dec.PCMBuffer.
For video, the practical approach is to run FFmpeg as a child process with exec.CommandContext, which lets you cancel it and set a timeout. Pass arguments as separate strings and never build a shell command from user input.
This needs context, fmt, os/exec and time. Validate inputPath and outputPath yourself before running the command.
A bounded worker pool with errgroup processes a batch quickly without overloading memory. golang.org/x/sync/errgroup provides SetLimit.
Since Go 1.22 each loop iteration has its own path variable, so the closure is safe without copying.
io.Reader and io.Copy instead of loading them whole.image.DecodeConfig before decoding user uploads.testing benchmarks and pprof before optimising.No. Use FFmpeg or a library that binds to it.
Yes for most server tasks, especially with a worker pool. For very heavy work, GoCV or a GPU service is faster.
The standard library does not parse EXIF. Use a package such as github.com/rwcarlsen/goexif or a maintained alternative.
You have not imported the decoder. Add a blank import such as _ "image/png".
Go handles image decoding, transformation and basic analysis in the standard library. Audio and video need external packages or FFmpeg, and a bounded worker pool gives you safe, fast batch processing.