Sunday, December 17, 2006

Put Youtube video to ipod using ffmpeg

Put Any YouTube Video On Your iPod is a good source for expanding the video library on the wonderful video iPod. A Beginner's Guide to Video for the IPod also introduced a number of commercial or free programs that can convert videos for the iPod.

However, I have developed a fondness for ffmpeg through my previous effort of making movies from still images. In addition, I found out that a lot of the existing video authoring programs are actually derivatives of ffmpeg. With a little googling around, I found this page - Converting video to play on your iPod with FFmpeg. After messing around different options, I finally settle with this command line:

I download flash videos using firefox videodownloader extension. All the downloaded video dimensions are 320x240, so no more fiddling is needed. It seems that people often misinterpret the -maxrate option. The correct meaning of it is maximum bitrate tolerance, so the output bitrate is usually dictated by the input bitrate since we don't want too much deviation.

If you are a fetish Java user, try this code to pool all the videos into a folder and convert them all at onece


import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
/**
* Convert the flv video files into ipod video files using ffmpeg.
* Usage:
* java itube [source_path] [prefix] [number_of_files]
*
* @author yctan
*
*/
public class itube {
public static class AlphabeticComparator implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
return s1.toLowerCase().compareTo(s2.toLowerCase());
}
}
public static void main(String[] args) {
File path;
String[] list;
if(args.length == 0)
path = new File(".");
else
path = new File(args[0]);
list = path.list();
if(list == null) {
System.err.println("File not found.");
System.exit(1);
}
Arrays.sort(list, new AlphabeticComparator());

String prefix = null;
if(args.length > 1) prefix = args[1];

int nfiles = list.length;
if(args.length == 3)
nfiles = Integer.parseInt(args[2]);

try {
PrintWriter logfile = new PrintWriter(new BufferedWriter(new FileWriter("itube.log")));
for(int i = 0; i < nfiles; i++) {
int dot = list[i].lastIndexOf('.');
if(dot==-1 || !list[i].substring(dot+1,list[i].length()).equals("flv")) continue;
String cmd = "ffmpeg -i " + path.getPath() + '/' + list[i];
cmd += " -f mp4 -maxrate 1000 -b 300 -qmin 3 -qmax 5";
cmd += " -bufsize 4096 -g 300 -vcodec mpeg4 -acodec aac ";
if(prefix!=null) cmd += prefix + '-';
cmd += list[i].substring(0, list[i].lastIndexOf('.'));
cmd += ".mp4";
// System.out.println(cmd);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
logfile.println("Converting " + list[i] + " ... ");
while((line = br.readLine()) != null)
logfile.println(line);
logfile.println("Done.");
int exitVal = proc.waitFor();
logfile.println("Process exitValue: " + exitVal);
}
logfile.close();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

Wednesday, December 06, 2006

Convert RMVB to iPod Video

As I started my quest to put RMVB videos to my newly acquired video ipod, I realized that ffmpeg simply does not have the codecs to decode this RMVB format. I kept googling the potential candidates but most of the solutions I found are non-free/commercial software. Finally, I took a chance with mencoder and had some success. It's not a smooth sail using mencoder. I tried it first on my 64 bit AMD linux machine, and none of the realvideo codecs worked. Therefore, I have to do it on my windows machine :-( Followings are the steps to successfully converting the RMVB:
  1. Download MPlayer 1.0rc1 Windows and grab "windows-all-20061022.zip" from codecs directory.
  2. Unzip both of them into the same directory. Let's say, C:\mplayer.
  3. Assume you want to convert "Cars.rmvb" and it is in "C:\Documents and Settings\All Users\Documents\". Open Notepad to type the following textbox as a single line and save the file as "encode.bat".
  4. Double click "encode.bat" to execute it. "Cars.mp4" will be created. Use iTune or gtkpod (on your linux machine) to transfer the mp4 into ipod :-)

"encode.bat"

The first thing we should keep in mind is the video ipod limitation. From ipod specs, we can immediately learn that the allowed video formats are H.264 and MPEG-4, and the allowed audio codec is AAC. For MPEG-4, the pixel limit is 640x480 and the max. frame rate is 30 fps. As a result, "vcodec=mpeg4" and "acodec=aac" are used.

Of course, we also need to understand the command line of mencoder to successfully convert every given RMVB file. The listed command line in "encode.bat" is very similar to Encoding to Sony PSP video format from the mencoder documentation. We'd better have this documentation ready to explain every parameter that can be used.

Another crucial element is understanding the video source - video bit rate, fps, and aspect ratio. Read video info using either Real Player or Real Alternative. For example, the source Cars.rmvb has these properties

  • Avg Stream Bit Rate: 996.9 Kbps
  • Dimensions: 800x452
  • Encoded Frame Rate: 24.0 fps
Therefore, I use
  • vbitrate=800 to sacrifice a little bit quality to control the output file size, I certainly don't think there is any benefit to use bit rate larger than 996.9 Kbps.
  • -ofps 24.0 to match the output frame rate. Otherwise, mencoder will keep complaining skipped frames.
  • -vf scale=640:362 to keep the correct aspect ratio and shrink the pixel size (remember the ipod limitation).

Monday, December 04, 2006

Black Forest Delight


How-to: Bake devil's food cake mix. Dissolve cherry gelatin and pour into cake layers. Mix sour cream and powdered sugar and stir in whip cream. Spread whipped topping mixture and cherries on the first cake layer. Place second cake layer on the first cake layer. Frost with remaining whipped topping mixture. Drizzle chocolate on the top. Garnish with cherries. Yummy.

Monday, June 26, 2006

Saturday, December 31, 2005

Make Mouse Scroll Wheel Work


I just made my PS/2 mouse scroll wheel work again in SUSE Linux 10.0. Who would have thought the correct protocol name should be imps/2? The protocol change does not take effect until the system is restarted, so the testing immediately after the switch is meaningless. Despite all the wonderful features in the latest SUSE Linux version, there are still some quirks I have picked up so far.
  1. My 16X DVD-ROM drive is treated as a CD-ROM drive such that no DVD can be read. I need to painfully do a switcheroo with a Plextor DVD drive during the initial system setup.
  2. By switching the USB and PS/2 mice after the initial system setup, I lost the correct setup for the PS/2 mouse. Hence I endured the annoyance of the loss of scroll wheel function until I figured out what protocol I need to choose.
  3. A sudden loss of OpenGL function due to some incompatible system packages (although I never figured out the real cause). The solution is to re-install the Nvidia video driver.
  4. Eclipse (3.1 and 3.2) will somehow become unstable and finally cannot start on the 64 bit JVM provided by SUSE, but it manages to work under the latest JVM 1.5.0 update 6 directly from Sun.

Monday, November 28, 2005

Give Me a Break

There are a number of things are newsworthy.

Michael Scofield and his team are going to break out of Fox River State Penitentiary tonight :-)

