Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Gstreamer - horribly distorted mp3 playback (solved)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
causality
Apprentice
Apprentice


Joined: 03 Jun 2006
Posts: 239

PostPosted: Wed Jun 26, 2019 4:58 pm    Post subject: Gstreamer - horribly distorted mp3 playback (solved) Reply with quote

On my system, gstreamer (and anything using it such as clementine) plays any format I throw at it flawlessly, except any mp3 files. It will play them without errors but the actual sound is horrible. It sounds heavily clipped and full of distortion. I can go play a .flac file and it sounds beautiful. Video files in various formats works fine including the audio. It's only mp3 files. This is an example command:

Code:
$ gst-play-1.0 02-Nightwish-End\ Of\ All\ Hope.mp3
Press 'k' to see a list of keyboard shortcuts.
Now playing /home/light/media/music/Albums/Nightwish/Century Child/02-Nightwish-End Of All Hope.mp3
Redistribute latency...
0:00:07.3 / 0:03:55.1


I played a bit until I pressed 'q' to quit. There are no errors in that output, none in dmesg, and none in my logs. It just plain sounds terrible. It likewise sounds horrible in Clementine since that uses gstreamer as a back-end. Right there in Clementine or using gst-play-1.0 any FLAC audio sounds great.

Anything that doesn't use gstreamer plays mp3 files just fine, such as mpv, mplayer, mpg123 on the command line, VLC, Musique, etc.

I've tried rebuilding/re-merging various related packages like gst-plugins-ugly and gst-plugins-mpg123 and it makes no difference. I also tried these with basic CFLAGS like "-O2 -pipe" and it didn't help.

So I've narrowed down the problem to gstreamer but I don't see where to go next in trying to diagnose the problem. Please help.

Output of "emerge --info":

Code:
# emerge --info
Portage 2.3.66 (python 3.6.5-final-0, default/linux/amd64/17.0/desktop/plasma, gcc-9.1.0, glibc-2.29-r2, 5.1.10-gentoo x86_64)
=================================================================
System uname: Linux-5.1.10-gentoo-x86_64-Intel-R-_Core-TM-_i5-6500_CPU_@_3.20GHz-with-gentoo-2.6
KiB Mem:    16362720 total,    835664 free
KiB Swap:    2246652 total,   2246384 free
Timestamp of repository gentoo: Wed, 26 Jun 2019 15:15:01 +0000
Head commit of repository gentoo: 33fa4a390de86d91e9a264ad92095eb2a108c6f2
Head commit of repository brother-overlay: 17bf222b4b001cdbb17a3fc3ff7295941678f3d9

sh bash 4.4_p23-r1
ld GNU ld (Gentoo 2.30 p5) 2.30.0
app-shells/bash:          4.4_p23-r1::gentoo
dev-java/java-config:     2.2.0-r4::gentoo
dev-lang/perl:            5.28.2-r1::gentoo
dev-lang/python:          2.7.15::gentoo, 3.5.5::gentoo, 3.6.5::gentoo
dev-util/cmake:           3.14.3::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.6-r1::gentoo
sys-apps/openrc:          0.41.2::gentoo
sys-apps/sandbox:         2.13::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r4::gentoo
sys-devel/automake:       1.16.1-r1::gentoo
sys-devel/binutils:       2.30-r4::gentoo, 2.31.1-r6::gentoo
sys-devel/gcc:            8.3.0-r1::gentoo, 9.1.0-r1::gentoo
sys-devel/gcc-config:     2.0::gentoo
sys-devel/libtool:        2.4.6-r3::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 4.14-r1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.29-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.ca.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-extra-opts:
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-jobs: 1

