clementine-player / Clementine

:tangerine: Clementine Music Player
https://www.clementine-player.org/
GNU General Public License v3.0
3.77k stars 679 forks source link

Duration not set when MPEG frame is missing, song from youtube-dl song download #7197

Open monoclex opened 2 years ago

monoclex commented 2 years ago

Before posting

Please follow the steps below and check the boxes with [x] once you did the step.

System information

Please provide information about your system and the version of Clementine used.

Expected behaviour / actual behaviour

Songs without an MPEG header should have a duration in clementine. The song playback is fine in clementine, so I would expect the timeline to work as well.

I'm not an expert on video container formats, audio container formats, and codecs, so while I wish I could provide a deeper explanation about the problem and a possible path forward, I cannot. Only thing I can think of is using ffmpeg as a library as it gets the duration right, running ffmpeg -i song.mp3

Steps to reproduce the problem (only for bugs)

I attached the song used here so you don't need youtube-dl to repro: song.zip

> youtube-dl --version
2021.12.17

> youtube-dl -x --audio-format mp3 -o song.mp3 https://www.youtube.com/watch?v=dQw4w9WgXcQ
[youtube] dQw4w9WgXcQ: Downloading webpage
[download] Destination: song.mp3
[download] 100% of 3.28MiB in 01:03
[ffmpeg] Post-process file song.mp3 exists, skipping

> ffmpeg -i song.mp3
Input #0, matroska,webm, from 'song.mp3':
  Metadata:
    encoder         : google/video-file
  Duration: 00:03:32.06, start: -0.007000, bitrate: 129 kb/s
  Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)

> clementine -c xd song.mp3
20:54:55.825 WARN  KGlobalAccelShortcutBackend:217  Tried setting global shortcut (QKeySequence("Media Next")) but KGlobalAccel returned ()
20:54:55.825 WARN  KGlobalAccelShortcutBackend:217  Tried setting global shortcut (QKeySequence("Media Play")) but KGlobalAccel returned ()
20:54:55.825 WARN  KGlobalAccelShortcutBackend:217  Tried setting global shortcut (QKeySequence("Media Previous")) but KGlobalAccel returned ()
20:54:55.825 WARN  KGlobalAccelShortcutBackend:217  Tried setting global shortcut (QKeySequence("Media Stop")) but KGlobalAccel returned ()
__logging_message__20:54:55.877 WARN  unknown                          QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 200, 200, 200, 75%'
__logging_message__20:54:55.888 WARN  unknown                          QCssParser::parseColorValue: Specified color without alpha value but alpha given: 'rgb 200, 200, 200, 75%'
TagLib: MPEG::Header::parse() -- MPEG header did not match MPEG synch.
20:54:56.090 WARN  IconLoader:48                    Icon name is null
TagLib: TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.
TagLib: MPEG::Properties::read() -- Could not find an MPEG frame in the stream.
TagLib: MPEG::Header::parse() -- MPEG header did not match MPEG synch.
TagLib: TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.
TagLib: MPEG::Properties::read() -- Could not find an MPEG frame in the stream.

Workaround

An easy fix is to simply re-encode the file with ffmpeg:

reencode() {
    mv "$1" "/tmp/$1"
    ffmpeg -i "/tmp/$1" "$1"
    rm "/tmp/$1"
}

reencode song.mp3