Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WMA files, including those with embedded album art #143

Merged
merged 1 commit into from Jun 4, 2021
Merged

Support WMA files, including those with embedded album art #143

merged 1 commit into from Jun 4, 2021

Conversation

thirtythreeforty
Copy link
Contributor

Hello! Thank you so much for a server that Just Works with 99% of my music collection.

Unfortunately I have a few ornery .wma files that gonic doesn't detect. I made a first pass at adding them to the mimetypes:

diff --git a/server/mime/mime.go b/server/mime/mime.go
index 63c8f93..91b6277 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

and that gets them successfully scanned, at least. However, most clients don't know how to decode wma files so I'd like to transcode them. And that's where I hit problems.

Seems that my wma files have embedded album art encoded as a video stream alongside the audio:

Input #0, asf, from '01. Emergency Pulloff.wma':
  Metadata:
    title           : Emergency Pulloff
    artist          : Various Artists
    AverageLevel    : 7291
    FMPS/Playcount  : 0
    FMPS/Rating     : -1
    FMPS/Rating_Amarok_Score: 0
    DeviceConformanceTemplate: L1
    PeakValue       : 32033
    album_artist    : Various Artists
    album           : Stelling Banjo Anthology
    WM/EncodingTime : 1095187712
    genre           : Bluegrass
    WM/MediaPrimaryClassID: {D1607DBC-E323-4BE2-86A1-48A42A28441E}
    track           : 1
    WM/Year         : 2005
    WMFSDKNeeded    : 0.0.0.0000
    WMFSDKVersion   : 11.0.5721.5145
    IsVBR           : 0
  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, and the track plays in Jamstack.

Here's a sample track you can reproduce all this with if you like. Sorry about the banjo music :)

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.
@sentriz
Copy link
Owner

sentriz commented May 28, 2021

Cool! Thanks for the nice words :) I haven't had a chance to test this yet. Presumably transcoding other formats w/ different requested bitrates still works?

@thirtythreeforty
Copy link
Contributor Author

I believe so based on the last hour or so of listening. A mix of opus, ogg, mp3, and m4a.

@sentriz sentriz merged commit 7100b2b into sentriz:master Jun 4, 2021
@sentriz
Copy link
Owner

sentriz commented Jun 4, 2021

sorry for the delay, using it for a little while all seems well :) thanks!
it should be in the next release #141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants