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.
This commit is contained in:
Esa Kataja
2026-05-16 20:07:33 +03:00
parent 0662ee3576
commit 5584bbca57
+8 -2
View File
@@ -27,6 +27,7 @@ type StreamInfo struct {
SampleAspectRatio string `json:"sample_aspect_ratio"` SampleAspectRatio string `json:"sample_aspect_ratio"`
DisplayAspectRatio string `json:"display_aspect_ratio"` DisplayAspectRatio string `json:"display_aspect_ratio"`
CodecName string `json:"codec_name"` CodecName string `json:"codec_name"`
CodecType string `json:"codec_type"`
} }
type ProbeResult struct { 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) return 0, 0, false, fmt.Errorf("parsing ffprobe output: %w", err)
} }
foundVideo := false
for _, stream := range result.Streams { for _, stream := range result.Streams {
if stream.CodecName == "mpeg2video" || stream.CodecName == "h264" || stream.CodecName == "hevc" { if stream.CodecType == "video" {
width = stream.Width width = stream.Width
height = stream.Height 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 break
} }
} }
if !foundVideo {
return 0, 0, false, fmt.Errorf("no video stream found")
}
cmd = exec.Command(e.ffmpegPath, cmd = exec.Command(e.ffmpegPath,
"-hide_banner", "-hide_banner",