Skip to main content

Gstreamer ' The stream is in the wrong format.' [Resolved]

I'm using a Raspberry pi zero with a Bluetooth dongle and I'm trying to play an mp3 file to a Bluetooth speaker. I managed to get them both connected after a lot of trying, this is the full list of commands I execute to get everything working:

rfkill unblock 0
sudo hciconfig hci0 up
sudo hciconfig hci0 piscan
pulseaudio -k
pulseaudio -D
bluetoothctl -a
  scan on
  connect 30:95:E3:95:46:F7

To now stream the audio to the speaker I'm using the following gstreamer command:

gst-launch-1.0 filesrc location=song.mp3 ! pulsesink device=bluez_source.30_95_E3_95_46_F7

And that results in the following error:

pi@raspberrypi:~ $ gst-launch-1.0 filesrc location=song.mp3 ! pulsesink device=bluez_source.30_95_E3_95_46_F7
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
ERROR: from element /GstPipeline:pipeline0/GstPulseSink:pulsesink0: The stream is in the wrong format.
Additional debug info:
gstaudiobasesink.c(1119): gst_audio_base_sink_preroll (): /GstPipeline:pipeline0/GstPulseSink:pulsesink0:
sink not negotiated.
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

song.mp3 is a normal audio file, I can play it just fine with my phone, vlc and windows media player. The speaker also works fine with my phone.

What can I do to solve this issue?

Question Credit: Todd Sewell
Question Reference
Asked August 21, 2019
Posted Under: Unix Linux
1 Answers

It turns out the were two issues with what I was doing:

  • Gstreamer does sometimes support mp3 files, see this link for the formats it does support. Replacing the filesrc with audiotestsrc ! convertaudio fixes it, although I'm not sure why it needs to be converted.
  • Because the Bluetooth device is an audio target I needed to use bluez_sink instead of bluez_src.

This is the final command that manages to play audio on the speaker.

gst-launch-1.0 audiotestsrc ! pulsesink device=bluez_source.FC_58_FA_68_B4_8B

credit: Todd Sewell
Answered August 21, 2019
Your Answer