From 7ec6509e11cc2d07b5b0f3ccdbb1d42026314578 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:09:21 +0000 Subject: [PATCH] [bugfix] support classifying correct video codec without audio as webm (#3494) * for webm support video:[vp8,vp9,av1] and audio:[NONE,vorbis,opus] * improved unsupported data type error output --- internal/media/ffmpeg.go | 29 +++++++++++++++++++++-------- internal/media/processingemoji.go | 2 +- internal/media/processingmedia.go | 8 ++++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/internal/media/ffmpeg.go b/internal/media/ffmpeg.go index ba251bd26..976662e60 100644 --- a/internal/media/ffmpeg.go +++ b/internal/media/ffmpeg.go @@ -392,18 +392,31 @@ func (res *result) GetFileType() (gtsmodel.FileType, string) { case "matroska,webm": switch { case len(res.video) > 0: + var isWebm bool + switch res.video[0].codec { case "vp8", "vp9", "av1": - default: - return gtsmodel.FileTypeVideo, "mkv" - } - if len(res.audio) > 0 { - switch res.audio[0].codec { - case "vorbis", "opus", "libopus": - // webm only supports [VP8/VP9/AV1]+[vorbis/opus] - return gtsmodel.FileTypeVideo, "webm" + if len(res.audio) > 0 { + switch res.audio[0].codec { + case "vorbis", "opus", "libopus": + // webm only supports [VP8/VP9/AV1] + + // [vorbis/opus] + isWebm = true + } + } else { + // no audio with correct + // video codec also fine. + isWebm = true } } + + if isWebm { + // Check for valid webm codec config. + return gtsmodel.FileTypeVideo, "webm" + } + + // All else falls under generic mkv. + return gtsmodel.FileTypeVideo, "mkv" case len(res.audio) > 0: return gtsmodel.FileTypeAudio, "mka" } diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go index 18d7895fd..750144296 100644 --- a/internal/media/processingemoji.go +++ b/internal/media/processingemoji.go @@ -158,7 +158,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { if err != nil && !isUnsupportedTypeErr(err) { return gtserror.Newf("ffprobe error: %w", err) } else if result == nil { - log.Warn(ctx, "unsupported data type") + log.Warnf(ctx, "unsupported data type by ffprobe: %v", err) return nil } diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go index acd326457..4c6670b06 100644 --- a/internal/media/processingmedia.go +++ b/internal/media/processingmedia.go @@ -22,6 +22,7 @@ import ( "os" errorsv2 "codeberg.org/gruf/go-errors/v2" + "codeberg.org/gruf/go-kv" "codeberg.org/gruf/go-runners" "github.com/superseriousbusiness/gotosocial/internal/gtserror" @@ -166,7 +167,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error { if err != nil && !isUnsupportedTypeErr(err) { return gtserror.Newf("ffprobe error: %w", err) } else if result == nil { - log.Warn(ctx, "unsupported data type") + log.Warnf(ctx, "unsupported data type by ffprobe: %v", err) return nil } @@ -214,7 +215,10 @@ func (p *ProcessingMedia) store(ctx context.Context) error { // metadata, in order to keep tags. default: - log.Warn(ctx, "unsupported data type: %s", result.format) + log.WarnKVs(ctx, kv.Fields{ + {K: "format", V: result.format}, + {K: "msg", V: "unsupported data type"}, + }...) return nil }