Saturday, January 12, 2013

Python Script to Convert MP4 Video to MP3 Audio

Earlier today, at around midday, I was going to do some exercise, but since I don't like to use my rowing erg without something to listen to, I thought I'd listen to some TED Talks via iPod Touch to Bluetooth headset. Unfortunately, I couldn't get the damned headphones to connect to my laptop, iPod or Nexus 7, though they were detected by all. The Nexus connected, but the playback cut out every few seconds, the iPod connected, but didn't work after that, and my laptop was only able to find my Nexus 7 and not the headphones.

This was really annoying as the headphones used to work fine with my iPod. I don't know what happened, but I expect that the headphones just decided to stop working today for the hell of it, despite them being fine just recently.

So I decided to go old skool and use my ancient iPod Nano instead. Unfortunately, due to my own inability to calmly handle minor problems, the fact I couldn't quickly filter downloaded Podcasts in Banshee from those I had yet to download, made me so angry I started to look for other solutions. That I had downloaded video podcasts in the belief that they were audio only podcasts just made me angrier and I started to find other ways to get audio only TED Talks.

In the end, I got so pissed off that I spent hours writing a Python script to convert the video podcasts into mp3 audio. It took so long partly because I am stupid, but also partly because I spent a lot of that time learning new things in Python and digging through the magnificent Stack Overflow for help.

Here is the script for anyone it might help. Note that you need to have mplayer, lame and python 2.x installed for this script to work.
sudo apt-get install mplayer
sudo apt-get install lame
sudo apt-get install python2.7
Then simply run
python mp4tomp3.py [input_directory [output_directory]]
This will convert all mp4 files in the input directory into an mp3 file in the output directory, ignoring any files that have been previously converted. The input and output directories are optional; Input will default to the current directory and output will default to the same as input.

So now I have a folder full of mp3 audio only TED Talk podcasts. I still don't know how I'm going to get them on my iPod though. There must be something similar to Sharepod available for Linux. I guess finding that is my next task.

I'm never going to buy another fucking iDevice again.

Update: Once I'd converted the videos to mp3s, I imported them into Banshee and from there it was quite trivial to get them onto my iPod. I think the main problem I had was that there was no filter for downloaded files. Also, I discovered that my 3rd generation Nano can play mp4 videos, so I just wasted half a day fucking around wisely spent half a day learning new things.

3 comments:

  1. Thanks a bunch for this!
    More than the script's utility, this is a great example of what Python can do.

    ReplyDelete
  2. cara baru convert video ke mp3
    terima kasih banyak infonya

    ReplyDelete
  3. I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. video to mp3 converter

    ReplyDelete