Image 01 Image 02

Mobile video for free

Posted on 3rd August 2008 by Sebastian
0

So you have a new fancy cellphone and it has the ability to play back video clips?

Well, here I will teach you how to easily convert your existing videos into ones that’re compact enough to carry around in your pocket — for free!

You have most likely done what I did in the beginning; searched Google for a way to do it and found a bunch of dubious looking applications that may or may not be able to do it, and if they are able, most likely for a small fee.

Well, this solution I have here should work on Windows, Mac, your favorite Linux distribution and more than likely tonnes of other places.

Prerequisites

You’ll need to download a few utilities in order to get this conversion method working.

  • Perl interpreter
    I chose to use Perl due to how hackish the script started to feel when I tried to write it as a Windows batch script.
    Download
  • ffmpeg
    The be all and end all commandline video conversion tool.
    Download: WindowsMacLinux

The Script

You have two options here:

  • Right click here, save as MobileVideo.pl
  • Open the text editor of your choice, paste the following code:
    #!/usr/bin/perl -w
    
    # Script by Sebastian Paaske Tørholm ( mathemaniac.org )
    
    opendir(DIR, ".");
    
    foreach my $file (grep(/.(flv|mpe?g|avi|wmv|mov)$/,readdir(DIR))) {
    	my $output = $file;
    	$output =~ s/.[^.]*$/.mp4/;
    	system("ffmpeg -i \"$file\" -s qcif -ar 48000 \"$output\"");
    	my $rm = ($^O eq "MSWin32") ? 'del' : 'rm';
    		system("$rm \"$file\"");
    }
    
    closedir(DIR);

    and save the file as “MobileVideo.pl”.

Usage

The script usage is very simple, you just copy the files you want converted into the script folder, run the script and it proceeds to convert the files.

Note: It deletes the original files once they’ve been converted! If you do not want this, comment out the last two lines of the foreach.

Final notes

Some cellphones don’t play MP4 files. If yours doesn’t, simply change the line that says

$output =~ s/.[^.]*$/.mp4/;

to

$output =~ s/.[^.]*$/.3gp/;

and you should be able to use the videos.



Leave a reply...