Posts Tagged ‘audio’

option click on volume menu bar item to change sound devices

Friday, August 19th, 2016

I find myself often switching the microphone and speaker devices on my mac. I usually go all the way through System Preferences > Sound, but I stumbled upon a much faster route.

Normally if you click on the volume menu item at the top of the screen you get a little volume slider:

volume menu bar

If you hold OPTION while you click you see a device selection menu:

volume menu bar option click

Split a long mp3 audio file into 3 min files

Wednesday, July 29th, 2015

After some frustration trying to get mp3splt to work, I caved in and wrote a script to split apart a large audio file into many 3min chunks. Save this in mp3split.sh:

#!/bin/bash
big="$1"
duration_stamp=$(ffmpeg -i "$big" 2>&1 | grep Duration | sed 's/^.*Duration: *\([^ ,]*\),.*/\1/g')
title=$(ffmpeg -i "$big" 2>&1  | grep "title *:" | sed 's/^.*title *: *\(.*\)/\1/g')
# get minutes as a raw integer number (rounded up)
prefix=$(basename "$big" .mp3)
echo $duration_stamp
mins=$(echo "$duration_stamp" | sed 's/\([0-9]*\):\([0-9]*\):\([0-9]*\)\.\([0-9]*\)/\1*60+\2+\3\/60+\4\/60\/100/g' | bc -l | python -c "import math; print int(math.ceil(float(raw_input())))")
ss="0"
count="1"
total_count=$(echo "$mins/3+1" | bc)
while [ "$ss" -lt "$mins" ]
do
  zcount=$(printf "%05d" $count)
  ss_hours=$(echo "$ss/60" | bc)
  ss_mins=$(echo "$ss%60" | bc)
  ss_stamp=$(printf "%02d:%02d:00" $ss_hours $ss_mins)
  ffmpeg -i "$big" -acodec copy -t 00:03:00 -ss $ss_stamp -metadata track="$count/$total_count" -metadata title="$title $zcount" "$prefix-$zcount.mp3" 
  ss=$[$ss+3]
  count=$[$count+1]
done

The execute mp3split.sh my-long-file.mp3. This will output a sequence of files:

my-long-file-00001.mp3
my-long-file-00002.mp3
my-long-file-00003.mp3
my-long-file-00004.mp3
...

Each will retain the meta data from the original file except the file number will be appended to the track name and the track number will be set accordingly (i.e. this will work well for splitting enormous audiobook files into file lists that play in the correct sequence on an iphone).

Note: mp3splt really seems like the right tool for this. It supposedly has fancy features like silence detection and presumably won’t reload the file for each new split.

Backup DVD of television show to .mkv files

Sunday, March 3rd, 2013

I bought some DVDs of a german tv show. With my fancy macbook air, I unfortunately have no way to play them: no DVD drive!

So I dusted off my old laptop and installed vobcopy then I copied each dvd first to the old laptop from the disks using:


vobcopy -m

Then I copied these over to my macbook air. But these are just the raw dvd files (VIDEO_TS/*.VOB), which are rather large and unwieldy. To convert these to .mkv files I know to use Handbrake, but since I want to extract each of the 3 or 4 episodes per DVD, setting up Handbrake for each episode turned out to be too tedious. The presets in Handbrake don’t include options to extract all audio channels and all subtitles by default. Instead I found a ruby script call hb.rb which can set up batch jobs.

So finally to extract my episodes with all subtitles and all audio channels in tact I used:

./hb.rb --verbose --input ~/Downloads/IM_ANGESICHT_DES_VERBRECHENS_D2 --output "~/Downloads/#title#_#pos#.mkv" --min-length 00:10:00 --max-length 00:50:00 --skip-duplicates --audio-copy --skip-commentaries --only-first-track-per-language --autocrop

Colours I AM A MAN MAN MAN MAN REMIX ft. Grouplove

Monday, December 24th, 2012


Download high resolution video
Download mp3

Getting Safari to play a short audio clip with HTML5’s audio tag

Friday, August 19th, 2011

I had a really annoying time trying to get Safari to load and play a small audio clip (mp3) I’d posted. The clip is only 2 seconds. Here’s the HTML I was using


<audio src="audio.mp3" autoplay preload="auto" controls loop>

But this resulting in nothing. Upon closer inspection I found out the the “onstalled” even was being fired so I added an “onstalled” even handler to try to load the clip again:


<audio onstalled="this.load();" src="audio.mp3" autoplay preload="auto" controls loop>

But this was to no avail, the “onstalled” event just fired each time recursively.

In the end I gave up on Safari’s ability to play/load small mp3 files. I’m not sure what the problem is since quicktime played the file fine. Also if my html and audio.mp3 files lived locally, Safari played it correctly.

I instead made use of HTML5 ability to specify fallback sources. For this I converted my mp3 file to a m4a:

First convert to wav with mplayer:


mplayer -quiet -vo null -vc dummy -ao pcm:waveheader:file="audio.wav" "audio.mp3"

Then convert to m4a with faac:


faac -o audio.m4a audio.wav

Finally use the .m4a file as a fallback source in the audio tag:


<audio autoplay preload="auto" controls loop>
<source src="audio.mp3" >
<source src="audio.m4a" >
<audio>

Extract mp3 audio from flv flash video

Thursday, May 20th, 2010

Found this resource about using mplayer or ffmpeg to extract the audio of an flv flash movie (like those from youtube etc.) and save it as an mp3 file.

I adapted the ffmpeg version with the -ab flag that allows me to specify audio bitrate:


ffmpeg -i input.flv -f mp3 -ab 192 -vn ouputfile.mp3

Change the 192 to whatever bitrate you want.