mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.2k stars 571 forks source link

Unable to build latest development version on RPI4 #1386

Closed atebeta closed 2 years ago

atebeta commented 2 years ago

When I try to run

./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2

it fails at with the following error:

checking for avformat_new_stream in -lavformat... no
configure: error: AirPlay 2 support requires libavformat -- libavformat-dev suggested

I was able to get it to build by rolling back the configure.ac file to commit 7693b4a from 5th December. I could now install and run Shairport-sync, but I was unable to connect to the speaker even though I opened port 319 and 320. I was able to connect after disabling UFW, but whenever I tried to play something Shairport would crash with the following error.

Dec 25 23:27:28 atebeta shairport-sync[7350]:          0.000062593 "rtsp.c:1832" anchor rate 0x0000000000000001.
Dec 25 23:27:28 atebeta shairport-sync[7350]:          0.000068407 "rtsp.c:1837" Connection 1: Start playing.
Dec 25 23:27:28 atebeta shairport-sync[7350]:          0.000789333 "rtp.c:1325" Connection 1: Clock f099b63a8f790008 is now the new anchor clock and master clock. History: 4010.968701 milliseconds.
Dec 25 23:27:28 atebeta shairport-sync[7350]:          0.000250371 "rtp.c:1408" Connection 1: NQPTP new master clock f099b63a8f790008.
Dec 25 23:27:28 atebeta systemd[1]: shairport-sync.service: Main process exited, code=killed, status=11/SEGV
Dec 25 23:27:28 atebeta systemd[1]: shairport-sync.service: Failed with result 'signal'.

Not sure what the issue is. I'm able to run the stable version fine (with UFW enabled), but I just got an AppleTV so would like to try the Airplay2 version.

mikebrady commented 2 years ago

Thanks for the post. Let me suggest that you start over and, making sure your Pi4 is fully up to date on Buster or Bullseye, follow the guide at BUILDFORAP2.md. The versions of Shairport Sync and NQPTP must match up -- you'll get a runtime error message if there's a problem. The missing library libavformat is actually included in the list of tools and libraries to be loaded, which is different for AirPlay 2 to those needed for AirPlay 1. Just FYI, ports 319, 320 and 9000 should be open for UDP packets. Timing is critically dependent on these ports offering minimal propagation delays.

Good luck!

atebeta commented 2 years ago

Hi thanks for your reply. I followed all the steps exactly from BUILDFORAP2.md and I have all the dependencies. I tried again after updating to Bullseye, but I'm still getting the same error. If I try to install libavformat-dev it just tells me it is already installed.

libavformat-dev is already the newest version (7:4.3.3-0+rpt2+deb11u1).

Also, as mentioned, when I used a slightly older version of the configure.ac file (from the development branch) it installs fine. I also already had 319, 320, and 9000 open for both UDP and TPC packets.

So the issues I’m facing is that with the most recent configure.ac file I can’t get past the ./configure... step with the the --with-airplay-2 flag even though I have libavformat installed.

If I use the old configure.ac file it will install and run, but I'm only able to connect if I disable my firewall even though ports 319, 320 and 9000 are open. If I do this I can connect, but it will crash as per above when I try to play something.

The biggest issue though is obviously that there is something with the configure.ac file which makes it not recognise that I have libavformat-dev installed.

atebeta commented 2 years ago

I was able to make it work by commenting out line 422 of configure.ac which checks for libavformat:

AC_CHECK_LIB([avformat],[avformat_new_stream], [], [AC_MSG_ERROR([AirPlay 2 support requires libavformat -- libavformat-dev suggested])])

after this it wouldn't complete.

make -j

and gave me this error:

/usr/bin/ld: /usr/local/lib/libavcodec.a(libx264.o): in function X264_init:
/home/pi/FFmpeg/libavcodec/libx264.c:922: undefined reference to x264_encoder_open_155
/usr/bin/ld: /usr/local/lib/libavcodec.a(libx265.o): in function libx265_encode_init_csp:
/home/pi/FFmpeg/libavcodec/libx265.c:642: undefined reference to x265_api_get_165
/usr/bin/ld: /home/pi/FFmpeg/libavcodec/libx265.c:644: undefined reference to x265_api_get_165
/usr/bin/ld: /home/pi/FFmpeg/libavcodec/libx265.c:646: undefined reference to x265_api_get_165
/usr/bin/ld: /usr/local/lib/libavcodec.a(libx265.o): in function libx265_encode_init:
/home/pi/FFmpeg/libavcodec/libx265.c:124: undefined reference to x265_api_get_165
/usr/bin/ld: /home/pi/FFmpeg/libavcodec/libx265.c:126: undefined reference to x265_api_get_165
/usr/bin/ld: rtp.o: in function rtp_buffered_audio_processor:
/home/pi/shairport-sync/rtp.c:2132: undefined reference to avcodec_register_all
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:827: shairport-sync] Error 1
make[2]: Leaving directory '/home/pi/shairport-sync'
make[1]: *** [Makefile:1066: all-recursive] Error 1
make[1]: Leaving directory '/home/pi/shairport-sync'
make: *** [Makefile:660: all] Error 2

