While reading about credit card readers, I stumbled upon the concept of
backmasking. Thus, the question naturally arose: how would one play back an audio file in reverse on a Mac? This is the best one-liner I could come up with:
input=~/Downloads/audio.ogg; channels=2; rate=44100; tempfile=test.wav
ffmpeg -i $input -f s16le - | xxd -p -c$((channels * 2)) | tail -r | xxd -r -p | ffmpeg -f s16le -ar $rate -ac $channels -i - -y $tempfile && afplay $tempfile
Unfortunately, this requires creating a temporary output file, and knowing the rate and number of channels of the audio file. To break down the operations:
- the first ffmpeg command converts the file into raw audio data (signed shorts)
- the first xxd converts the audio data for a sample from each channel into an ascii hexadecimal line
- tail -r is the reversion command
- the second xxd reverses the ascii line into raw data
- the second ffmpeg creates a temporary audio file from the raw data, given the rate and channel count
- afplay plays the file out