owntone/owntone-server

Soundbridge selective transcoding

frankusb opened this issue · 108 comments

  1. Could httpd_rsp.c transcode to CBR MP3 instead of WAV? This is mostly a question of if ffmpeg can do FLAC to MP3 like it does FLAC to WAV now.
  2. If so, could it do it on a per client basis?

Wireless Soundbridges can't handle WAV bitrates. Currently I have two instances of owntone running, one in conjunction with mp3fs to allow reliable playback on wireless Soundbridges. Besides the duplication of resources, the real annoyance is when I update a playlist, the mp3fs owntone then churns for 30-40 minutes re-reading all of the metadata since inotify is not supported with mp3fs.

Sounds like it should be possible, I'll look into it.

For testing this concept, I have made a branch with a very rudimentary implementation where the transcoding is switched to CBR MP3 at 256 kbit/s. Could you try if this works with a flac and the Soundbridge?

This is the branch: https://github.com/owntone/owntone-server/tree/rspmp3

I get httpd: Transcoding error, file id 37484 in the log.

Also, if it's not obvious, the Soundbridge does not play.

Which version of ffmpeg is it?

Also, can you confirm it doesn't play and you get the same error if you try from a browser? Try with http://[address]:3689/rsp/stream/37484

ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Debian 12.2.0-14)
configuration: --disable-decoder=amrnb --disable-decoder=libopenjpeg --disable-gnutls --disable-liblensfun --disable-libopencv --disable-podpages --disable-sndio --disable-stripping --enable-avfilter --enable-chromaprint --enable-frei0r --enable-gcrypt --enable-gpl --enable-ladspa --enable-libaom --enable-libaribb24 --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libdavs2 --enable-libdc1394 --enable-libdrm --enable-libfdk-aac --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libkvazaar --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librsvg --enable-librubberband --enable-libshine --enable-libsmbclient --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-nonfree --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-openssl --enable-postproc --enable-pthreads --enable-shared --enable-version3 --enable-vulkan --incdir=/usr/include/x86_64-linux-gnu --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --toolchain=hardened --enable-vaapi --enable-libvpl --enable-libvmaf --enable-libilbc --enable-libjxl --disable-altivec --shlibdir=/usr/lib/x86_64-linux-gnu
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Hyper fast Audio and Video encoder

It does not play and I get the same error if I try from a browser.

I also noticed that the Soundbridge shows the song info as "Kind:WAV audio file" and "Bit Rate: 1411 kbps" for FLAC files which is not what I would expect.

Ok, I found the reason it's not playing in the browser. I'll get back to you with a new attempt.

I've pushed a commit to the branch that I think should fix at least playback in browser. Please test and let me know.

The Soundbridge is unable to stream. It still shows shows the song info as "Kind:WAV audio file" and "Bit Rate: 1411 kbps" for FLAC files. I can stream to my web browser.