so I recompiled and installed FFmpeg after which make -j worked. Now I am running:

4.1-dev-141-g30472850-dirty-AirPlay2-OpenSSL-Avahi-ALSA-pa-pipe-soxr-metadata-mqtt-sysconfdir:/etc

I still had to comment out line 422 for it to work even after recompiling and and reinstalling FFmpeg, so not quite sure what is going on there, but at least I got it to work. I was able to add my speaker to Homekit and the audio on Youtube doesn't stop playing after 10 seconds. Thanks.

mikebrady commented 2 years ago

Thanks -- I'm glad you got it to work eventually. I really don't understand why the problem arose, I'm afraid. But see also Issue 1361.

mikebrady commented 2 years ago

Just looking through the error messages above, it seems that the linker was looking for locally-compiled libav... stuff (and looking for it in the /usr/local/lib directory). Is it possible that you might have built some AV stuff in the past and had to build a library locally? I note that you solved it by building and installing FFmpeg locally. On my machines, there is nothing libav...-related in /usr/local/lib. In fact, there is very little in there...

atebeta commented 2 years ago

Yeah, I think I needed some additional libraries so I had followed this tutorial to install ffmpeg previously.

I also followed it when I reinstalled it.

mikebrady commented 2 years ago

Yeah, I think I needed some additional libraries so I had followed this tutorial to install ffmpeg previously.

I also followed it when I reinstalled it.

Thanks -- that might explain how the problem arose.

atebeta commented 2 years ago

Yeah, I'm guessing it would have built if I had just commented out line 422 before upgrading to bullseye. I didn't do a clean install so a few things were broken after. I still don't quite understand why it built when I used to older the configure.ac file.

github-actions[bot] commented 2 years ago

This issue has been inactive for 45 days so will be closed 7 days from now. To prevent this, please remove the "stale" label or post a comment.

alexisteleco commented 1 year ago

I have the same problem but I'm not able to make it work. I am trying to install Shairport Sync with Airplay 2. I tried to reinstall ffmpeg, compiling with source code and with default package, but neither of those options worked for me. I also uninstalled and reinstalled the pages that were asked for, but it changed nothing.

I really would want to reinstall all from zero, but I have a bunch of customisations and services running in the RPi 4 that I don't want to lose.

Is there anything that I can do to compile with Airplay2? It works without the Airplay2 flag.

The error is:

checking for gcry_control in -lgcrypt... yes
checking for libavutil... yes
checking for libavcodec... no
configure: error: AirPlay 2 support requires libavcodec -- libavcodec-dev suggested

But if I try to install libavcodec, I get:

$ sudo apt-get install libavcodec-dev 
Reading package lists... Done                                                                            
Building dependency tree       
Reading state information... Done
libavcodec-dev is already the newest version (7:4.1.9-0+deb10u1+rpt1).
mikebrady commented 1 year ago

Thanks. Could you run $ shairport-sync --displayConfig even on the non-AirPlay-2 version and post the results please? It will give us an idea of the system you are using.

alexisteleco commented 1 year ago

Thanks for the quick response. Yes of course :)

>> Display Config Start.

From "uname -a":
 Linux raspberrypi4 5.10.103-v7l+ #1529 SMP Tue Mar 8 12:24:00 GMT 2022 armv7l GNU/Linux

From /etc/os-release:
 Raspbian GNU/Linux 10 (buster)

From /sys/firmware/devicetree/base/model:
 Raspberry Pi 4 Model B Rev 1.1

Shairport Sync Version String:
 4.1-4-g99e76fdf-OpenSSL-Avahi-ALSA-soxr-metadata-mqtt-sysconfdir:/etc

Command Line:
 shairport-sync --displayConfig

Configuration File:
 /etc/shairport-sync.conf

