MPD icon indicating copy to clipboard operation
MPD copied to clipboard

MPD with opus decoder plugin doesn't report track length

Open aereaux opened this issue 9 months ago • 6 comments

Bug report

Describe the bug

  1. mpc add https://jmad.org/tmp/01%20Just%20One%20Break.opus
  2. mpc play
  3. mpc status

Expected Behavior

mpc status lists the total length of the track.

Actual Behavior

mpc status lists 0:00 as the length of the track.

Version

Music Player Daemon 0.24 (v0.24)
Copyright 2003-2007 Warren Dukes <[email protected]>
Copyright 2008-2021 Max Kellermann <[email protected]>
This is free software; see the source for copying conditions.  There is NO
warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Database plugins:
 simple proxy upnp

Storage plugins:
 local udisks nfs curl

Neighbor plugins:
 upnp udisks

Decoder plugins:
 [mpg123] mp3
 [mad] mp3 mp2
 [vorbis] ogg oga
 [oggflac] ogg oga
 [flac] flac
 [opus] opus ogg oga
 [dsdiff] dff
 [dsf] dsf
 [faad] aac
 [mpcdec] mpc
 [wavpack] wv
 [openmpt] mptm mod s3m xm it 669 amf ams c67 dbm digi dmf dsm dtm far imf ice j2b m15 mdl med mms mt2 mtm nst okt plm psm pt36 ptm sfx sfx2 st26 stk stm stp ult wow gdm mo3 oxm umx xpk ppm mmcmp
 [modplug] 669 amf ams dbm dfm dsm far it med mdl mod mtm mt2 okt s3m stm ult umx xm
 [mikmod] amf dsm far gdm imf it med mod mtm s3m stm stx ult uni xm
 [sidplay] sid mus str prg P00
 [wildmidi] mid
 [fluidsynth] mid
 [gme] ay gbs gym hes kss nsf nsfe rsn sap spc vgm vgz
 [ffmpeg] 264 265 266 302 3g2 3gp 4xm 669 722 aa aa3 aac aax abc ac3 ac4 ace acm act adf adp ads adx aea afc aiff aix al alias_pix alp amf amr amrnb amrwb ams anm ans apc ape apl apm apng aptx aptxhd aqt argo_asf argo_brp argo_cvg art asc asf asf_o ass ast au avc avi avif avr avs avs2 avs3 bcstm bethsoftvid bfi bfstm bin bink binka bit bitpacked bmp_pipe bmv boa bonk brender_pix brstm c2 c93 caf cdata cdg cdxl cgi cif cine codec2raw concat cri_pipe dash dat data daud dav dbm dds_pipe dfa dff dfpwm dif digi dirac diz dmf dnxhd dpx_pipe dsf dsicin dsm dss dst dtk dtm dts dtshd dv dvbsub dvbtxt dvdvideo dxa ea eac3 ec3 evc exr_pipe f32be f32le f4v f64be f64le fap far ffmetadata film_cpk fits flac flic flm flv frm fsb fwse g722 g723_1 g726 g726le g729 gdm gdv gem_pipe genh gif gif_pipe gsm gxf h261 h263 h264 h265 h266 h26l hca hcom hdr_pipe heic heif hevc hls hnm iamf ice ico idcin idf idx iff ifv ilbc image2 image2pipe imf imx ipmovie ipu ircam ism isma ismv iss it itgz itr itz iv8 ivf ivr j2b j2k j2k_pipe jacosub jpeg_pipe jpegls_pipe jpegxl_pipe jv jxl kux kvag laf lc3 lmlm4 loas lrc lvf lxf m15 m2a m4a m4b m4v mac mca mcc mdgz mdl mdr mdz med mgsts microdvd mid mj2 mjpeg mjpg mk3d mka mks mkv mlp mlv mm mmcmp mmf mms mo3 mod mods moflex mov mp2 mp3 mp4 mpa mpc mpc8 mpeg mpegts mpegtsraw mpegvideo mpl2 mpo mptm msbc msf msnwctcp msp mt2 mtaf mtm mtv musx mv mvi mxf mxg nfo nist nsp nst nsv nut nuv obu ogg okt oma omg osq paf pam_pipe pbm_pipe pcx_pipe pdv pfm_pipe pgm_pipe pgmyuv_pipe pgx_pipe phm_pipe photocd_pipe pictor_pipe pjs plm pmp png_pipe pp_bnk ppm ppm_pipe psd_pipe psm psp psxstr pt36 ptm pva pvf qcif qcp qdraw_pipe qoa qoi_pipe r3d rco rcv rcwt rgb rka rl2 rm roq rpl rsd rso rt rtp rtsp s16be s24be s24le s32be s32le s337m s3gz s3m s3r s3z sami sap sb sbc sbg scc scd sdns sdp sdr2 sds sdx ser sf sfx sfx2 sga sgi_pipe shn sln smi smk smush sol son sox spdif sph srt ss2 st26 stk stl stm stp str sub sunrast_pipe sup svag svg_pipe svs sw swf tak tco tedcaptions thd thp tiertexseq tiff_pipe tmv tta txd txt ty ty+ u16be u24be u24le u32be u32le ub ul ult umx usm uw v v210 vag vapoursynth vb vbn_pipe vc1 vidc viv vividas vmd voc vpk vqe vqf vql vt vtt vvc w64 wa wav way wc3movie webm webm_dash_manifest webp_pipe wow wsaud wsd wsvqa wtv wv wve xa xbin xbm_pipe xl xm xmd xmgz xmr xmv xmz xpk xpm_pipe xvag xwd_pipe xwma y4m yop yuv yuv10 rtp:// rtsp:// rtsps://
 [sndfile] wav aiff aif au snd paf iff svx sf voc w64 pvf xi htk caf sd2
 [pcm]

