steps

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package steps provides workflow step implementations for the media processing workflows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotifyWorkflowFailure

func NotifyWorkflowFailure(ctx context.Context, stepErrors map[string]string, workflowName, filePath string, webhookClient *webhook.Client) error

NotifyWorkflowFailure sends an aggregated failure notification to webhookClient. stepErrors is the map returned by ctx.StepRunErrors() in an OnFailure handler. workflowName is included in the webhook payload; filePath is the file being processed. Returns nil (no-op) when stepErrors is empty.

func RunCleanup

func RunCleanup(filePath, watchRoot string, retainEmptyDirs bool) error

RunCleanup deletes the original source file after successful processing and, unless retainEmptyDirs is true, removes any parent directories that become empty as a result, stopping at watchRoot.

func RunDetectCrop

func RunDetectCrop(ctx context.Context, filePath string, inputW, inputH, minCropX, minCropY int) (*ffmpeg.CropParams, error)

RunDetectCrop runs the ffmpeg cropdetect filter over filePath and returns the crop region to apply, or nil when no crop is needed.

minCropX and minCropY are the minimum number of pixels that must be trimmed on each horizontal/vertical axis for a crop to be applied. A value of -1 disables the threshold for that axis (any detected crop is accepted). When both are -1 the crop detection step is skipped entirely and ffmpeg.DetectCrop is never called.

inputW and inputH are the pixel dimensions of the source video (from the ProbeOutput). They are used to compute how many pixels would be trimmed on each axis.

func SelectVideoCodec

func SelectVideoCodec(videoCodecName, format string) ffmpeg.Codec

SelectVideoCodec returns CodecCopy when the video is already H.264 or H.265 in an MKV container, and CodecH265 otherwise.

func WriteSentinel

func WriteSentinel(filePath string) error

WriteSentinel creates a zero-byte hidden sentinel file alongside filePath to mark it as processed, preventing the watcher from re-dispatching it. The sentinel path is .BASENAME.done in the same directory (e.g. /dl/movie.mkv → /dl/.movie.mkv.done). The write is idempotent.

Types

type AudioStreamInfo

type AudioStreamInfo struct {
	StreamInfo
	// ReportedChannelCount is the channel count as reported by ffprobe.
	// A value of 0 means the channel layout could not be detected.
	ReportedChannelCount int `json:"reported_channel_count"`
	// EffectiveChannelCount is the channel count used for processing decisions
	// such as downmix synthesis. When ReportedChannelCount is 0 (unknown layout),
	// this is set to a conservative surround value (6) so that unknown streams
	// are treated as surround rather than inadvertently blocking downmix synthesis.
	EffectiveChannelCount int  `json:"effective_channel_count"`
	HasLFE                bool `json:"has_lfe,omitempty"`
}

AudioStreamInfo holds stream info for an audio stream, including channel count.

type DetectCropOutput

type DetectCropOutput struct {
	// Crop is the detected crop region, or nil when no crop should be applied.
	Crop *ffmpeg.CropParams `json:"crop,omitempty"`
}

DetectCropOutput is the output of the detectcrop workflow task.

type ProbeOutput

type ProbeOutput struct {
	// IsValidMedia is false when the file is not a recognisable media file with a
	// video stream. All downstream steps are skipped when this is false.
	IsValidMedia bool `json:"is_valid_media"`
	// VideoCodec is the codec name of the first video stream (e.g. "h264", "hevc").
	// Only meaningful when IsValidMedia is true.
	VideoCodec string `json:"video_codec"`
	// Format is the container format name as reported by ffprobe (e.g. "matroska,webm").
	// Only meaningful when IsValidMedia is true.
	Format string `json:"format"`
	// DurationSeconds is the total duration of the media file in seconds.
	// Only meaningful when IsValidMedia is true; zero otherwise.
	DurationSeconds float64 `json:"duration_seconds"`
	// AudioStreams lists every audio stream found in the file, in stream order.
	// Only meaningful when IsValidMedia is true.
	AudioStreams []AudioStreamInfo `json:"audio_streams,omitempty"`
	// SubtitleStreams lists every subtitle stream found in the file, in stream order.
	// Only meaningful when IsValidMedia is true.
	SubtitleStreams []StreamInfo `json:"subtitle_streams,omitempty"`
	// VideoWidth and VideoHeight are the pixel dimensions of the first video stream.
	// Only meaningful when IsValidMedia is true; zero otherwise.
	VideoWidth  int `json:"video_width,omitempty"`
	VideoHeight int `json:"video_height,omitempty"`
	// StartedAt is the wall-clock time at which the probe step began. It is NOT set
	// by RunProbe; the workflow step closure sets it before calling RunProbe so that
	// downstream steps can compute elapsed durations.
	StartedAt time.Time `json:"started_at,omitempty"`
}