On November 18, my new computer ceased to work after being assembled merely three weeks earlier. Without understanding the true cause of the breakdown, I placed the blame on the mother board - Epox 9NDA3J nForce3. I regretted the premature disposal of the packaging boxes because by doing so I cannot refund the defected items from NewEgg.com. Desperately I bought another mother board - Gigabyte Uli 1689 from NewEgg, and it should arrive today. The temperature rises to a near-term peak today. And I will be assembling my new computer tonight ...

My last blog - trip to Yellowstone - is heavily spammed in addition to my mailbox. I don't exactly know how the spammers benefit from commenting my blog entry and placing a link back to their web sites. Are they trying to raise the Google ranking of their own web sites?

XBox 360 started selling on November 22, which is right before the Thanksgiving shopping craze. But rumor has it - PS3 will be sold with Linux pre-installed. Very sweet. With all the hype on HD gaming, yesterday I installed, DOSBox, a MS-DOS emulation program such that my Mom can play Lode Runner, a pre-historic yet extremely fun game. And that's what a brilliant video game should have, an innovative gameplay instead of only pretty high resolution.

Saturday, August 06, 2005

Yellowstone trip


Long time no blog until I found out my wife posted an excellent blog about our Yellowstone trip. I am just too lazy writing up a long and exhaustive memento. It was a pretty nice trip in the hot summer of 2005.

Thursday, June 09, 2005

Poa Annua

Poa Annua
These things popped up in my lawn since about two weeks ago. Their appearances really get on my nerves, and it will be tough to wage a war against them. I contacted Scotts Lawn Service to have a free lawn analysis. Hopefully they can suggest something useful but not too costly.

Based on what I have read so far, I guess I made mistakes in not doing some prevention work in early spring and then mowing the lawn too short. I will try to stop mowing my lawn for a while and apply Ortho Grass-B-Gon Garden Grass Killer. I will also consider mowing with bagger to collect the seeds of them.

$%@x#!, I really hate my lawn!

Friday, May 27, 2005

BigKid : Xbox 360 vs PS3

BigKid : Xbox 360 vs PS3 puts up a nice comparison table. Someone throws in a NINTENDO Revolution picture, too. I blogged this with Mozilla on HP-UX aftering installing a google toolbar to it. This toolbar thing first works on IE, then there is a Firefox version, and now it can fit backward to Mozilla. Job nicely done! These developers make me like open-source mechanism even more every day!

Monday, May 23, 2005

Dantzig's obituary

Long time no blog. Lately the biggest tech news are probably the reveals of xbox 360 and PS3. I have wanted to write about the specs of the hardware. But it turned out it would take too much time digesting all the stuff around the Net, so the idea has not been realized so far. Today I learned from Slashdot that George Dantzig passed away and somehow I felt sad. I have this emotional attachment because lately I spent so much time implementing the Dantzig alogorithm to solve the Linear Complimentary Problem that results from solving the contact constraints in multibody dynamics. RIP, Dantzig. Here is the post from Slashdot:

Posted by timothy on Sunday May 22, @10:00PM
from the life-well-lived dept.
Markus Registrada writes "George Dantzig, the inventor of the Simplex method for solving Linear Programming problems, died on May 13. He was also the now-legendary student who turned in solutions for what he had taken to be a homework assignment, only to find out they had been posted as examples of what were suspected to be unsolvable problems."

Friday, April 08, 2005

Plextor 716A DVD burner

With the failed CDs keep piling up, finally I am fed up with the degrading performance of both of my CD burners. File archiving becomes ever more important to me with my routine BitTorrent downloads. I decided to pursue a DVD burner. At the beginning, I was surprised to find out that a 16x Sony DWD22A only cost in the low 50s. As I read more user opinion on the web, I concluded Plextor 716A would be the best in the current market and I got an OEM version from newegg.com. I'd like to pay attention to the details this time to avoid piling up failed DVDs, so I spent time reading the manual and found out my 40 conductor IDE cables have been outdated. Then I went on to replace them with 80 conductor IDE cables for both my hard drive and the new acquired DVD drive. I also got a bundle of 25 8x TDK DVD-R from BestBuy for only $9.99 (basically no matter which brand you choose they are all made in Taiwan). Last night I finally used Nero to fire up this baby. The DVD-R was burned quietly at 8x without any problem. I am looking forward to breaking speed record if I have faster disks. This drive can burn CD-R at 48x. I have never achieved 16x with my previous HP CD burner although it is advertised at 16x.

Friday, April 01, 2005

Google Maps

I searched computer hardware stores in my home town area and found Google Map and Driving Direction quite impressive. I also spent a little time checking out Yahoo Map and MapQuest. Compared to the other two offerings, Google Map provides the largest map viewing area and keeps the rest of page very clean as opposed to getting cluttered with ads. Google Map also interacts very well with the users by showing neat popups when the turn of driving direction is clicked. Panning around the map is very smooth by dragging it with the mouse. At the right bottom corner, it states that the data is from NAVTEQ, which is also used by the other two map offerings. So everyone uses the same source, it is just a matter of coming up with the best user interface and Google does it brilliantly.

Thursday, March 31, 2005

Matrix Toolkits for Java

