Saving Ustream videos using ngrep in Ubuntu
I came across a wonderful video of a guided meditation by Tenzin Wangyal Rinpoche. He has posted online a large collection of video recordings his teachings and guided meditations. But I wanted to figure out how convert the Ustream video for listen to on my mp3 player later offline. It also means the meditation won’t be frequently interrupted by the advertisements.
But first I needed to figure out how to download it! It turns out it’s easy to do using the terminal in Ubuntu. It’s like a super jackknife that can do pretty much anything. People recommended using a URL sniffer to discover the flash video file for downloading. In Ubuntu this is very easy to do using ngrep. Here’s how:
Step 1 : open up your terminal and install it if you haven’t already:
$ sudo apt-get install ngrep
Step 2: activate the ngrep command:
$ sudo ngrep -d any '.flv' port 80
Step 3: reload/refresh the Ustream video page and then look at the ngrep output. Look through it carefully and you’ll see a section like this:
HTTP/1.1 200 OK..Date: Sat, 27 Apr 2013 56:11 GMT..Server: Apache..X-RSR C: sjc-web048..Content-Length: 112..Keep-Alive: timeout=15, max=200..Connection: Keep-Alive..Content-Type: text/html....http://vodp13.ustream.tv/0/1/1/1419/1419528/1_354487_1419528.flv ############################
There’s the video link you can download using wget or pasting in your browser!
Step 4: converting the flash video to mp3 audio:
$ ffmpeg -i 1_354487_1419528.flv -ar 22050 -ab 64k -ac 1 trancending-fear.mp3
This conversion took a few minutes. It greatly reduced the file size from 140mb to 40mb. Now I can listen to it on my mini mp3 player (Sansa Clip+) whenever I like!