brother-overlay
    location: /usr/local/overlay/brother-overlay
    sync-type: git
    sync-uri: https://github.com/stefan-langenmaier/brother-overlay.git
    masters: gentoo

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=native -fomit-frame-pointer -fsched-pressure -ftree-loop-distribution -fweb -frename-registers -floop-interchange -ftree-vectorize -fivopts -pipe -flto -fno-fat-lto-objects -fuse-linker-plugin -floop-nest-optimize -fgraphite-identity"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -march=native -fomit-frame-pointer -fsched-pressure -ftree-loop-distribution -fweb -frename-registers -floop-interchange -ftree-vectorize -fivopts -pipe -flto -fno-fat-lto-objects -fuse-linker-plugin -floop-nest-optimize -fgraphite-identity"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps=y"
ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg candy cgroup config-protect-if-modified distlocks ebuild-locks fail-clean fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news pid-sandbox preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://gentoo.mirrors.pair.com/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O2 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,now -Wl,--strip-debug -O2 -march=native -fomit-frame-pointer -fsched-pressure -ftree-loop-distribution -fweb -frename-registers -floop-interchange -ftree-vectorize -fivopts -pipe -flto -fno-fat-lto-objects -fuse-linker-plugin -floop-nest-optimize -fgraphite-identity"
MAKEOPTS="-j4"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="3dnow 3dnowext X \ a52 aac aalib acl acpi activities alsa amd64 bash-completion berkdb branding bzip2 cairo cdda cdr cli consolekit crypt cups cxx dbus declarative dri dts dvd dvdr emboss encode exif fam ffmpeg flac fortran gdbm gif glamor gpm gtk iconv ipv6 jpeg jpeg2k kde kipi kwallet lcms ldap libnotify libtirpc lzma mad mng mp3 mp4 mpeg mplayer multilib mysql ncurses nptl offensive ogg opengl openmp openssl pam pango pcre pdf phonon plasma png policykit ppds python qml qt5 readline sdl seccomp socks5 spell ssl startup-notification svg symlink tcpd tiff truetype udev udisks unicode upower usb videos vorbis wayland widgets wmf wxwidgets x264 xattr xcb xcomposite xine xml xscreensaver xv xvid zlib" ABI_X86="64 32" ALSA_CARDS="hda-intel" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 fma3 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="pc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" L10N="en en-US" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" NETBEANS_MODULES="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_6" PYTHON_TARGETS="python2_7 python3_5 python3_6" RUBY_TARGETS="ruby24" USERLAND="GNU" VIDEO_CARDS="nvidia nv vesa" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS


Tail end of current "emerge --info gst-plugins-ugly":

Code:
=================================================================
                        Package Settings
=================================================================

media-libs/gst-plugins-ugly-1.14.3::gentoo was built with the following:
USE="-nls" ABI_X86="32 (64) (-x32)"
CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="-march=native -O2 -pipe"
LDFLAGS="-Wl,-O2 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,now -Wl,--strip-debug -march=native -O2 -pipe"


And tail end of current "emerge --info gst-plugins-mpg123":

Code:
=================================================================
                        Package Settings
=================================================================

media-plugins/gst-plugins-mpg123-1.14.4::gentoo was built with the following:
USE="" ABI_X86="32 (64) (-x32)"
CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="-march=native -O2 -pipe"
LDFLAGS="-Wl,-O2 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,now -Wl,--strip-debug -march=native -O2 -pipe"


Last edited by causality on Sun Jun 30, 2019 6:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
causality
Apprentice
Apprentice


Joined: 03 Jun 2006
Posts: 239

PostPosted: Sun Jun 30, 2019 5:19 pm    Post subject: Reply with quote

I did some further experimentation and found something strange to me.

This command plays a given mp3 file and it sounds flawless:

Code:
$ gst-launch-1.0 --gst-debug-level=2 filesrc location=12-Nightwish-Lagoon\ \(Bonus\).mp3 ! mpegaudioparse ! mpg123audiodec ! audioconvert ! audioresample ! alsasink


While this command plays a given m3p file and it sounds horribly distorted:

Code:
$ gst-launch-1.0 --gst-debug-level=2 filesrc location=./12-Nightwish-Lagoon\ \(Bonus\).mp3 ! decodebin ! audioconvert ! audioresample ! alsasink


I think this means that the mpg123 plugin provided by media-plugins/gst-plugins-mpg123 package works well. I'm not finding an easy way to see what mp3 plugin it selects when "decodebin" performs auto-selection. Apparently this automatic selection is also what gst-play-1.0 uses.
Back to top
View user's profile Send private message
causality
Apprentice
Apprentice


Joined: 03 Jun 2006
Posts: 239

PostPosted: Sun Jun 30, 2019 6:32 pm    Post subject: Reply with quote

I did some digging by running the failing command with --gst-debug-level=4 and examining the logs. When told to auto-select a plugin (which is what decodebin does) it picks gst-plugins-libav for mp3 files (as opposed to the working command where it was told to use mpg123 instead). So the problem must be with the libav gstreamer plugin.

I previously had -libav USE flag for media-plugins/gst-plugins-libav. I enabled libav USE flag for this package and rebuilt it. Now all mp3 files play flawlessly regardless of how gstreamer plays them. This means that now I can use Clementine again since it uses gstreamer.