I have been using Colt for a while, and thought it is pretty good. Today I just came across another numerical library that could be the best I have ever seen - MTJ. Native interface to BLAS and LAPACK, sparse matrix solvers, and distributed matrix computation are all packed in one library?! Are you kidding me?! For those who stick with C++, I found MTL. For C# users, I found Math.Net. But they certainly cannot compete with MTJ in terms of the features mentioned above. Java people are just extremely blessed!

Friday, March 18, 2005

Frequently Unanswered Questions

I thought the title of this posting is neat. After reading a post from Slashdot, I collected the links here so I can ponder upon in the future. No, I am not interested in how placebo works. I am not blessed with the mathematical talents to solve the millenium problems, either. The things that always fascinate me are the cosmology and astrophysics stuff - strange gravity pull and speed of light that make Einstein famous. Moreover, I do find the sonoluminescence phenomonum very interesting and I may have some reflection on Navier-Stokes Equation. Without further ado, here are the links

Monday, March 07, 2005

I just increased my swap space with a swap file


/sbin/swapon -s

Filename Type Size Used Priority
/dev/hda5 partition 1044184 0 -1


df -m

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/hda7 372 81 272 23% /
/dev/hda2 46 10 34 22% /boot
/dev/hda6 9705 2325 6887 26% /home
none 251 0 250 0% /dev/shm
/dev/hda3 26537 2113 23076 9% /usr
/dev/hda8 251 64 173 27% /var

su

dd if=/dev/zero of=/usr/extraswap bs=1M count=1024

/sbin/mkswap /usr/extraswap
Setting up swapspace version 1, size = 1048572 KiB

/sbin/swapon /usr/extraswap

/sbin/swapon -s

Filename Type Size Used Priority
/dev/hda5 partition 1044184 0 -1
/usr/extraswap file 1048568 0 -2

cp /etc/fstab /etc/fstab.mybackup

emacs /etc/fstab&

diff /etc/fstab /etc/fstab.mybackup
10d9
< /usr/extraswap none swap sw 0 0

Saturday, March 05, 2005

Eclipse

I found Borland JBuilder become quite sluggish as I move on to the version of JBuilder 2005. Since I have been reading high praise on Eclipse for some time, I finally decided to give it a try. After I loaded the download page of www.eclipse.org, somehow it smartly detected I was using HP-UX and let me download the HP-UX version of Eclipse Platform SDK 3.0. This version just launched without any problem as it detected the path of installed HP Java VM. At this point, I was very impressed since nothing worked in HP-UX so naturally before. This is a whole new experience!!

The interface is of motif theme that seems outdated, but, again, it is a HP-UX version. I will need a windows version for a fair comparison. The perspective, in my opinion, is a pretty good idea. It let you switch around different arrangements of the panels for each specific task. Switching over from JBuilder is not easy since it also has many merits and I am very accustomed to it. I will explore other notable features of Eclipse after I have accumulated more play time.

Friday, March 04, 2005

The Dow Jones Expensive Merlot Index

Movie "Sideways" slaps Merlot but here is the rebuttal.

By DOROTHY J. GAITER AND JOHN BRECHER

In a broad tasting of American Merlots that cost $20 to $50, mostly from the 2001 vintage, these were our favorites. While most inexpensive Merlots are meant to be drunk immediately, many better Merlots, including these, will age beautifully for some years. These pair well with steak and similarly serious foods.

