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();
}
}
}