I wanted to use some of Apple’s iconic audio sounds in a project, here’s how I did it.
Extracting the audio files
The first thing was to extract the raw audio files from iOS.
On a mac this process was pretty simple.
- download the
.ipsw
files from a site like IPSW Downloads - extract the correct
.dmg
which contains the files - navigate to
System/Library/Audio/UISounds
where the files are located
This resulted in around 300 individual audio files.
Using these files
Worth noting is that Apple use their own proprietory Core Audio Format .caf
file format which can be played using VLC.
My aim was to have an easy way of listening through them to identifying the ones I needed.
This turned out to be a four step process
- convert the audio format
- generate videos showing filenames
- compile an index of these videos
- concatenate them together
1. Convert the audio format
I used FFMPEG for this
#!/bin/bash
mkdir ./mp3/
for path in ./caf/*.caf; do
file=${path##*/}
ffmpeg -i "$path" -c:a mp3 -strict -2 "./mp3/${file%.*}.mp3"
done
#!/bin/bash
mkdir ./mp3/
for path in ./caf/*.caf; do
file=${path##*/}
ffmpeg -i "$path" -c:a mp3 -strict -2 "./mp3/${file%.*}.mp3"
done
Turns out this was necessary because of the .caf
format1 and audio sync issues.
… time is measured depending on the bitrate when importing aac files:
Estimating duration from bitrate, this may be inaccurate
2. Generate videos showing filenames
Again, using FFMPEG. The video includes a histogram of the audio and the filename.
#!/bin/bash
mkdir ./mp4/
for path in ./mp3/*.mp3; do
file=${path##*/}
ffmpeg -i "$path" -s hd1080 -filter_complex "[0:a]ahistogram,format=yuv420p,drawtext=text='${file}':x=(w-text_w)/2:y=(h-text_h)/2:fontfile=./font.otf:fontsize=36:fontcolor=white" -c:v libx264 "./mp4/${file%.*}.mp4"
done
#!/bin/bash
mkdir ./mp4/
for path in ./mp3/*.mp3; do
file=${path##*/}
ffmpeg -i "$path" -s hd1080 -filter_complex "[0:a]ahistogram,format=yuv420p,drawtext=text='${file}':x=(w-text_w)/2:y=(h-text_h)/2:fontfile=./font.otf:fontsize=36:fontcolor=white" -c:v libx264 "./mp4/${file%.*}.mp4"
done
Here is an example video generated.
Resources
FFMPEG
- Official FFmpeg Docs
- H.264 Video Encoding Guide
- Concatenating media files
- Show Filename in Video (fmpeg - drawtext)
- Adding silent audio in ffmpeg
- FFMPEG - video with timer
- Text on video ffmpeg
Command line scripting
- How do I remove the file suffix and path portion from a path string in Bash?
- Execute ffmpeg command in a loop
Audio sync issues
- FFMPEG concat video and audio out of sync
- FFMPEG concat makes video async over time
- Non-monotonous DTS in output stream when concat videos using ffmpeg
- FFMPEG is generating an out-of-sync audio/video file
- FFMPEG concatenate videos with audio not synched
Footnotes
-
From Superuser post Duration parameter being ignored ↩