Vineyard/Vintage Price Rating Tasters' Comments
Duckhorn Vineyards 2002 (Napa Valley) $49.99 Delicious Best of tasting. Intense, dark and rich, with herbs, earth and cedar -- all in a package that's so sensual it's like blackberry chocolate fondue. Very young.
Sarah's Vineyard 'Besson Vineyard' 2001 (Santa Clara Valley) $20.00 Very Good Best value. Lighter than some, with more obvious fruit flavors. It tastes like great grapes, left alone to taste good -- fruity yet not at all sweet. Very pleasant.
Steltzner Vineyards 2001 (Stags Leap District, Napa Valley) $24.98 Very Good/Delicious A deep, complex wine, with a sense of place and plenty of layers. Slightly herbal and nicely tight, with such great acids it demands a big meal.
Corte Riva Vineyards 2002 (Napa Valley) $44.99 Very Good Hefty, with great body and structure, some herbs and plenty of earth. Blackberries and cream. A real mouthful of wine.
Groth Vineyards & Winery 2001 (Napa Valley) $34.99* Very Good Elegant, with Bordeaux-like structure and a long, dry finish. Could age for a long time.
Joseph Phelps Vineyards 2001 (Napa Valley) $38.99 Very Good Smells like chocolate, blackberries and rich soil, with some nice hints of herbs, too. Tight and nicely earthy.
Larkmead Vineyards 2001 (Napa Valley) $36.00* Very Good Very serious wine, with hints of black tea and soil. Have it with roast meat.
Matanzas Creek Winery 2001 (Sonoma County) $29.95 Very Good It looks and even tastes dark, with hints of tobacco and coffee and a kind of leathery toughness. Classy wine.
Provenance Vineyards 2001 (Carneros, Napa Valley) $26.95 Very Good Grapey and pleasant, with some spice and cream, a dark core and nicely dry finish.
Rombauer Vineyards 2001 (Napa Valley) $25.95 Very Good Very pleasant, plum-like fruit and terrific acids for food. Quite complete. More forward and easier to drink than some.

NOTE: Wines are rated on a scale that ranges: Yech, OK, Good, Very Good, Delicious, and Delicious! These came from California, Florida and New York. *We paid $36.95 for the Groth and $29.97 for the Larkmead, but these prices appear to be more representative. Prices vary widely.

Thursday, March 03, 2005

4 8 15 16 23 42

Again I am LOST!

Episode 18 - Numbers

4 8 15 16 23 42

I am tired of guessing. The facts that interest me are

Episode 19 - Deus Ex Machina (Latin for "God from the machine"). This episode will center on Locke (BTW, John Locke is the name of a English philosopher). The title is so tantilizing that ABC is going to make us wait for a LONG LONG time (April 13 according to TV Tome). Some quick notes are:
  • Deus Ex Machina refers to an implausible ending where everything is solved and justice is served.
  • The episode title is also similar to the title of Chapter 48 of Watership Down "Dea ex Machina." (Watership Down is the book that Sawyer was reading that came from Boone's suitcase).

Facts provided by TV Tome

Sunday, February 20, 2005

A small form factor PC

VIA has been producing a series of Mini-ITX motherboards for some time. Recently it introduced a so-called Nano-ITX board with the size of 12 x 12 cm. There are plenty of PC modders using Mini-ITX boards to build many weird-looking PCs, which can be seen from mini-itx.com. But what really raises my interests in Nano-ITX is the JDOS project. The project promises an embedded system running Linux and Java. I have been dreaming about using the cellphone systems running J2ME as the microcontrollers for robots. What advantages does the JDOS solution have over J2ME? The other thing that baffles me is about the real-time operation in Linux. Some people claimed that Windows CE naturally supports real time operations but Linux does not. Does J2ME have real time capability? And why are there so many questions in life without answers?

Count Linux Distros

It seems nowadays a great number of geeks could take the Linux kernel and bundle it with different flavors of software and make their own distros. What distro should I grab to fit my next PC project?

  • Xandros - Do printer/file sharing just like Windows. It is used by Extremetech to build a home server. Great for beginners. Bundled with Walmart PC.
  • Gentoo - Features Portage (based on FreeBSD's Ports tool) that lets administrators acquire and update software by downloading source code and compiling applications to suit their particular system.
  • Fedora - Fedora Core 3 has a better plug-and-play and wireless networking support.
  • Mandrake
  • SuSe
  • Debian - Very hardcore!
  • Ubuntu - A derivative of Debian.
  • uClinux - For embedded systems.

The caveat of installing Linux is of course making sure that all the hardware in the PC system can be properly supported. Many hardware by default only ship with Windows drivers and there is just no way to get around. Try to put Linux on laptop is proved to be no small task.

Skiing at Winter Park