Java: Converting Time from one format to another

I’ve started using Checkstyle on my code base. One of the checks I’ve enabled is magicnumbers, which as its name implies, ensures your code isn’t using magic numbers.

As a result, I found some code that was doing the following:

How many times have you done that? Or wanted to convert milliseconds to minutes or various others? Created a constant with 60*60*24 for conversions?

Doing a bit of Googling, I learned that in Java 6, as part of the Concurrency updates, the JDK now has a TimeUnit class. This then allows one to do the following instead:

That’s much cleaner, and less prone to both misunderstanding and errors.

  • Checkstyle:[elink link=””]
  • TimeUnit: [elink link=””]

Taking a movie for your CD equipped notebook

I’m going to Florida in January with my daughter, and am trying to plan ahead so she doesn’t get bored. I don’t have a notebook with a DVD player in it, or a portable DVD player, so I thought about converting some of our DVDs to SVCD. This format can be burned to a CD, and played back on a computer with the right software (and a number of DVD players will play it too. Did some searching and found this very useful web page. Provides guides to convert movies into VCD, SVCD and DIVx format. Decided against DIVx as it requires a lot of computing power to play, which my notebook doesn’t have, and which also will kill the battery very fast.

DVD Ripping Guides by KalEl

Just worked my way through it and it went fine.

The SmartRipper installer dialog is in German, but the program dialogs are in English. Just change the directory to where you want SmartRipper put, and push the right most button to extract. It doesn’t have an installer per se, so whatever directory you put it in is where it will be run from.

SmartRipper took about 15 minutes to rip a 1:40 movie. Not bad time.

DVD2AVI again isn’t intuitive (Thank goodness for this guide), but it worked quickly. About 5 minutes to create its index. The one thing I forgot to do the first time was set Audio to Encode to Wav format.

For TMPEng, some of the interface has changed since the guide was written. No show stoppers, as the functions are the same, just some of the text has changed. I did run into a problem taking a widescreen movie and outputting it to SVCD. The result ended up being a full screen movie, and I couldn’t quite tell if it was stretched or cropped.

To overcome this, I modified the settings on the Advanced tab so that the Video Arrange Method was Center (Custom Size) and set the size to 480×320. This seemed to fix it up so the movie filled the output width and was the correct height (or at least close enough).

This portion takes a looong time to do, even on a quick machine! It took almost 5 hours (I took the 2-pass VBR option) for this movie.

For my purposes, I didn’t burn it to CD. I just copied it from the harddrive of my machine to the notebook (via my local LAN). Much easier to carry the notebook than to have 3 CDs per movie, and the notebook had enough space on the HD for this (although 30GB doesn’t go very far anymore)

EAC – Exact Audio Copy

An excellent program for ripping music from your CDs. EAC – Exact Audio Copy (EAC)

Having purchased an iPod, I want my music available on the go. I needed a program that pulls the information from the CD accurately, and lets me know if it has a problem doing it. I’ve used programs like MusicMatch before, and they do a reasonable job, but they occasionally produce glitches in the output. Thus far, EAC has not produced an MP3 with any problems.

One downside is it doesn’t contain a built-in MP3 encoder. It does contain a good tie-in with one of the better MP3 encoders, namely LAME. It is an Open Source encoder and it’s main page is at sourceforge. The site I have linked to is providing a compiled binary download (i.e. an executable that anyone can use). The official project only provides source code.

To install EAC, first install LAME (unzip the download to a LAME directory). Then install EAC, and EAC will search for a LAME install.

EAC isn’t the most intuitive program to use, but it is very powerful and works very well. It has even been able to read ‘copy protected’ CDs that I have so I was able to get the songs into MP3, and also make a copy for use in the car (I never use originals in the car. Too susceptible to damage or theft).