On my system I have media-video/ffmpeg installed but I do not have media-video/libav installed. This remains the case because gst-plugins-libav uses a bundled ffmpeg library and not the system media-video/ffmpeg if the libav USE flag is enabled. The description of the flag (as produced by "equery uses gst-plugins-libav") is: "Use bundled ffmpeg to support systems using media-video/libav globally instead of media-video/ffmpeg".

I still don't understand how this happened or why. Everything else built against my system media-video/ffmpeg plays all files flawlessly including mp3s. The ffplay command plays them just fine. I have no idea why this affected only gstreamer but I'm glad to have it fixed. I have a penchant for finding oddball problems that apparently no one else is having.
Back to top
View user's profile Send private message
agroth
n00b
n00b


Joined: 05 Dec 2024
Posts: 1

PostPosted: Sun Dec 08, 2024 6:54 pm    Post subject: Reply with quote

I'm posting to this 5-years old topic, because I had the same problem in 2024, and found another solution which I like to share.

TL;DR: Compiling ffmpeg with the "-floop-nest-optimize" flag produces a buggy MP3 decoder at least on some architectures.

I had the same problem when playing MP3 with quodlibet. Quodlibet is also using gstreamer, which in turn used ffmpeg for MP3. I could work around this by changing USE flags for gst-plugins-meta. Disabling "ffmpeg" and enabling "mp3" made gstreamer use mpg123 for MP3s instead. This is similar to causality's solution. It worked for me, but might not work for others, if gstreamer needs ffmpeg for different formats they might want to play.

I looked into this again recently when I wanted Vivaldi to play proprietary media. There is a "proprietary-media" flag for this, which either pulls in ffmpeg-chromium or ensures ffmpeg was installed with the "chromium" USE flag. It seems there is still some work in progress, as recently "ffmpeg-chromium" seems to be a "forced" flag. Anyway, the outcome is always that Vivaldi uses a libffmpeg.so built on the system instead of the one that comes shipped with it. And my system ffmpeg had broken MP3 support.

As a side-note: ffmpeg has two MP3 decoders. On my system, only the "fixed point" one was broken; the "float" one played well.
Code:
# Horribly distorted 
ffmpeg  -c:a mp3 -i example.mp3 -f matroska - | ffplay -
# Nice
ffmpeg  -c:a mp3float -i example.mp3 -f matroska - | ffplay -

Unfortunately, I could not figure out how to make ffmpeg choose the floating-point decoder when used via gstreamer or anything else. Wrong direction...

I found that ffmpeg had bugs related to the -march option in the past. My CFLAGS from /etc/portage/make.conf.

Code:
### Compiler options
# Basic
CFLAGS="-O2 -pipe -march=native"
# Loop nest optimisation (need GCC with USE=graphite setting for --with-isl)
CFLAGS="${CFLAGS} -fgraphite-identity -floop-interchange -ftree-loop-distribution -floop-nest-optimize"

While experimenting, it turned out that the option "-floop-nest-optimize" causes the bug. It is the only from my list that is experimental according to the documentation . I can not even say if it provides any benefit at all, but it doesn't seem to cause problems elsewhere, so I removed it just for ffmpeg like so:

Created a file /etc/portage/env/friendlier_cflags with
Code:
# Remove problematic options like -floop-nest-optimize from CFLAGS
COMMON_FLAGS="-O2 -pipe -march=native -fgraphite-identity -floop-interchange -ftree-loop-distribution"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"[/url]

and a file /etc/portage/package.env/ffmpeg with

Code:
# ffmpeg needs friendlier_cflags to for the mp3 (fixed) decoder
media-video/ffmpeg-chromium friendlier_cflags
media-video/ffmpeg friendlier_cflags

After re-installing both ffmpegs ("emerge -av1 ffmpeg ffmpeg-chromium:128" in my case) everything is working fine!

I don't feel like officially reporting a bug somewhere, because the problem seems to occur only when using using an experimental feature of an uncommon GCC build to generate an ffmpeg tailored for a small and declining number of old CPUs.
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 2018

PostPosted: Mon Dec 09, 2024 9:51 pm    Post subject: Reply with quote

Please do file a bug on bugs.gentoo.org. I'm interested in such issues and handle them. If you would be so kind to, please include what you've said above, as well as what -march=native expands to on your machine (resolve-march-native may help), as well as some simple way to generate a bad file (using whatever example.mp3 fetched from somewhere). I'd much appreciate it.

It's especially useful given that such issues are often latent on other hardware and may resurface later.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum