SoX MP4 support - lmmx/devnotes GitHub Wiki

SoX lists MP4 support on its features page:

MP4, AAC, AC3, WAVPACK, AMR-NB files (with optional ffmpeg library)

So install ffmpeg:

sudo apt install ffmpeg

To check the formats sox and ffmpeg will read:

sox --help-format all
ffmpeg -formats
ffmpeg -codecs
  • ffmpeg -formats gives a line:

      E mp4             MP4 (MPEG-4 Part 14)
    

    in which the E indicates "Muxing supported"

To test out the support:

sox output.mp4 output.wav

sox FAIL formats: no handler for file extension `mp4'

or even simply use the play utility SoX provides:

play output.mp4

play WARN alsa: can't encode 0-bit Unknown or not applicable
play FAIL formats: no handler for file extension `mp4'

Since sox doesn't work with ffmpeg to read MP4 'out of the box' (i.e. from pre-built binary) we will follow this suggestion:

Yes..sox has support for mp4, m4p, & m4a. They're marked as optional in the pdf manual. Perhaps one has to compile sox from the source files e.g. the sox(version number).tar.gz source package...unpack it using an archive manager, then do something like make, make install, etc... while including the additional option for the mp4 types of files. Checkout the README file in the package to make sure.

First remove the apt-installed binary and any other libraries it pulled in:

sudo apt purge --autoremove sox

The following packages will be REMOVED
  libsox-fmt-alsa* libsox-fmt-base* libsox3* sox*

The source code can be downloaded from the repo as

git clone https://git.code.sf.net/p/sox/code sox-code

in which the README.osx (by which they mean Unix, i.e. OSX and Linux)

In an appendix, the README says:

sox OSX repo appendix: MP3 support

Appendix - MP3 Support

SoX contains support for reading and writing MP3 files but does not ship with the dylib's that perform decoding and encoding of MP3 data because of patent restrictions. For further details, refer to:

https://en.wikipedia.org/wiki/MP3#Licensing_and_patent_issues

MP3 support can be enabled by placing Lame encoding library and/or MAD decoding library into a standard library search location such as /usr/lib or set LTDL_LIBRARY_PATH to location.

These can be compiled yourself, they may turn up on searches of the internet or may be included with other MP3 applications already installed on your system. Try searching for libmp3lame.dylib and libmad.dylib.

Obtain the latest Lame and MAD source code from approprate locations.

If your system is setup to compile software, then the following commands can be used. Note: since SoX is distributed as a 32-bit i386 binary, the library must match that format as well:

cd lame-398-2
./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386"
make
sudo make install


cd libmad-0.15.1b
./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386"
make
sudo make install

The -m32 flag to gcc is mentioned here in a suggestion of the unusual format:

CPPFLAGS=-m32 ./configure ...

and then below this a longer suggestion:

./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"

which has the CXXFLAGS parameter set too. The suggestion we got for MP3s just had CFLAGS and LDFLAGS

./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386"

(Come back here if the configure step encounters problems)

So even though it's not stated, we can compare this instruction to the listing for MP3 on the features page:

MP2/MP3 (with optional libmad, libtwolame and libmp3lame libraries)

To get MP4 support for SoX we’ll need to compile 32-bit i386 binaries and statically link them somewhere SoX can find them like /usr/lib/.

So by rephrasing the MP3 instructions, we can surmise that the requirements for MP4 will be something like:

  • "placing FFMPEG encoding library and/or FFMPEG decoding library into a standard library search location such as /usr/lib or set LTDL_LIBRARY_PATH to location."

    • FFMPEG “offers MPEG-4 Part 2 video encoder under LGPL, and MPEG-4 Part 10 through libx264 under GPL” (via)
      • x264 “is just an encoder” (like LAME is for MP3)
      • “Codecs in the libavcodec library from the FFmpeg project [include] MPEG-4 part 2”
      • “Decoders in the libavcodec library [include] H.264” (like MAD is for MP3)
    • The FFMPEG source code includes 7 libraries:
      libavcodec libavformat libavutil libavfilter libavdevice libswresample libswscale
      
    • Of these, libavcodec is the only encoding/decoding library, but libavformat sounds important too(?)
      • In fact, the SoX suggestion was to install the ffmpeg library, so we should do that (and therefore build all of the sub-libraries) not just libavcodec.
      • I checked with the FFMPEG-gers and they confirmed "you might not want to bring in FFMPEG's libraries if all you want is audio resampling etc". That is, there will be many libraries that get built and put in /usr/lib/i386-linux-gnu/
  • "These can be compiled yourself, they may turn up on searches of the internet or may be included with other MP3 applications already installed on your system. Try searching for libmp4ffmpeg.dylib and libffmpeg.dylib."

    • The 32-bit versions will not be likely to be found on a 64-bit system I'd presume, but may be available online (but I’d rather just build myself)
    • My system already has i386 packages in /usr/lib/i386-linux-gnu/ but while it has /usr/lib/x86_64-linux-gnu/libavcodec.so.58 there is no /usr/lib/i386-linux-gnu/libavcodec.so.58 (so I would expect it to turn up here after installation and can remove this specific file to uninstall).
  • Obtain the latest FFMPEG source code from approprate locations. (GitHub or FFMPEG or FFMPEG git tree)

    git clone https://github.com/FFmpeg/FFmpeg ffmpeg_i386
    cd ffmpeg_i386/libavcodec
    ./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386"
    make
    sudo make install

However a problem arises: there's no configure for libavcodec alone! That leaves 2 options:

  • Build ffmpeg from source but add a bunch of flags that prevent installing all libraries (?)
  • Install from APT: apt install libavcodec-extra:i386 (use --dry-run to just see what would change)

For reference, here's the current output of ffmpeg:

STDERR output of ffmpeg

ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-liblensfun --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

and a quick way to backup a list of your installed libraries

Shell script to back up a list of installed libraries

ls /usr/lib > ./usr_lib_list.txt
ls /usr/lib/i386-linux-gnu > ./usr_lib_i386_list.txt
ls /usr/lib/x86_64-linux-gnu > ./usr_lib_x86_list.txt

and here's what was installed:

apt output for "libavcodec-extra:i386"

The following additional packages will be installed:
  i965-va-driver:i386 intel-media-va-driver:i386 libaom0:i386 libaribb24-0:i386 libavcodec-extra58:i386 libavutil56:i386 libblkid1:i386 libcairo-gobject2:i386 libcairo2:i386 libcodec2-0.9:i386 libdatrie1:i386 libfontconfig1:i386
  libfreetype6:i386 libfribidi0:i386 libgdk-pixbuf2.0-0:i386 libglib2.0-0:i386 libgomp1:i386 libgraphite2-3:i386 libgsm1:i386 libharfbuzz0b:i386 libicu66:i386 libigdgmm11:i386 libjbig0:i386 libjpeg-turbo8:i386 libjpeg8:i386
  liblzma5:i386 libmount1:i386 libmp3lame0:i386 libnuma1:i386 libogg0:i386 libopencore-amrnb0:i386 libopencore-amrwb0:i386 libopenjp2-7:i386 libopus0:i386 libpango-1.0-0:i386 libpangocairo-1.0-0:i386 libpangoft2-1.0-0:i386
  libpcre2-8-0:i386 libpcre3:i386 libpixman-1-0:i386 libpng16-16:i386 librsvg2-2:i386 librsvg2-common:i386 libselinux1:i386 libshine3:i386 libsnappy1v5:i386 libsoxr0:i386 libspeex1:i386 libswresample3:i386 libthai0:i386 libtheora0:i386
  libtiff5:i386 libtwolame0:i386 libuuid1:i386 libva-drm2:i386 libva-x11-2:i386 libva2:i386 libvdpau1:i386 libvo-amrwbenc0:i386 libvorbis0a:i386 libvorbisenc2:i386 libvpx6:i386 libwavpack1:i386 libwebp6:i386 libwebpmux3:i386
  libx264-155:i386 libx265-179:i386 libxcb-render0:i386 libxcb-shm0:i386 libxml2:i386 libxrender1:i386 libxvidcore4:i386 libzvbi0:i386 mesa-va-drivers:i386 mesa-vdpau-drivers:i386 ocl-icd-libopencl1:i386 va-driver-all:i386
  vdpau-driver-all:i386
Suggested packages:
  i965-va-driver-shaders:i386 opus-tools:i386 librsvg2-bin:i386 speex:i386 libvdpau-va-gl1:i386 nvidia-vdpau-driver:i386 nvidia-legacy-340xx-vdpau-driver:i386 nvidia-legacy-304xx-vdpau-driver:i386
The following NEW packages will be installed
  i965-va-driver:i386 intel-media-va-driver:i386 libaom0:i386 libaribb24-0:i386 libavcodec-extra:i386 libavcodec-extra58:i386 libavutil56:i386 libblkid1:i386 libcairo-gobject2:i386 libcairo2:i386 libcodec2-0.9:i386 libdatrie1:i386
  libfontconfig1:i386 libfreetype6:i386 libfribidi0:i386 libgdk-pixbuf2.0-0:i386 libglib2.0-0:i386 libgomp1:i386 libgraphite2-3:i386 libgsm1:i386 libharfbuzz0b:i386 libicu66:i386 libigdgmm11:i386 libjbig0:i386 libjpeg-turbo8:i386
  libjpeg8:i386 liblzma5:i386 libmount1:i386 libmp3lame0:i386 libnuma1:i386 libogg0:i386 libopencore-amrnb0:i386 libopencore-amrwb0:i386 libopenjp2-7:i386 libopus0:i386 libpango-1.0-0:i386 libpangocairo-1.0-0:i386 libpangoft2-1.0-0:i386
  libpcre2-8-0:i386 libpcre3:i386 libpixman-1-0:i386 libpng16-16:i386 librsvg2-2:i386 librsvg2-common:i386 libselinux1:i386 libshine3:i386 libsnappy1v5:i386 libsoxr0:i386 libspeex1:i386 libswresample3:i386 libthai0:i386 libtheora0:i386
  libtiff5:i386 libtwolame0:i386 libuuid1:i386 libva-drm2:i386 libva-x11-2:i386 libva2:i386 libvdpau1:i386 libvo-amrwbenc0:i386 libvorbis0a:i386 libvorbisenc2:i386 libvpx6:i386 libwavpack1:i386 libwebp6:i386 libwebpmux3:i386
  libx264-155:i386 libx265-179:i386 libxcb-render0:i386 libxcb-shm0:i386 libxml2:i386 libxrender1:i386 libxvidcore4:i386 libzvbi0:i386 mesa-va-drivers:i386 mesa-vdpau-drivers:i386 ocl-icd-libopencl1:i386 va-driver-all:i386
  vdpau-driver-all:i386

To check what changed (what was installed) by this command, run

diff <(ls /usr/lib/i386-linux-gnu/) <(cat usr_lib_i386_list.txt) | grep -E "^<"

The following line of output indicates the file /usr/lib/i386-linux-gnu/libavcodec.so.58 exists (i.e. version 58 of libavcodec):

< libavcodec.so.58
  • (There should be nothing uninstalled, i.e. changing the last argument to "^>" should give nothing)

Additionally, no non-i386 libraries should've changed. These should give nothing:

diff <(ls /usr/lib/x86_64-linux-gnu/) <(cat usr_lib_x86_list.txt)
diff <(ls /usr/lib/) <(cat usr_lib_list.txt)

The point of all of this was so SoX would be able to use them.

First I tried to just re-install it and check if anything changed (I didn't expect it to, as it was pre-built so obviously could not find the statically linked libraries I just installed) then I moved on to build from source:

  • There is a configure.ac file but no configure script so we run autoconf (via)

I'd expect something like this:

cd sox-code
autoconf
./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386"
make
sudo make install

The file osxbuild is a little more complex (and specific to OSX) but involves:

autoreconf -i
  • The -i is for "install" and means the missing auxiliary files (in particular configure will be "installed" to the directory, i.e. created there)

so first get autoreconf from autoconf:

apt install autoconf
  • We get the same error twice: Libtool library used but 'LIBTOOL' is undefined
    • It suggests to put LT_INIT in configure.ac or to check its definition is in aclocal's search path
    • Inspecting configure.ac, the variable LT_INIT is set as LT_INIT([win32-dll]), clearly wrong!

So it seems the standard version of sox is Mac-only, boo. However this just means that it can't be how the Ubuntu-distributed binaries were built, which means that we must be able to get their source tarballs from launchpad and build those instead, never mind the official repo.

By following the upstream link from the sox package in Ubuntu to the sox project to the repo for sox

...but this has the same problem, the LT_INIT line says "win32-dll"...

Another option is to download the package source through APT (into the current working directory)

cd ~/opt
apt-get source sox

However I get the error that I "don't have src URIs" in /etc/apt/sources.list

  • I'm on Mint 20.1 Ulyssa with an Ubuntu 20.04 Focal Fossa base

  • This suggests software-properties-gtk (available as "Software Sources" in the menu), which has an option for "Source code repositories", which when set to use updates the APT cache.

  • Upon running apt-get source sox again, I now get notified:

    NOTICE: 'sox' packaging is maintained in the 'Git' version control system at: https://salsa.debian.org/multimedia-team/sox.git

  • If we once again download the source code from the real packaged repo source:

    git clone https://salsa.debian.org/multimedia-team/sox.git sox-deb
  • It turns out this is actually on the launchpad page (click the "Latest upload" then the tarball there has the same content as the git repo)

  • We can see with diff that there is no difference (except of course that we get the .git directory in sox-deb). If you're doing this manually I'd go for the git repo for neatness, if automating efficiently go for the tarball and unpack it.

So once again uninstall sox:

sudo apt purge --autoremove sox

and now this repo has actually got some auxiliary files like configure, so no need to run autoreconf, and we can use the original plan for installing:

cd sox-deb
./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386"
make
sudo make install

This time the configure step gives the following error

configure error (build, host, target all x86)

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/home/louis/opt/sox-deb':
configure: error: C compiler cannot create executables
See `config.log' for more details
  • We can see the error arises on the first 3 lines: target system type should not be x86_64-unknown-linux-gnu, we're targetting i386!

  • C compiler cannot create executables is an error that arises when "cross-compiling", that is when compiling for a different target OS than the build/host system's (which here is compiling for 32-bit Linux while the host is 64-bit Linux).

  • To overcome it, we need to supply the configure call with the information since it won't guess it from the CFLAGS (either of these are fine):

    --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu
    --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=i386-unknown-linux-gnu
configure retry (passing in build, host, target)

This makes the full setup:

cd sox-deb
./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu
make
sudo make install

The configure call then gives:

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... i386-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for x86_64-unknown-linux-gnu-gcc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/home/louis/opt/sox-deb':
configure: error: C compiler cannot create executables
See `config.log' for more details

Aside: a cool option to get around this is LXD as here

I can silence the failing checks for x86_64-unknown-linux-gnu-gcc by omitting the --build and --host flags, doing so doesn't stop the C compiler check failing though, which highlights the real problem upon inspecting config.log:

configure:3677: checking whether the C compiler works
configure:3699: gcc -arch i386 -m32  -arch i386 conftest.c  >&5
gcc: error: i386: No such file or directory
gcc: error: i386: No such file or directory
gcc: error: unrecognized command line option '-arch'
gcc: error: unrecognized command line option '-arch'

and that's because it's for OSX gcc, which makes sense as the original README I was reading from was for OSX

The -arch option is part of the Apple extensions to gcc. You need to use the gcc supplied by Apple's Developer Tools, Xcode.

checking man shows that it should be -march instead

The -arch option is only in the Apple-provided version of gcc. Change CFLAGS (which might be set via your environment, your makefile, or your configure options) so it uses -march or -m32 instead.

This changes the configure call to:

./configure CFLAGS="-march=i386 -m32" LDFLAGS="-march=i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu

and finally a more interesting error appears in config.log:

config.log (missing Scrt1.o/crti.o, obtained via libc6-dev:i386)

configure:3677: checking whether the C compiler works
configure:3699: gcc -march=i386 -m32  -march=i386 conftest.c  >&5
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status

Looking up these files Scrt1.o and crti.o, I found (1, 2) they can be acquired from the package musl-dev (on APT), however this usually seems to occur in Docker (Alpine Linux is a minimal Linux distro for application containers). I tried installing it and it didn't change the error, so I uninstalled it again.

In fact, I can see the files were already there:

find / -iname "Scrt1.o" 2> /dev/null
find / -iname "crti.o" 2> /dev/null

/usr/lib/x86_64-linux-gnu/Scrt1.o
/usr/lib/x86_64-linux-gnu/crt1.o

This was also explored here (this Q&A seems to suggest they come from libc6-dev but I'm not certain of this).

It suggests gcc -print-search-dirs to diagnose the search paths, which for me gives:

gcc -print-search-dirs | tr ":" "\n"

install
 /usr/lib/gcc/x86_64-linux-gnu/9/
programs
 =/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries
 =/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/
/lib/x86_64-linux-gnu/9/
/lib/x86_64-linux-gnu/
/lib/../lib/
/usr/lib/x86_64-linux-gnu/9/
/usr/lib/x86_64-linux-gnu/
/usr/lib/../lib/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../
/lib/
/usr/lib/
  • There are a lot of lines here, the only important one is /usr/lib/x86_64-linux-gnu/ (6th line from the last)

I also tried a completely unrelated cross-compilation of cgo:

So the problem is that for the cross-compiler to properly find its headers and libraries it needs a --sysroot option, in your case --sysroot /am335x_toolchain/ added both to CGO_CFLAGS and CGO_LDFLAGS.

By analogy we would change /am335x_toolchain/ to /usr/lib/x86_64-linux-gnu/, so the configure call would become:

./configure CFLAGS="-march=i386 -m32 --sysroot=/usr/lib/x86_64-linux-gnu/" LDFLAGS="-march=i386 --sysroot=/usr/lib/x86_64-linux-gnu/" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu

...but this made no difference

Adding -print-search-dirs to the CFLAGS confirmed that /usr/lib/x86_64-linux-gcc is definitely searched when looking for the files it says it can't find

configure:3677: checking whether the C compiler works
configure:3699: gcc -march=i386 -m32 -print-search-dirs  -march=i386 conftest.c  >&5
install: /usr/lib/gcc/x86_64-linux-gnu/9/
programs:
=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/i386-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries:
=/usr/lib/gcc/x86_64-linux-gnu/9/32/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/32/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/i386-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib32/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/32/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../i386-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib32/:/lib/x86_64-linux-gnu/9/32/:/lib/i386-linux-gnu/:/lib/../lib32/:/usr/lib/x86_64-linux-gnu/9/32/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib32/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/i386-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../i386-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/x86_64-linux-gnu/9/:/lib/i386-linux-gnu/:/lib/:/usr/lib/x86_64-linux-gnu/9/:/usr/lib/i386-linux-gnu/:/usr/lib/
configure:3703: $? = 0
configure:3741: result: no

If we split those lines of programs and libraries at the colons we get

tail --lines=+112 config.log | head -2 | tr ":" "\n"

programs
 =/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/i386-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries
 =/usr/lib/gcc/x86_64-linux-gnu/9/32/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/32/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/i386-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib32/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/32/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../i386-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib32/
/lib/x86_64-linux-gnu/9/32/
/lib/i386-linux-gnu/
/lib/../lib32/
/usr/lib/x86_64-linux-gnu/9/32/
/usr/lib/i386-linux-gnu/
/usr/lib/../lib32/
/usr/lib/gcc/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/i386-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../i386-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/9/../../../
/lib/x86_64-linux-gnu/9/
/lib/i386-linux-gnu/
/lib/
/usr/lib/x86_64-linux-gnu/9/
/usr/lib/i386-linux-gnu/
/usr/lib/

Again there are a lot of lines, but notice that the one important line (/usr/lib/x86_64-linux-gnu/) is now missing! Instead, there is /usr/lib/i386-linux-gnu/, which suggests two solutions could resolve this error:

  1. Add /usr/lib/x86_64-linux-gnu/ to the library search path
  2. Add the i386 packages which provide these dependencies

As mentioned above, it appears that the files in question come from libc6-dev, which I verified with:

dpkg -S crti.o

libc6-dev:amd64: /usr/lib/x86_64-linux-gnu/crti.o

To get an i386 build of the package we just run

apt install libc6-dev:i386

The following additional packages will be installed:
  libcrypt-dev:i386 linux-libc-dev:i386
Suggested packages:
  glibc-doc:i386
The following NEW packages will be installed
  libc6-dev:i386 libcrypt-dev:i386 linux-libc-dev:i386

...and now we have

find / -iname "Scrt1.o" 2> /dev/null
find / -iname "crti.o" 2> /dev/null

/usr/lib/i386-linux-gnu/Scrt1.o
/usr/lib/x86_64-linux-gnu/Scrt1.o
/usr/lib/i386-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crt1.o

...so I'd expect the configure call to work now...

./configure CFLAGS="-march=i386 -m32" LDFLAGS="-march=i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu

configure:3677: checking whether the C compiler works
configure:3699: gcc -march=i386 -m32  -march=i386 conftest.c  >&5
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status

So now we just need to get a compatible (presumably i386) libgcc.a file

dpkg -S libgcc.a

libgcc-9-dev:amd64: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a
(Mistaken attempt to install libgcc-9-dev:i386

[Spoiler: wrong] So this suggests we also need:

apt install libgcc-9-dev:i386

The following additional packages will be installed:
  gcc-9-base:i386 libasan5:i386 libitm1:i386 libquadmath0:i386 libubsan1:i386
The following NEW packages will be installed
  gcc-9-base:i386 libasan5:i386 libgcc-9-dev:i386 libitm1:i386 libquadmath0:i386
  libubsan1:i386

...and again run the configure call... but no change, so this was removed.

In fact, the suggested approach is to install 32-bit versions of the development libraries (not mentioned in the sox README!)

sudo apt install gcc-multilib g++-multilib libc6-dev-i386

and finally we get a compilation!

Successfull configure output

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... i386-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for x86_64-pc-linux-gnu-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking whether ln -s works... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format...
func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for x86_64-pc-linux-gnu-objdump... no
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for x86_64-pc-linux-gnu-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for x86_64-pc-linux-gnu-ar... no
checking for ar... ar
checking for archiver @FILE support... @
checking for x86_64-pc-linux-gnu-strip... no
checking for strip... strip
checking for x86_64-pc-linux-gnu-ranlib... no
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for x86_64-pc-linux-gnu-mt... no
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_i386) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for shl_load... no
checking for shl_load in -ldld... no
checking for dlopen... no
checking for dlopen in -ldl... yes
checking whether a program can dlopen itself... yes
checking whether a statically linked program can dlopen itself... no
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for x86_64-pc-linux-gnu-pkg-config... /usr/bin/x86_64-pc-linux-gnu-pkg-config
checking pkg-config is at least version 0.9.0... yes
checking whether to make a debug build... 
checking whether libssp exists... no
checking whether stack-smashing protection is available... yes
checking whether stack-smashing protection is buggy... yes
checking gcc version... 9
checking whether byte ordering is bigendian... no
checking for inline... inline
checking for ANSI C header files... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for unistd.h... (cached) yes
checking byteswap.h usability... yes
checking byteswap.h presence... yes
checking for byteswap.h... yes
checking for sys/stat.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/timeb.h usability... yes
checking sys/timeb.h presence... yes
checking for sys/timeb.h... yes
checking for sys/types.h... (cached) yes
checking sys/utsname.h usability... yes
checking sys/utsname.h presence... yes
checking for sys/utsname.h... yes
checking termios.h usability... yes
checking termios.h presence... yes
checking for termios.h... yes
checking glob.h usability... yes
checking glob.h presence... yes
checking for glob.h... yes
checking fenv.h usability... yes
checking fenv.h presence... yes
checking for fenv.h... yes
checking for strcasecmp... yes
checking for strdup... yes
checking for popen... yes
checking for vsnprintf... yes
checking for gettimeofday... yes
checking for mkstemp... yes
checking for fmemopen... yes
checking for library containing pow... -lm
checking for library containing lrint... none required
checking for lrint... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for _LARGEFILE_SOURCE value needed for large files... no
configure: Forcing _LARGEFILE_SOURCE to be safe since off_t is 64 bits
checking whether libtool should be silenced... yes
checking ltdl.h usability... no
checking ltdl.h presence... no
checking for ltdl.h... no
checking for gcc option to support OpenMP... -fopenmp
checking for libtool version... 2.4.2, OK
checking magic.h usability... no
checking magic.h presence... no
checking for magic.h... no
checking png.h usability... no
checking png.h presence... no
checking for png.h... no
checking libpng/png.h usability... no
checking libpng/png.h presence... no
checking for libpng/png.h... no
checking mad.h usability... no
checking mad.h presence... no
checking for mad.h... no
checking whether to dlopen mad... no
checking for mad_stream_buffer in -lmad... no
checking id3tag.h usability... no
checking id3tag.h presence... no
checking for id3tag.h... no
checking whether to dlopen lame... no
checking lame/lame.h usability... no
checking lame/lame.h presence... no
checking for lame/lame.h... no
checking lame.h usability... no
checking lame.h presence... no
checking for lame.h... no
checking for lame_get_lametag_frame in -lmp3lame... no
checking for id3tag_set_fieldvalue in -lmp3lame... no
checking twolame.h usability... no
checking twolame.h presence... no
checking for twolame.h... no
checking whether to dlopen twolame... no
checking for twolame_init in -ltwolame... no
checking gsm/gsm.h usability... no
checking gsm/gsm.h presence... no
checking for gsm/gsm.h... no
checking gsm.h usability... no
checking gsm.h presence... no
checking for gsm.h... no
checking for gsm_create in -lgsm... no
checking lpc10.h usability... no
checking lpc10.h presence... no
checking for lpc10.h... no
checking for lpc10.h... (cached) no
checking for create_lpc10_encoder_state in -llpc10... no
checking vorbis/codec.h usability... no
checking vorbis/codec.h presence... no
checking for vorbis/codec.h... no
checking for OPUS... no
checking FLAC/all.h usability... no
checking FLAC/all.h presence... no
checking for FLAC/all.h... no
checking opencore-amrwb/dec_if.h usability... no
checking opencore-amrwb/dec_if.h presence... no
checking for opencore-amrwb/dec_if.h... no
checking amrwb/dec.h usability... no
checking amrwb/dec.h presence... no
checking for amrwb/dec.h... no
checking opencore-amrnb/interf_dec.h usability... no
checking opencore-amrnb/interf_dec.h presence... no
checking for opencore-amrnb/interf_dec.h... no
checking amrnb/sp_dec.h usability... no
checking amrnb/sp_dec.h presence... no
checking for amrnb/sp_dec.h... no
checking wavpack/wavpack.h usability... no
checking wavpack/wavpack.h presence... no
checking for wavpack/wavpack.h... no
checking sndio.h usability... no
checking sndio.h presence... no
checking for sndio.h... no
checking CoreAudio/CoreAudio.h usability... no
checking CoreAudio/CoreAudio.h presence... no
checking for CoreAudio/CoreAudio.h... no
checking alsa/asoundlib.h usability... no
checking alsa/asoundlib.h presence... no
checking for alsa/asoundlib.h... no
checking ao/ao.h usability... no
checking ao/ao.h presence... no
checking for ao/ao.h... no
checking pulse/simple.h usability... no
checking pulse/simple.h presence... no
checking for pulse/simple.h... no
checking for mmsystem.h... no
checking for SNDFILE... no
checking sndfile.h usability... no
checking sndfile.h presence... no
checking for sndfile.h... no
checking sys/soundcard.h usability... yes
checking sys/soundcard.h presence... yes
checking for sys/soundcard.h... yes
checking sys/audioio.h usability... no
checking sys/audioio.h presence... no
checking for sys/audioio.h... no
checking sun/audioio.h usability... no
checking sun/audioio.h presence... no
checking for sun/audioio.h... no
checking whether to enable symlinks... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating libgsm/Makefile
config.status: creating lpc10/Makefile
config.status: creating msvc9/Makefile
config.status: creating msvc10/Makefile
config.status: creating sox.pc
config.status: creating src/soxconfig.h
config.status: src/soxconfig.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands

BUILD OPTIONS
Debugging build............no
Distro name ...............not specified!
Dynamic loading support....no
Pkg-config location........$(libdir)/pkgconfig
Play and rec symlinks......yes
Symlinks enabled...........yes

OPTIONAL DEVICE DRIVERS
ao (Xiph)..................no
alsa (Linux)...............no
coreaudio (Mac OS X).......no
sndio (OpenBSD)............no
oss........................yes
pulseaudio.................no
sunaudio...................no
waveaudio (MS-Windows).....no

OPTIONAL FILE FORMATS
amrnb......................no
amrwb......................no
flac.......................no
gsm........................yes (in-tree)
lpc10......................yes (in-tree)
mp2/mp3....................no
 id3tag....................no
 lame......................no
 mad.......................no
 twolame...................no
oggvorbis..................no
opus.......................no
sndfile....................no
wavpack....................no

OTHER OPTIONS
ladspa effects.............no
magic support..............no
png support................no
OpenMP support.............yes, -fopenmp

Configure finished.  Do 'make -s && make install' to compile and install SoX.
Attempt to make install (spoiler: needs autoreconf first and install libtool)

and then just

make
sudo make install

Here make gives a warning:

WARNING: 'aclocal-1.14' is missing on your system.
         You should only need it if you modified 'acinclude.m4' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'aclocal' program is part of the GNU Automake package:
         <http://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <http://www.gnu.org/software/autoconf>
         <http://www.gnu.org/software/m4/>
         <http://www.perl.org/>
make: *** [Makefile:473: aclocal.m4] Error 127

The solution to this is:

Before running ./configure try running autoreconf -f -i. The autoreconf program automatically runs autoheader, aclocal, automake, autopoint and libtoolize as required.

Edit to add: This is usually caused by checking out code from Git instead of extracting it from a .zip or .tar.gz archive. In order to trigger rebuilds when files change, Git does not preserve files' timestamps, so the configure script might appear to be out of date. As others have mentioned, there are ways to get around this if you don't have a sufficiently recent version of autoreconf.

Another edit: This error can also be caused by copying the source folder extracted from an archive with scp to another machine. The timestamps can be updated, suggesting that a rebuild is necessary. To avoid this, copy the archive and extract it in place.

That would be correct: I did get this from git.

Upon trying to run autoreconf -f -i I get told:

Can't exec "libtoolize": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 345, <GEN3> line 4.
autoreconf: failed to run libtoolize: No such file or directory
autoreconf: libtoolize is needed because this package uses Libtool

So just apt install libtool...

..and the eventual workflow is:

autoreconf -f -i
./configure CFLAGS="-arch i386 -m32" LDFLAGS="-arch i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu
make
sudo make install

...and it completed!

Unfortunately there are a couple of problems:

  • The binary is created as /usr/local/bin/i386-pc-linux-gnu-sox while the symlinks set up in /usr/local/bin/ (play, rec, soxi) point to /usr/local/bin/sox

    • This can be manually fixed by sudo ln -s /usr/local/bin/i386-pc-linux-gnu-sox /usr/local/bin/sox
    • There is probably a way to configure this but I'm not sure of it yet
  • When run (e.g. play some_file.mp4) you get the error:

    soxi: error while loading shared libraries: libsox.so.3: cannot open shared object file: No such file or directory
    

    which apparently indicates you're missing libsox-dev: if we look at the sox package dependencies we see this:

    apt show sox | grep -E "^Depends" | cut -d ":" -f 2- | tr "|" "\n"

    libsox-fmt-alsa (= 14.4.2+git20190427-2) 
    libsox-fmt-ao (= 14.4.2+git20190427-2) 
    libsox-fmt-oss (= 14.4.2+git20190427-2) 
    libsox-fmt-pulse (= 14.4.2+git20190427-2), libsox-fmt-base (= 14.4.2+git20190427-2), libsox3 (= 14.4.2+git20190427-2), libc6 (>= 2.29)
    
  • Note that this time, these dependencies are for running on the 64-bit OS, so they don't need to be i386(?)

    • Not all of them exist as i386:
      • libsox-fmt-alsa:i386 (exists)
      • libsox-fmt-ao:i386 (exists)
      • libsox-fmt-oss:i386 (exists)
      • libsox-fmt-pulse:i386 (exists)
      • libsox-fmt-base:i386 (does not exist)
      • libsox3:i386 (exists)
      • libc6:i386 (exists, installed along with libc6-dev:i386) (DO NOT TOUCH)
      • libsox-fmt-all (exists)
  • Attempting to install these also suggests libsox-fmt-all

APT install details

apt install libsox-fmt-alsa libsox-fmt-ao libsox-fmt-ao libsox-fmt-pulse libsox-fmt-base libsox3 libc6 libsox-fmt-all

libc6 is already the newest version (2.31-0ubuntu9.2).
The following additional packages will be installed:
  libsox-fmt-mp3 libsox-fmt-oss
The following NEW packages will be installed
  libsox-fmt-all libsox-fmt-alsa libsox-fmt-ao libsox-fmt-base libsox-fmt-mp3 libsox-fmt-oss
libsox-fmt-pulse libsox3
0 to upgrade, 8 to newly install, 0 to remove and 0 not to upgrade.
  • Attempting to install the i386 versions also suggests:
    • libaudio2:i386
    • libsndio6.1:i386
    • libasound2-plugins:i386
    • rng-tools:i386
APT install details (i386)

apt install libsox-fmt-alsa:i386 libsox-fmt-ao:i386 libsox-fmt-ao:i386 libsox-fmt-pulse:i386 libsox-fmt-base:i386 libsox3:i386 libsox-fmt-all:i386 # libc6:i386

The following additional packages will be installed:
  libao4:i386 libapparmor1:i386 libasound2:i386 libasyncns0:i386 libbz2-1.0:i386 libdbus-1-3:i386
libflac8:i386 libgcrypt20:i386 libgpg-error-l10n libgpg-error0:i386 libid3tag0:i386 libltdl7:i386
liblz4-1:i386 libmad0:i386
  libmagic1:i386 libpulse0:i386 libsndfile1:i386 libsox-fmt-mp3:i386 libsox-fmt-oss:i386
libsystemd0:i386 libvorbisfile3:i386 libwrap0:i386
Suggested packages:
  libaudio2:i386 libsndio6.1:i386 libasound2-plugins:i386 rng-tools:i386
The following NEW packages will be installed
  libao4:i386 libapparmor1:i386 libasound2:i386 libasyncns0:i386 libbz2-1.0:i386 libdbus-1-3:i386
libflac8:i386 libgcrypt20:i386 libgpg-error-l10n libgpg-error0:i386 libid3tag0:i386 libltdl7:i386
liblz4-1:i386 libmad0:i386
  libmagic1:i386 libpulse0:i386 libsndfile1:i386 libsox-fmt-all:i386 libsox-fmt-alsa:i386
libsox-fmt-ao:i386 libsox-fmt-base:i386 libsox-fmt-mp3:i386 libsox-fmt-oss:i386
libsox-fmt-pulse:i386 libsox3:i386 libsystemd0:i386
  libvorbisfile3:i386 libwrap0:i386
0 to upgrade, 28 to newly install, 0 to remove and 0 not to upgrade.

Now it builds with make -s && sudo make install and sudo ln -s /usr/local/bin/i386-pc-linux-gnu-sox /usr/local/bin/sox sets up the correct binary name via symlink (allowing play to link it)

...but after all that it still doesn't read MP4

play FAIL formats: no handler for file extension `mp4'

Frustratingly anticlimactic, but I built sox from source in the end at least...

Plan B ideas:

  • Install libavcodec-dev:i386

  • Install FFMPEG itself rather than just libavcodec (ffmpeg:i386)

I'll try them in that order.

Attempt to install libavcodec-dev:i386 and retry installation (unsuccessful)

apt install libavcodec-dev:i386

The following additional packages will be installed:
  libavutil-dev:i386 libswresample-dev:i386
The following NEW packages will be installed
  libavcodec-dev:i386 libavutil-dev:i386 libswresample-dev:i386
0 to upgrade, 3 to newly install, 0 to remove and 0 not to upgrade.
sudo make uninstall
sudo rm /usr/local/bin/sox # Remove symlink when uninstalling
./configure CFLAGS="-march=i386 -m32" LDFLAGS="-march=i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu
make -s && sudo make install
sudo ln -s /usr/local/bin/i386-pc-linux-gnu-sox /usr/local/bin/sox

(Still no change)

Lastly I'm going to try installing FFMPEG in its entirety on i386 (which annoyingly will uninstall ffmpeg, this is why people use containers I guess...

Attempt to install ffmpeg:i386 and retry installation (unsuccessful)

apt install ffmpeg:i386

The following package was automatically installed and is no longer required:
  libavresample4
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
  libass9:i386 libavc1394-0:i386 libavdevice58:i386 libavfilter7:i386 libavformat58:i386 libavresample4:i386 libbluray2:i386 libbs2b0:i386 libcaca0:i386 libcdio-cdda2:i386
  libcdio-paranoia2:i386 libcdio18:i386 libchromaprint1:i386 libcom-err2:i386 libdc1394-22:i386 libfftw3-double3:i386 libflite1:i386 libgme0:i386 libgmp10:i386 libgnutls30:i386
  libgpm2:i386 libgssapi-krb5-2:i386 libhogweed5:i386 libiec61883-0:i386 libjack-jackd2-0:i386 libk5crypto3:i386 libkeyutils1:i386 libkrb5-3:i386 libkrb5support0:i386 liblilv-0-0:i386
  libmpg123-0:i386 libmysofa1:i386 libncursesw6:i386 libnettle7:i386 libnorm1:i386 libopenal1:i386 libopenmpt0:i386 libp11-kit0:i386 libpgm-5.2-0:i386 libpostproc55:i386 libraw1394-11:i386
  librubberband2:i386 libsamplerate0:i386 libsdl2-2.0-0:i386 libserd-0-0:i386 libslang2:i386 libsndio7.0:i386 libsodium23:i386 libsord-0-0:i386 libsratom-0-0:i386 libssh-gcrypt-4:i386
  libssl1.1:i386 libswscale5:i386 libtasn1-6:i386 libudev1:i386 libusb-1.0-0:i386 libvidstab1.1:i386 libwayland-cursor0:i386 libwayland-egl1:i386 libxcb-shape0:i386 libxcursor1:i386
  libxi6:i386 libxinerama1:i386 libxkbcommon0:i386 libxrandr2:i386 libxss1:i386 libxv1:i386 libzmq5:i386
Suggested packages:
  ffmpeg-doc:i386 libbluray-bdj:i386 libfftw3-bin:i386 libfftw3-dev:i386 gnutls-bin:i386 gpm:i386 krb5-doc:i386 krb5-user:i386 jackd2:i386 libportaudio2:i386 libraw1394-doc:i386 serdi:i386
  sndiod:i386 sordi:i386
Recommended packages:
  libaacs0:i386
The following packages will be REMOVED
  ffmpeg
The following NEW packages will be installed
  ffmpeg:i386 libass9:i386 libavc1394-0:i386 libavdevice58:i386 libavfilter7:i386 libavformat58:i386 libavresample4:i386 libbluray2:i386 libbs2b0:i386 libcaca0:i386 libcdio-cdda2:i386
  libcdio-paranoia2:i386 libcdio18:i386 libchromaprint1:i386 libcom-err2:i386 libdc1394-22:i386 libfftw3-double3:i386 libflite1:i386 libgme0:i386 libgmp10:i386 libgnutls30:i386
  libgpm2:i386 libgssapi-krb5-2:i386 libhogweed5:i386 libiec61883-0:i386 libjack-jackd2-0:i386 libk5crypto3:i386 libkeyutils1:i386 libkrb5-3:i386 libkrb5support0:i386 liblilv-0-0:i386
  libmpg123-0:i386 libmysofa1:i386 libncursesw6:i386 libnettle7:i386 libnorm1:i386 libopenal1:i386 libopenmpt0:i386 libp11-kit0:i386 libpgm-5.2-0:i386 libpostproc55:i386 libraw1394-11:i386
  librubberband2:i386 libsamplerate0:i386 libsdl2-2.0-0:i386 libserd-0-0:i386 libslang2:i386 libsndio7.0:i386 libsodium23:i386 libsord-0-0:i386 libsratom-0-0:i386 libssh-gcrypt-4:i386
  libssl1.1:i386 libswscale5:i386 libtasn1-6:i386 libudev1:i386 libusb-1.0-0:i386 libvidstab1.1:i386 libwayland-cursor0:i386 libwayland-egl1:i386 libxcb-shape0:i386 libxcursor1:i386
  libxi6:i386 libxinerama1:i386 libxkbcommon0:i386 libxrandr2:i386 libxss1:i386 libxv1:i386 libzmq5:i386
0 to upgrade, 69 to newly install, 1 to remove and 0 not to upgrade.
sudo make uninstall
sudo rm /usr/local/bin/sox # Remove symlink when uninstalling
./configure CFLAGS="-march=i386 -m32" LDFLAGS="-march=i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu
make -s && sudo make install
sudo ln -s /usr/local/bin/i386-pc-linux-gnu-sox /usr/local/bin/sox

(Still no change, out of ideas, giving up for now...)

To undo the last step and put the system back to how I found it at this point:

sudo make uninstall
sudo rm /usr/local/bin/sox # Remove symlink when uninstalling
apt purge --autoremove ffmpeg:i386
apt install ffmpeg

At this point I dug into the search results for the more popular search result "sox compile with MP3 support", which took me via a StackOverflow comment to an archived blog post on CentOS which mentioned something I hadn't seen:

OPTIONAL FILE FORMATS
amrnb......................no
amrwb......................no
ffmpeg.....................no
flac.......................yes
gsm........................yes (in-tree)
lpc10......................yes (in-tree)
mp3........................yes
 id3tag....................yes
 lame......................yes
 dlopen lame...............no
 mad.......................yes
 dlopen mad................no
oggvorbis..................yes
sndfile....................no
wavpack....................no

This is apparently the output at the end of the configure call (which I had overlooked) so I re-ran it to see if I could diagnose the build's file formats.

apt purge --autoremove ffmpeg
apt install ffmpeg:i386
./configure CFLAGS="-march=i386 -m32" LDFLAGS="-march=i386" --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu | tee configure_tee.out

This time, at the configure step I tee the result to a file configure_tee.out... and it turns out that ffmpeg is not included here at all! It's no longer an option in the package being distributed via Ubuntu, which... explains it I suppose.

tail -42 configure_tee.out | head -40

BUILD OPTIONS
Debugging build............no
Distro name ...............not specified!
Dynamic loading support....no
Pkg-config location........$(libdir)/pkgconfig
Play and rec symlinks......yes
Symlinks enabled...........yes

OPTIONAL DEVICE DRIVERS
ao (Xiph)..................no
alsa (Linux)...............no
coreaudio (Mac OS X).......no
sndio (OpenBSD)............no
oss........................yes
pulseaudio.................no
sunaudio...................no
waveaudio (MS-Windows).....no

OPTIONAL FILE FORMATS
amrnb......................no
amrwb......................no
flac.......................no
gsm........................yes (in-tree)
lpc10......................yes (in-tree)
mp2/mp3....................no
 id3tag....................no
 lame......................no
 mad.......................no
 twolame...................no
oggvorbis..................no
opus.......................no
sndfile....................no
wavpack....................no

OTHER OPTIONS
ladspa effects.............no
magic support..............no
png support................no
OpenMP support.............yes, -fopenmp

The file formats that are supported are: amrnb, amrwb, flac, gsm, lpc10, mp2/mp3 (id3tag, lame, mad, twolame), oggvorbis, opus, sndfile, wavpack

...and the older versions of SoX that support MP4 can only be built with OSX!

To clean up and put everything back to normal:

apt purge --autoremove ffmpeg:i386
apt install ffmpeg sox

If we search the git repo for ffmpeg the most recent ChangeLog entry in fact states that the ffmpeg format was removed in 14.4.2 (which is the version still being distributed):

$ox-14.4.2      2015-02-22
----------

Previously deprecated features that have been removed in this release:

  Deprec-  Feature    [O(ption)]
  ated in  [F(ormat)] [E(ffect)]   Replacement
  -------  ----------------------  ----------------------
  14.3.0   O -1/-2/-3/-4/-8        -b
  14.3.0   O -s/-u/-f              -e
  14.3.0   O -A/-U/-o/-i/-a/-g     -e
  14.4.0   E swap with parameters  remix
  14.4.0   E mixer                 remix
  14.4.1   OpenMP < 3.0            OpenMP >= 3.0
  14.4.1   F ffmpeg                ffmpeg/avconv via pipe

Instead it is replaced by "ffmpeg/avconv via pipe". Case closed!

⚠️ **GitHub.com Fallback** ⚠️