Filters:
 libsamplerate soxr

Tag plugins:
 id3tag

Output plugins:
 shout null fifo pipe alsa ao oss openal solaris pipewire pulse jack httpd snapcast recorder

Encoder plugins:
 null vorbis opus lame twolame wave flac

Archive plugins:
 [bz2] bz2
 [zzip] zip
 [iso] iso

Input plugins:
 file io_uring archive alsa qobuz curl ffmpeg nfs mms cdio_paranoia

Playlist plugins:
 extm3u m3u pls xspf asx rss soundcloud flac cue embcue

Protocols:
 file:// alsa:// cdda:// ftp:// ftps:// gopher:// hls+http:// hls+https:// http:// https:// mms:// mmsh:// mmst:// mmsu:// nfs:// qobuz:// rtmp:// rtmpe:// rtmps:// rtmpt:// rtmpte:// rtmpts:// rtp:// rtsp:// rtsps:// scp:// sftp:// smb:// srtp://

Other features:
 avahi dbus udisks epoll icu inotify ipv6 systemd tcp un

Configuration

# See: /usr/share/doc/mpd/mpdconf.example

#auto_update  "no"

audio_output {
        type            "pipewire"
        name            "PipeWire Sound Server"
}

input {
	plugin "curl"
	tcp_keepalive "yes"
}

#decoder {
#    plugin "opus"
#    enabled "no"
#}

Log

Mar 14 08:26:45 : decoder_thread: probing plugin vorbis
Mar 14 08:26:45 : decoder_thread: probing plugin oggflac
Mar 14 08:26:45 : decoder_thread: probing plugin opus
Mar 14 08:26:45 : decoder: audio_format=48000:16:2, seekable=false

aereaux avatar Mar 14 '25 15:03 aereaux

Determining the track duration requires seeking a lot within the file.

Files served via HTTP are seekable (via Range requests), but some decoder plugins, such as Opus, decide not to use that because seeking in HTTP files is extremely slow; this is because the current HTTP request needs to be aborted, and a whole new one needs to be sent. This needs to be repeated for each and every seek call.

You can find the code (with a comment) here: https://github.com/MusicPlayerDaemon/MPD/blob/30e1cbbcba443d8d98041c6f9a5281beef23f2cd/src/input/InputStream.cxx#L34-L52

MaxKellermann avatar Mar 14 '25 16:03 MaxKellermann

Ah OK. The weird thing is that it works if I disable the "opus" decoder plugin (which presumably uses ffmpeg?) In that case it correctly reports the length (at least with 0.23.17). Unfortunately that workaround doesn't work with 0.24 (see the other bug I filed), so is there any other good workaround? The reason I ask is because of this problem using this setup with symfonium: https://support.symfonium.app/t/some-tracks-opus-files-extracted-from-youtube-not-marked-as-played/6933

aereaux avatar Mar 14 '25 17:03 aereaux

I know seeking is expensive but calculating duration isn't supposed to be. I've only a little experience with opus so forgive me, but isn't this addressed in their faq @MaxKellermann ?

https://wiki.xiph.org/OpusFAQ#Why_don't_you_store_the_duration_in_the_header?_Isn't_all_of_that_slow_and_complicated?

Opening a typical .opus file, which is not multiplexed and not chained, and computing the duration over the network requires just one extra HTTP request, which can proceed in parallel with the buffering in the main request. This is the behavior you will get from libopusfile's HTTP backend by default.

Or are we dealing with multiplexed and/or chained files here?

kingosticks avatar Mar 18 '25 21:03 kingosticks

The weird thing is that it works if I disable the "opus" decoder plugin (which presumably uses ffmpeg?) In that case it correctly reports the length (at least with 0.23.17).

Only Ogg-related decoder plugin has this check (because Ogg handling is known to have many seeks). The FFmpeg decoder plugin has no code to check for expensive seeking.

MaxKellermann avatar Mar 20 '25 20:03 MaxKellermann

I know seeking is expensive but calculating duration isn't supposed to be. I've only a little experience with opus so forgive me, but isn't this addressed in their faq

Yes and no. MPD doesn't use libopusfile, therefore anything said about libopusfile isn't relevant for MPD. It would sure be possible to optimize the length calculation with said one extra HTTP request, just like libopusfile does, but that would need some volunteer to take time to implement it in MPD. Therefore this is actually a feature request.

MaxKellermann avatar Mar 20 '25 20:03 MaxKellermann

Duplicate of #811?

jcorporation avatar Jun 29 '25 21:06 jcorporation