internal/ffmpeg/README.md
Last Updated: November 22, 2025
internal/ffmpeg wraps the ffmpeg CLI to transcode videos to AVC/H.264, remux containers, and extract preview frames in a predictable, testable way. Command builders share option structs so CLI tools, workers, and tests can select software or hardware encoders without duplicating flag logic.
ffmpeg binary; defaults to FFmpegBin but callers may override Options.Bin.#nosec G204.TranscodeCmd returns a useMutex hint to serialize expensive work.Force and reuse shared map flags; metadata copying is limited to safe defaults.encode.TranscodeToAvcCmd (x264 or default encoder).internal/ffmpeg/intel (h264_qsv) with optional Options.Device.internal/ffmpeg/nvidia (h264_nvenc).internal/ffmpeg/apple (h264_videotoolbox).internal/ffmpeg/vaapi (h264_vaapi) supporting optional device paths.internal/ffmpeg/v4l (h264_v4l2m2m) for ARM/embedded targets.fs.VideoMp4); RemuxCmd can handle other fs.Type values when provided.encode.MovFlags defaults to use_metadata_tags+faststart to keep outputs stream-friendly.encode/ — shared option structs, quality helpers, default map/metadata flags, software AVC command builder.apple/, intel/, nvidia/, vaapi/, v4l/ — hardware-specific AVC command builders.remux.go — container-only transfers with metadata copy and temp-file safety.transcode_cmd.go — selects encoder, handles animated image inputs, and signals mutex usage.extract_image_cmd.go — JPEG/PNG preview frame extraction with color-space presets.test.go & *_test.go — reusable command runner and smoke tests (use fixtures in testdata/).ffmpeg.go — package logger hook.internal/thumb calls these builders for video previews and thumbnails.internal/commands and workers select encoders based on configuration options and reuse encode.Options.pkg/fs supplies path helpers, existence checks, and file-mode constants referenced by remux/extract logic.NewVideoOptions to [1, 15360] pixels and the defined quality bounds.Options.Force; without it existing outputs are preserved.-map_metadata and clean sanitizers; only safe string fields (title, description, comment, author, creation_time) are added when set.PHOTOPRISM_FFMPEG_ENCODER guidance in AGENTS.md).go test ./internal/ffmpeg/...TranscodeCmd over manual exec.Command to keep logging, metadata, and mutex hints consistent.RemuxFile to convert containers without re-encoding; it creates a temp file and swaps atomically.encode.Options with SeekOffset and TimeOffset computed from video duration (see NewPreviewImageOptions).