Configuration File Settings:
 general : 
 {
   name = "Minicadena Comedor %v";
   volume_range_db = 60;
 };
 sessioncontrol : 
 {
   run_this_before_play_begins = "/usr/bin/python3 /opt/custom_scripts/startHiFiforRPi.py";
   run_this_after_play_ends = "/usr/bin/python3 /opt/custom_scripts/stopHiFiforRPi.py";
 };
 alsa : 
 {
   output_device = "hw:0";
   mixer_device = "PCM";
 };
 mqtt : 
 {
   enabled = "yes";
   hostname = "172.16.0.100";
   port = 1883;
   topic = "house/livingRoom/minicadena";
   publish_parsed = "yes";
   publish_cover = "yes";
   enable_remote = "yes";
 };

>> Display Config End.
>> Goodbye!
mikebrady commented 1 year ago

Thanks. Let me check this out.

alexisteleco commented 1 year ago

Thanks for the help. It is really appreciated.

mikebrady commented 1 year ago

Thanks — it’ll be tomorrow though, it’s later here in Ireland…

mikebrady commented 1 year ago

Before you try the rest of this suggestion, consider this: Since you have compiled FFmpeg locally, you may simply need to tell the linker about it. See here for a similar situation having build libalac locally.

Okay, if that doesn't work, then there's an update (in the development branch) that tries a little harder to find libavcodec. If you switch to the development branch, pull the updates and go through the autoconf... and ./configure... again, and see what happens -- hopefully you'll get further along.

It's all a bit peculiar, because Shairport Sync normally builds on this system without issue and the libraries are accessible though pkg-config:

$ pkg-config --list-all | grep libav
libavformat                    libavformat - FFmpeg container format library
libavcodec                     libavcodec - FFmpeg codec library
libavutil                      libavutil - FFmpeg utility library

...so I guess it's because FFmpeg was built locally and the build system can't find it.

alexisteleco commented 1 year ago

It works like a charm now! 🎉 Thanks!

Let me explain what I have tried and what worked at the end (for me), so if anyone finds this issue he is able to try what worked for me.

  1. Not worked I have tried to uninstall ffmpeg and install it via apt-get, but the libraries were not found either way. Maybe is some old stuff that I was not able to find and erase.
  2. Not Worked I have linked ffmpeg via using sudo ldconfig, and it was available to other programs, but libraries were not found for shairport sync
  3. Worked Your thoughts regarding "letting the compiler know about what you got" made me think that maybe the problem was not about ffmpeg itself, but the libraries I had installed to compile it, so I went forward and recompile/reinstalled the libraries with the --enable-shared flag when running configure, and I used sudo ldconfig after on each library. That did the trick.

I leave here the three scripts I created to do all this stuff, so people is able to copy/paste 😉

