Friday, August 29, 2025

Building ffmpeg 8.0 with MP3 support on macOS Sequoia on Silicon

So the other day I needed to strip the audio out of an mp4 and turn it into an mp3.  It's a long story that goes on to involve OpenAI Whisper making a transcription that I could feed into DeepL for translation and finally outputting it as an SRT file.  "Hey, I could just write a Python script to do that."

But first, I'd need to shave a yak.

You see, the slam-dunk tool for doing something like this is ffmpeg.  The only problem is that you can't just download ffmpeg from the macOS app store.  You can get it from homebrew, but if you're going to trust some janky package off the internet, well, you might as well go all-in and build it from source.  At least then you know what's in it.

What's not in it is a few necessary libraries.  I'd need one to handle the MP3 encoding.  And for that I'd need pkg-config.  And at least I already had Xcode and its command-line utilities installed, so that yak was already shaved.  Here's what I ran on the command-line to get it all working.

Step 1, build and install pkg-config on a Silicon Mac:

As of this writing, the latest version is 0.29.2.  You should probably pop over to the releases site in a browser and see what the current version is.  But here's what works for 0.29.2.

cd /tmp
curl -OL https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
tar -xzf pkg-config-0.29.2.tar.gz
cd pkg-config-0.29.2
CFLAGS="-Wno-int-conversion" CXXFLAGS="-Wno-int-conversion" \
  ./configure --with-internal-glib
make
sudo make install
pkg-config --version  # should return 0.29.2
cd ..

Step 2, build and install LAME (for MP3 support)

As of this writing, LAME is version 3.100, so that's what I used.  Go double-check there's not a newer one.

curl -OL https://sourceforge.net/projects/lame/files/lame/3.100/lame-3.100.tar.gz
tar -xzf lame-3.100.tar.gz
cd lame-3.100
sed -i -e "/lame_init_old/d" include/libmp3lame.sym
./configure
make
sudo make install
lame --version  # Should say 3.100
cd ..

Step 3, build and install H.264 support (optional, but I wanted it)

This will grab the latest no matter what.

git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-static
make
sudo make install
h264 --version  # Should show a version and that you just built it
cd ..

Step 4, build and install ffmpeg (finally)

They'd just released version 8 so that's what I went with.  As before, check my version numbers against whatever's current and modify these commands as appropriate.

curl -OL https://ffmpeg.org/releases/ffmpeg-8.0.tar.gz
tar -xzf ffmpeg-8.0.tar.gz
cd ffmpeg-8.0
./configure --prefix=/usr/local --enable-gpl \
  --enable-nonfree --enable-libmp3lame --enable-libx264 \
  --enable-shared
make
sudo make install
ffmpeg  # Should show version and usage information
cd ..

Step 5, try it out

My original goal was to strip the audio out of an mp4 and have an mp3 as the result.  Here's an ffmpeg command that does that, assuming you have a file called test-clip.mp4 in the current working directory and want to produce a file called test-clip.mp3.

ffmpeg -i test-clip.mp4 -vn -codec:a libmp3lame  test-clip.mp3

Works on my laptop! (tm)

Hopefully this saves someone some time.  If you try this on your own Sequoia system on Silicon and find you have to change anything, please let me know!

Thursday, May 22, 2025

Just a QR Code

Every once in a while you need to generate a QR code.  You type "qr" into your address bar and hope your history still has something useful, but when it doesn't, you go ahead and google it.  Reviewing the array of results, you pick the least sketchy-looking one.  You enter your text, save the QR code, and quickly close the browser tab.  Why so furtive?

Because you know that the site's not just randomly passionate about giving free QR codes to the world -- it's not some Johnny Appleseed of machine-vision -- someone expects to get paid.  And that's why the page includes ads, it's laden with trackers, whatever you type is sent to a remote server, and it's setting all kinds of cookies on your browser.  All for just a QR code.

"Isn't it possible to just make a one-page website that uses Javascript to generate QR codes?  Something I could save to disk and run locally," I pondered.

Screenshot of the just a QR code dot com site
Yes.  Yes it is.  (Spoiler, here it is.)

In about 19k of HTML and Javascript (and half of that is comments and easter eggs) it does exactly what you'd expect.  You type something, it makes a QR code.  You can also set the size, error correction, and colors.  And that's it.  Just a QR code.  Holy heck it works.  And there is no "pro" plan.

I uploaded it to my webserver for sharing.  And as I looked at the URL I realized, yes, I definitely need to be paying for another single-project custom domain name.  My project shall have no path in its URL!  It shall be the one and true main page.  After half an hour of trying to be clever, I discovered that "just a qr code" dot com was available for ten bucks.  Sure, whatever.  Ship it!

I present to you: justaqrcode.com

Check it out -- you can view the page source and confirm that it doesn't send anything anywhere.  There are no trackers.  You can save it to your local disk and run it from there.  Go ahead and modify your copy to suit your own needs.

What's my payback for the domain name and hosting costs?  I don't know.  But I'm really annoyed at the state of the world right now and this is somehow my way of fighting back.  I'll keep paying for the domain name and hosting, and you keep being awesome.