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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user