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

7 comments:

Anonymous said...

excellent program man! useful to me alot. Thanks

Hay said...

Thanks! This worked for me when converting a FLV video from YouTube using the ffmpeg binary from the 0.0.9y release of ffmpegX for Mac OS X Leopard. Just one thing: apparently the '-buffersize' option has been renamed to '-bufsize' sometime, so you need to use that. Then it works perfectly!

Anonymous said...

Hi there,

What you could also do is go to
http://www.dintillion.com/scripts/convert_to_ipod.html

, download the .zip file, copy the bat file and ffmpeg to the directory you want to convert, and just double-click the bat. It will run through your entire folder, re-encoding them all to ipod ready format in one go. Enjoy!

Anonymous said...

instead of aac, use the option libfaac

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

ipod video said...

I still can't believe how you think of that kind of amazing program. It is so amazing. The code are so easy to follow. I am sure that lot of people will love this program.

cialis said...

In principle, a good happen, support the views of the author

Skiing at Winter Park