From 5584bbca57b7d8638c91f19495be93c7c2358dfa Mon Sep 17 00:00:00 2001 From: Esa Kataja Date: Sat, 16 May 2026 20:06:11 +0300 Subject: [PATCH] fix: detect video stream by codec_type instead of codec name allowlist GetMediaInfo previously only recognized mpeg2video/h264/hevc and silently returned 0x0 with no error for other codecs (VC-1, MPEG-4 ASP, AV1, ProRes), causing DetectMediaType to misclassify as DVD and feeding bogus dimensions to the zscale filter. Pick the first stream with codec_type=video and return an explicit error if none is found. --- internal/encoder/encoder.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/encoder/encoder.go b/internal/encoder/encoder.go index 31bfe4d..dabaf08 100644 --- a/internal/encoder/encoder.go +++ b/internal/encoder/encoder.go @@ -27,6 +27,7 @@ type StreamInfo struct { SampleAspectRatio string `json:"sample_aspect_ratio"` DisplayAspectRatio string `json:"display_aspect_ratio"` CodecName string `json:"codec_name"` + CodecType string `json:"codec_type"` } type ProbeResult struct { @@ -116,14 +117,19 @@ func (e *Encoder) GetMediaInfo(path string) (width, height int, interlaced bool, return 0, 0, false, fmt.Errorf("parsing ffprobe output: %w", err) } + foundVideo := false for _, stream := range result.Streams { - if stream.CodecName == "mpeg2video" || stream.CodecName == "h264" || stream.CodecName == "hevc" { + if stream.CodecType == "video" { width = stream.Width height = stream.Height - fmt.Printf("DEBUG detected video: %dx%d, SAR=%s\n", width, height, stream.SampleAspectRatio) + foundVideo = true + fmt.Printf("DEBUG detected video: %dx%d, codec=%s, SAR=%s\n", width, height, stream.CodecName, stream.SampleAspectRatio) break } } + if !foundVideo { + return 0, 0, false, fmt.Errorf("no video stream found") + } cmd = exec.Command(e.ffmpegPath, "-hide_banner",