ProbeOutput is the output of the probe step.

func RunProbe

func RunProbe(ctx context.Context, filePath, watchRoot string, retainEmptyDirs bool) (ProbeOutput, error)

RunProbe reads codec and container info for filePath. If the file is not a recognised media file or has no video stream, it deletes the file and returns IsValidMedia=false (without error), causing all downstream steps to be skipped. When retainEmptyDirs is false and a deletion occurs, empty parent directories up to watchRoot are also removed via pruneEmptyParents.

type StreamInfo

type StreamInfo struct {
	Index    int    `json:"index"`
	Language string `json:"language"`
	Title    string `json:"title,omitempty"`
}

StreamInfo holds the input stream index, language tag, and source title for one audio or subtitle stream.

type TranscodeOutput

type TranscodeOutput struct {
	// DestCodec is the video codec written to the output file (e.g. "hevc", "copy").
	DestCodec string `json:"dest_codec"`
	// DestContainer is the container format of the output file (always "mkv").
	DestContainer string `json:"dest_container"`
	// DestFilePath is the path of the output file.
	DestFilePath string `json:"dest_file_path"`
	// SourceFileSizeBytes is the size of the input file in bytes, measured before transcoding.
	SourceFileSizeBytes int64 `json:"source_file_size_bytes"`
	// DestFileSizeBytes is the size of the output file in bytes, measured after transcoding.
	DestFileSizeBytes int64 `json:"dest_file_size_bytes"`
	// TranscodeDurationSeconds is the wall-clock time spent in RunTranscode (the ffmpeg call
	// plus surrounding stat/rename operations), in seconds.
	TranscodeDurationSeconds float64 `json:"transcode_duration_seconds"`
	// ArtworkFetchSkipped is true when artwork fetch was attempted but yielded no
	// embeddable image (library unreachable, no poster available, or unsupported type).
	ArtworkFetchSkipped bool `json:"artwork_fetch_skipped,omitempty"`
	// CropApplied is true when a crop filter was applied during transcoding.
	CropApplied bool `json:"crop_applied,omitempty"`
	// HardwareAccelerated is true when at least one video stream was encoded
	// using a hardware encoder (e.g. NVENC, QSV, VAAPI) at runtime. False when
	// the encoder fell back to software (e.g. libx265) even if
	// MEDIA_HARDWARE_DEVICE_PATH is set.
	HardwareAccelerated bool `json:"hardware_accelerated,omitempty"`
}

TranscodeOutput is the output of a successful RunTranscode call.

func RunTranscode

func RunTranscode(ctx context.Context, filePath string, probe ProbeOutput, cropParams *ffmpeg.CropParams, outputDir string, watcherRoot string, hardwareDevicePath string, h265CRF int, progressLogInterval time.Duration, library medialib.ArrLibrary) (TranscodeOutput, error)

RunTranscode transcodes filePath into outputDir, writing to a temp file named "._<stem>.mkv.tmp" and atomically renaming it to "<stem>.mkv" on success. The output always carries a .mkv extension to match the forced MKV container. Writing directly to the output directory avoids a cross-filesystem copy and guarantees the rename is atomic on Linux (same directory). probe is the output of RunProbe for filePath. cropParams is the crop region to apply, or nil for no cropping. When cropParams is non-nil and videoCodec would be CodecCopy, the codec is promoted to CodecH265 so the crop filter can be applied. watcherRoot is the root directory that the watcher monitors. When non-empty, the subdirectory of filePath relative to watcherRoot is mirrored under outputDir, preserving the download client's directory structure. When empty, the output is written flat into outputDir (no subdirectory). hardwareDevicePath is the device path passed to CreateHardwareDeviceContext; an empty string uses the libav default (auto-select). h265CRF is the constant-quality value for H.265 encoders. 0 means use the encoder's built-in default; valid explicit values are 1–51 (lower = higher quality). For libx265 this is the CRF; for hevc_nvenc it is the CQ value; for hevc_qsv and hevc_vaapi it is the global_quality (ICQ) value. Values outside 1–51 are silently ignored and the encoder default is used. progressLogInterval controls how often a progress log line is emitted during transcoding. Zero disables progress logging. library is the arr library used to fetch poster artwork. When nil, no fetch is attempted and transcoding proceeds without an embedded attachment, and ArtworkFetchSkipped is not set. When non-nil and the fetch yields no embeddable image, transcoding proceeds without an embedded attachment and ArtworkFetchSkipped is set to true.

Jump to

Keyboard shortcuts

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