more fun with ffmpeg
2011-07-16
To follow up on two previous posts, the Buckethead concert and making your own YouTube bootlegs, I’m going to add just a little more.
As I mentioned, the concert was great. If I were to pick out one part, it would have been this lengthy untitled (as far as I know) freestyle jam he did with a simple looping beat.
I cannot think of anything worse than falling in love with a song at a concert, and not knowing the name of it.
Thankfully, a lot of people have recorded the entire show. So Friday at work, while I was beating my head against MediaWiki’s new installer (that silently fails to populate the database with stock data because they tried to import a poorly escaped text blob… sheesh), I played the entire concert in the background. When my ears finally picked up the wonderful peice I heard at our SF show, I took note of the time.
The song starts around the 29 minute mark, and its nearly 8 minutes and 40 seconds long.
Once again, the first thing is to extract the audio from YouTube with youtube-dl:
[server]-[mcarlson] 11:55am: /SafeKeg/Music/Buckethead>youtube-dl --extract-audio --audio-format="aac" 'http://www.youtube.com/watch?v=l_bApGe0a0U'
[youtube] Setting language
[youtube] l_bApGe0a0U: Downloading video webpage
[youtube] l_bApGe0a0U: Downloading video info webpage
[youtube] l_bApGe0a0U: Extracting video information
[download] Destination: l_bApGe0a0U.mp4
[download] 100.0% of 519.25M at 1.51M/s ETA 00:00
[ffmpeg] Destination: l_bApGe0a0U.aac
Time spent in user mode (CPU seconds) : 5.831s
Time spent in kernel mode (CPU seconds) : 9.170s
Total time : 5:49.83s
CPU utilisation (percentage) : 4.2%
Now I have a nice aac file to work with. That clip is almost 50 minutes long though, and I just want one song.
FFMPEG TO THE RESCUE!!
ffmpeg is an exceptional tool, and how it ties into a LOT of other codecs and filters make it really useful. You can even cut up an audio file, like I did here.
The command,
ffmpeg -i l_bApGe0a0U.aac -ss 00:29:01 -t 00:08:41 -ab 128000 -ar 44100 sweet-new-song.mp3
specifies the following:
-
-i l_bApGeoaoU.aac : This is the input file, out audio that youtube-dl extracted for us
-
-ss 00:29:01 : Seek to 29 minutes a 1 second
-
-t 00:08:41 : The total “time”, or duration, of this file will be 8 minutes and 41 seconds
-
-ab 128000 : The bitrate to use
-
-ar 44100 : Sets the audio sampling rate to 44.1K hz
-
sweet-new-song.mp3 is the final output name
[server]-[mcarlson] 10:03pm: /SafeKeg/Music/Buckethead>ffmpeg -i l_bApGe0a0U.aac -ss 00:29:01 -t 00:08:41 -ab 128000 -ar 44100 sweet-new-song.mp3
FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
built on Apr 2 2011 08:09:07 with gcc 4.2.1 20070719 [FreeBSD]
[aac @ 0x803c22010]max_analyze_duration reached
[aac @ 0x803c22010]Estimating duration from bitrate, this may be inaccurate
Input #0, aac, from 'l_bApGe0a0U.aac':
Duration: 00:53:04.07, bitrate: 126 kb/s
Stream #0.0: Audio: aac, 44100 Hz, stereo, s16, 126 kb/s
Output #0, mp3, to 'sweet-new-song.mp3':
Metadata:
TSSE : Lavf52.64.2
Stream #0.0: Audio: libmp3lame, 44100 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
size= 8144kB time=521.22 bitrate= 128.0kbits/s ts/s
video:0kB audio:8144kB global headers:0kB muxing overhead 0.000396%
Time spent in user mode (CPU seconds) : 27.280s
Time spent in kernel mode (CPU seconds) : 0.340s
Total time : 0:27.74s
CPU utilisation (percentage) : 99.5%
And if anyone wants to listen to the final product, here you go: sweet-new-song
The whole thing is a work of art, and to me, the second half (around 4:30) is the absolute best. So beautiful.