[2023-11-01 09:27:09] [DEBUG] db: Starting query 'SELECT f.* FROM files f JOIN playlistitems pi ON f.path = pi.filepath WHERE f.disabled = 0 AND f.data_kind = 0 AND pi.playlistid = 12 ORDER BY pi.id ASC ;'
[2023-11-01 09:27:09] [DEBUG] db: End of query results
[2023-11-01 09:27:09] [DEBUG] httpd: Gzipping response
[2023-11-01 09:27:09] [DEBUG] rsp: RSP request '/rsp/db/0?query=id%3D12702&type=full' in worker thread 386760
[2023-11-01 09:27:09] [DEBUG] db: Running query 'SELECT COUNT() FROM files f WHERE f.disabled = 0 AND (f.id = 12702) AND f.data_kind = 0;'
[2023-11-01 09:27:09] [DEBUG] db: Starting query 'SELECT f.
FROM files f WHERE f.disabled = 0 AND (f.id = 12702) AND f.data_kind = 0 ORDER BY f.title_sort ;'
[2023-11-01 09:27:09] [DEBUG] db: End of query results
[2023-11-01 09:27:09] [DEBUG] httpd: Gzipping response
[2023-11-01 09:27:09] [DEBUG] rsp: RSP request '/rsp/stream/12702' in worker thread 386760
[2023-11-01 09:27:09] [DEBUG] db: Running query 'SELECT f.* FROM files f WHERE f.id = 12702;'
[2023-11-01 09:27:09] [ INFO] httpd: Preparing to transcode /var/autofs/removable/easystore10TB/Music/Travis Larson Band/Travis Larson Band-The New Exhibit/02-And Then.flac
[2023-11-01 09:27:09] [DEBUG] xcode: Selected encoder 'libmp3lame MP3 (MPEG audio layer 3)'
[2023-11-01 09:27:09] [DEBUG] ffmpeg: tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:stereo
[2023-11-01 09:27:09] [DEBUG] xcode: Created 'abuffer' filter: 'time_base=1/44100:sample_rate=44100:sample_fmt=s16:channel_layout=stereo'
[2023-11-01 09:27:09] [DEBUG] xcode: Created 'aformat' filter: 'sample_fmts=s16p:sample_rates=44100:channel_layouts=stereo'
[2023-11-01 09:27:09] [DEBUG] xcode: Created 'abuffersink' filter: ''
[2023-11-01 09:27:09] [DEBUG] ffmpeg: auto-inserting filter 'auto_aresample_0' between the filter 'abuffer' and the filter 'aformat'
[2023-11-01 09:27:09] [DEBUG] ffmpeg: ch:2 chl:stereo fmt:s16 r:44100Hz -> ch:2 chl:stereo fmt:s16p r:44100Hz
[2023-11-01 09:27:09] [ INFO] httpd: Kicking off streaming for /var/autofs/removable/easystore10TB/Music/Travis Larson Band/Travis Larson Band-The New Exhibit/02-And Then.flac
[2023-11-01 09:27:09] [DEBUG] httpd: Got 66037 bytes from transcode; streaming file id 12702

Ok, that's progress then. It could sound like the Soundbridge gets some metadata that makes it expect wav, so I will check what is sent to it before streaming.

I see the RSP playlist response returns info about the media format, so now I made a change so that the response instead tells the Soundbridge that it is 256 kbit mp3. Please try again with the latest commit from the branch included.

It works perfect.

Excellent. Does seeking also work?

To change the implementation from experimental to actual, I have to decide which clients should get what formats. In the branch, all clients get 256 kbit mp3, even iTunes (haven't tested if it works, though). I would like to set some good defaults, so that configuration generally isn't needed. I am always weary about adding config options. What defaults do you suggest for RSP?

The Soundbridge does not support seeking, only next and previous tracks and that does work.

For bit rate default, I would suggest 320kbps. That's what I've been using with mp3fs for a while now. I used to frequent the Soundbridge forums and there were never complaints about mp3 bit rates needing to be reduced that I recall. May as well maximize sound quality.

Are there other default settings you are asking about?

To be clear, I am interested in this feature so that I can set wireless Soundbridges to receive 320kbps MP3 and wired Soundbridges to receive 1411kbps WAV. I have been thinking if the default should be 320kbps MP3 to insure that owntone will work with all Soundbridges regardless of type of network connection.

Agreed 320kbps is a good default. Lots of literature to say that it's the level where its almost impossible to hear any difference from lossless files. It's also the most common mp3 format to download online.

While looking at how to do this, I came across this which seems to imply that the Soundbridge supports ALAC. Do you know if that is the case @frankusb? If so, would it be a better alternative? You would get lossless, but with less compression than the 320 kbps mp3, so requires more wifi bandwidth (I think the compression is about 50%, so half of 1411 kbps I guess).

You tried ALAC transcoding previously. I also found that the Soundbridge could not handle ALAC over wireless reliably by dropping some ALAC files in owntone.