Installing ffmpeg locally with shared libraries ```bash #!/bin/bash # Based on https://pimylifeup.com/compiling-ffmpeg-raspberry-pi/ FFMPEG_HOME='/opt/ffmpeg' #Set some coloring danger=`tput setaf 1` success=`tput setaf 2` warning=`tput setaf 3` info=`tput setaf 4` debug=`tput setaf 5` cyan=`tput setaf 6` white=`tput setaf 7` bg_white=`tput setab 7` bg_black=`tput setab 0` reset=`tput sgr0` #set some functions for printing with colours print_info () { echo "" echo "${info}################################################################" echo $1 echo "################################################################${reset}" } print_success () { echo "${success}$1${reset}" } print_danger () { echo "${danger}$1${reset}" } print_warning () { echo "${warning}$1${reset}" } print_abort_if_failed () { if [ $1 -ne 0 ]; then echo "" echo "${warning}[$2] failed, aborting.${reset}" exit 1 fi } print_info "Removing previous binaries versions" sudo rm -f $(which ffmpeg) sudo rm -f $(which ffmpeg) sudo rm -f $(which ffmpeg) print_info "Removing previous sources" sudo rm -rf $FFMPEG_HOME/* STEP_MSG="Installing dependencies" print_info "$STEP_MSG" sudo apt-get install -y autoconf automake build-essential cmake doxygen git graphviz imagemagick \ libasound2-dev libass-dev libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libavutil-dev \ libfreetype6-dev libgmp-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libopus-dev librtmp-dev \ libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev libsnappy-dev libsoxr-dev \ libssh-dev libssl-dev libtool libv4l-dev libva-dev libvdpau-dev libvo-amrwbenc-dev libvorbis-dev libwebp-dev \ libx264-dev libx265-dev libxcb-shape0-dev libxcb-shm0-dev libxcb-xfixes0-dev libxcb1-dev libxml2-dev lzma-dev \ meson nasm pkg-config python3-dev python3-pip texinfo wget yasm zlib1g-dev libdrm-dev print_abort_if_failed $? "$STEP_MSG" print_info "Creating directory [$FFMPEG_HOME] home and entering" mkdir -p $FFMPEG_HOME/ffmpeg-libraries cd $FFMPEG_HOME/ffmpeg-libraries STEP_MSG="Downloading and installing libraries: [fdk-aac (Fraunhofer FDK AAC library)]" print_info $STEP_MSG # support for the AAC sound format. git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git $FFMPEG_HOME/ffmpeg-libraries/fdk-aac \ && cd $FFMPEG_HOME/ffmpeg-libraries/fdk-aac \ && autoreconf -fiv \ && sudo ./configure --enable-shared\ && sudo make -j$(nproc)\ && sudo make install print_abort_if_failed $? $STEP_MSG STEP_MSG="Downloading and installing libraries: [dav1d]" print_info "$STEP_MSG" # decoding the AV1 video format into FFmpeg. Considered the successor of the VP9 codec and as a competitor to the x265 codec git clone --depth 1 https://code.videolan.org/videolan/dav1d.git $FFMPEG_HOME/ffmpeg-libraries/dav1d \ && mkdir $FFMPEG_HOME/ffmpeg-libraries/dav1d/build \ && cd $FFMPEG_HOME/ffmpeg-libraries/dav1d/build \ && meson .. \ && ninja \ && sudo ninja install print_abort_if_failed $? $STEP_MSG STEP_MSG="Downloading and installing libraries: [kvazaar (HEVC encoder)]" print_info "$STEP_MSG" git clone --depth 1 https://github.com/ultravideo/kvazaar.git $FFMPEG_HOME/ffmpeg-libraries/kvazaar \ && cd $FFMPEG_HOME/ffmpeg-libraries/kvazaar \ && ./autogen.sh \ && sudo ./configure --enable-shared\ && sudo make -j$(nproc) \ && sudo make install print_abort_if_failed $? $STEP_MSG STEP_MSG="Downloading and installing libraries: [LibVPX (VP8 and VP9 video codecs)]" print_info "$STEP_MSG" git clone --depth 1 https://chromium.googlesource.com/webm/libvpx $FFMPEG_HOME/ffmpeg-libraries/libvpx \ && cd $FFMPEG_HOME/ffmpeg-libraries/libvpx \ && sudo ./configure --disable-examples --disable-tools --disable-unit_tests --disable-docs --enable-shared\ && sudo make -j$(nproc) \ && sudo make install print_abort_if_failed $? $STEP_MSG STEP_MSG="Downloading and installing libraries: [AOM (AP1 video codec)]" print_info "$STEP_MSG" git clone --depth 1 https://aomedia.googlesource.com/aom $FFMPEG_HOME/ffmpeg-libraries/aom \ && mkdir $FFMPEG_HOME/ffmpeg-libraries/aom/aom_build \ && cd $FFMPEG_HOME/ffmpeg-libraries/aom/aom_build \ && cmake -G "Unix Makefiles" AOM_SRC -DENABLE_NASM=on -DPYTHON_EXECUTABLE="$(which python3)" -DCMAKE_C_FLAGS="-mfpu=vfp -mfloat-abi=hard" .. \ && sed -i 's/ENABLE_NEON:BOOL=ON/ENABLE_NEON:BOOL=OFF/' CMakeCache.txt \ && make -j$(nproc) \ && sudo make install print_abort_if_failed $? $STEP_MSG # This command ensures we won't run into linking issues because the compiler can't find a library. STEP_MSG="Linking installed libraries" print_info "$STEP_MSG" sudo ldconfig print_abort_if_failed $? $STEP_MSG STEP_MSG="Making ffmpeg whith libraries" print_info "$STEP_MSG" # --enable-libzimg \ git clone --branch release/5.1 --depth 1 https://github.com/FFmpeg/FFmpeg.git $FFMPEG_HOME/FFmpeg \ && cd $FFMPEG_HOME/FFmpeg \ && sudo ./configure \ --extra-cflags="-I/usr/local/include" \ --extra-ldflags="-L/usr/local/lib" \ --extra-libs="-lpthread -lm -latomic" \ --arch=armel \ --enable-gmp \ --enable-gpl \ --enable-libaom \ --enable-libass \ --enable-libdav1d \ --enable-libdrm \ --enable-libfdk-aac \ --enable-libfreetype \ --enable-libkvazaar \ --enable-libmp3lame \ --enable-libopencore-amrnb \ --enable-libopencore-amrwb \ --enable-libopus \ --enable-librtmp \ --enable-libsnappy \ --enable-libsoxr \ --enable-libssh \ --enable-libvorbis \ --enable-libvpx \ --enable-libwebp \ --enable-libx264 \ --enable-libx265 \ --enable-libxml2 \ --enable-mmal \ --enable-nonfree \ --enable-omx \ --enable-omx-rpi \ --enable-version3 \ --target-os=linux \ --enable-pthreads \ --enable-openssl \ --enable-hardcoded-tables \ --enable-shared \ && sudo make -j$(nproc) \ && sudo make install print_abort_if_failed $? $STEP_MSG print_success "FFMPEG whith libraries have been successfully installed" ```
Clean previous Shairport Sync installations ```bash #!/bin/bash # This script must be run manually, because it will reboot the RPi SHA_SYNC_HOME='/opt/shairport-sync' #Set some coloring danger=`tput setaf 1` success=`tput setaf 2` warning=`tput setaf 3` info=`tput setaf 4` debug=`tput setaf 5` cyan=`tput setaf 6` white=`tput setaf 7` bg_white=`tput setab 7` bg_black=`tput setab 0` reset=`tput sgr0` #set some functions for printing with colours print_info () { echo "${info}################################################################" echo $1 echo "################################################################${reset}" } print_danger () { echo "${danger}$1${reset}" } print_warning () { echo "${warning}$1${reset}" } print_info "Cleaning of previous version" sudo rm -f $(which shairport-sync) sudo rm -f $(which shairport-sync) sudo rm -f $(which shairport-sync) sudo rm -f \ /etc/systemd/system/shairport-sync.service \ /lib/systemd/system/shairport-sync.service \ /etc/init.d/shairport-sync \ /etc/dbus-1/system.d/shairport-sync-dbus.conf \ /etc/dbus-1/system.d/shairport-sync-mpris.conf rm -rf $SHA_SYNC_HOME sudo reboot now ```
Install NQPTP and Shairport Sync prepared for home assistant with Airplay 2 support ```bash #!/bin/bash SHA_SYNC_HOME='/opt/shairport-sync' #Set some coloring danger=`tput setaf 1` success=`tput setaf 2` warning=`tput setaf 3` info=`tput setaf 4` debug=`tput setaf 5` cyan=`tput setaf 6` white=`tput setaf 7` bg_white=`tput setab 7` bg_black=`tput setab 0` reset=`tput sgr0` #set some functions for printing with colours print_info () { echo "${info}################################################################" echo $1 echo "################################################################${reset}" } print_danger () { echo "${danger}$1${reset}" } print_warning () { echo "${warning}$1${reset}" } print_info "Upgrade libraries" sudo apt-get update && sudo apt-get upgrade print_info "Install dependencies" sudo apt install \ --no-install-recommends \ build-essential \ git \ autoconf \ automake \ libtool \ libpopt-dev \ libconfig-dev \ libasound2-dev \ avahi-daemon \ libavahi-client-dev \ libssl-dev \ libsoxr-dev \ libplist-dev \ libsodium-dev \ libavutil-dev \ libavcodec-dev \ libavformat-dev \ uuid-dev \ libgcrypt-dev \ xxd print_info "Install NQPTP" sudo rm /lib/systemd/system/nqptp.service cd /opt/ git clone https://github.com/mikebrady/nqptp.git cd nqptp autoreconf -fi ./configure --with-systemd-startup make sudo make install print_info "Enable and start NQPTP" sudo systemctl enable nqptp sudo systemctl start nqptp print_info "Installation of Shairport Sync with Airplay 2" cd /opt git clone https://github.com/mikebrady/shairport-sync.git cd shairport-sync autoreconf -fi ./configure \ --sysconfdir=/etc \ --with-alsa \ --with-soxr \ --with-avahi \ --with-ssl=openssl \ --with-systemd \ --with-metadata \ --with-mqtt-client \ --with-airplay-2 #--with-apple-alac \ make && sudo make install # Starting and enabling systemd service sudo systemctl enable shairport-sync sudo systemctl start shairport-sync systemctl status shairport-sync ```

BTW, thanks for the help, I have already invited you to a coffee, is the least I can do.

mikebrady commented 1 year ago

Many thanks for the comprehensive report (and the coffee!). Hopefully your scripts will be useful to future users.