Saturday, May 31, 2008

How to convert your video to work on your IPod in one click with linux (Gnome)

This tutorial has been done with Ubuntu 8.04 .
The problem with Ubuntu 8.04 is that ffmpeg doesn't support aac encoding by default. So we will have to compile it with support for aac.

First of all, verify that ffmpeg is not installed on your computer. If it'S installed, please, uninstall it using synaptic.

Now, open a terminal, and execute the following commands:
sudo apt-get build-dep ffmpeg
sudo apt-get install liblame-dev libfaad-dev libfaac-dev libxvidcore4-dev libx264-dev liba52-0.7.4 liba52-0.7.4-dev

sudo apt-get source ffmpeg


Now, go in ffmpeg source folder folder:
cd ffmpeg-0.cvs20070307/

Now, it's time to compile ffmpeg with the following commands:
sudo ./configure --enable-gpl --enable-libogg --enable-liba52 --enable-dc1394 --enable-libgsm --disable-debug --enable-libmp3lame --enable-libfaad --enable-libfaac --enable-xvid --enable-pthreads --enable-x264
sudo make
sudo checkinstall -D make install

If everything went well, now ffmpeg is installed on your computer with support for aac.

To allow you to convert films to mp4 supported by an IPod in a single click, you need to do the following.

First, verify that zenity is installed by running the following command:
sudo apt-get install zenity

Then, run the following command to create and edit the script used to convert vidoes in 4:3:
gedit "~/.gnome2/nautilus-scripts/Ipod Video 4:3"
Then copy the following script in the editor and save the content:
#!/bin/bash

IFS='

';

# List all files
count=0;

for f in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS;
do
count=$(($count+1));
done

pos=0;
for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS;
do
pos=$(($pos+1));
name=${file##*/}
ffmpeg -threads 3 -y -i "$file" -f mp4 -vcodec mpeg4 -maxrate 700000 -b 700000 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 "$file.mp4" 2>&1 | perl -ne '$/="\r";$| = 1;if (/Duration: (\d+):(\d+):(\d+)/) { $max=($1*3600+$2*60+$3) }; if (/time=(\d+)/) { printf "%d\n",($1/$max*100);} print STDERR $_;'| zenity --progress --auto-close --title="$name" --text="File $pos/$count" --percentage=0
done

Since I have a quad core GPU, I use the option -threads 3 to use 3 cores. Change the value to 1 or 2 if you have one or two cores.

Now, close the editor and run the following command to make the file executable:
chmod 700 "~/.gnome2/nautilus-scripts/Ipod Video 4:3"




To create the script which convert fils in 16:9 format, run the following commands:
gedit "~/.gnome2/nautilus-scripts/Ipod Video 16:9"
Then copy the following script in the editor and save the content:
#!/bin/bash

IFS='

';

# List all files
count=0;

for f in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS;
do
count=$(($count+1));
done

pos=0;
for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS;
do
pos=$(($pos+1));
name=${file##*/}
ffmpeg -threads 3 -y -i "$file" -f mp4 -vcodec mpeg4 -maxrate 700000 -b 700000 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x180 -aspect 16:9 "$file.mp4" 2>&1 | perl -ne '$/="\r";$| = 1;if (/Duration: (\d+):(\d+):(\d+)/) { $max=($1*3600+$2*60+$3) }; if (/time=(\d+)/) { printf "%d\n",($1/$max*100);} print STDERR $_;'| zenity --progress --auto-close --title="$name" --text="File $pos/$count" --percentage=0
done


Since I have a quad core GPU, I use the option -threads 3 to use 3 cores. Change the value to 1 or 2 if you have one or two cores.

Now, close the editor and run the following command to make the file executable:
chmod 700 "~/.gnome2/nautilus-scripts/Ipod Video 16:9"



To convert a video, just right click on your video file, then left click, then go to scripts option, and choose one of the two scripts.


The you will see the conversion progress:


You can select several videos at the same time to make a batch conversion.

Now, to put your new video on your Ipod, just use gtkpod.

No comments: