From 7100b2b241ab5c199aaa17b2631b85b065b383e1 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 4 Jun 2021 13:03:19 -0500 Subject: [PATCH] feat: Support WMA files, including those with embedded album art (#143) The tag library supports WMA, so add the mimetype. Some wma files have embedded album art encoded as a video stream alongside the audio: ``` Input #0, asf, from '01. Emergency Pulloff.wma': Metadata: (snip) Duration: 00:03:11.47, start: 0.000000, bitrate: 129 kb/s Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 200x200 [SAR 96:96 DAR 1:1], 90k tbr, 90k tbn, 90k tbc Metadata: comment : Cover (front) Stream #0:1: Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp, 128 kb/s Output #0, opus, to '/tmp/output.opus': Output file #0 does not contain any stream ``` The `-map 0:0` passed to ffmpeg is selecting the video stream to transcode, then `-vn` says not to transcode video, so the whole process returns an error code: ``` 2021/05/28 18:59:09 transcoding according to transcoding profile of 96k 2021/05/28 18:59:09 serving transcode `02. Cotton Patch Rag.wma`: cache [opus/96k] miss! 2021/05/28 18:59:09 serving transcode `02. Cotton Patch Rag.wma`: error: starting transcode: running ffmpeg: exit status 1 ``` I believe the correct solution here is to use an _audio_ stream specifier, as in `-map 0:a:0`. Doing this selects the audio and successfully performs the transcode. --- server/encode/encode.go | 2 +- server/mime/mime.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/encode/encode.go b/server/encode/encode.go index 93fc652f..6dbb13bd 100644 --- a/server/encode/encode.go +++ b/server/encode/encode.go @@ -88,7 +88,7 @@ func ffmpegCommand(filePath string, profile Profile) (*exec.Cmd, error) { args := []string{ "-v", "0", "-i", filePath, - "-map", "0:0", + "-map", "0:a:0", "-vn", "-b:a", fmt.Sprintf("%dk", profile.Bitrate), } diff --git a/server/mime/mime.go b/server/mime/mime.go index 63c8f939..91b6277d 100644 --- a/server/mime/mime.go +++ b/server/mime/mime.go @@ -12,6 +12,7 @@ func FromExtension(ext string) (string, bool) { "m4b": "audio/m4b", "ogg": "audio/ogg", "opus": "audio/ogg", + "wma": "audio/x-ms-wma", } v, ok := types[ext] return v, ok