Monday, March 16, 2009

Encode video files for ipod-touch/iphone and T-Mobile G1/Andriod [Linux Hacks]

I posted an article back in February on how to re-encode movies for ipod and other pmp devices in linux, based on my mini_encoder.py script. I have a few more updates now to add to the script for your enjoyment. Release notes as follows:

-Now uses optparse python module for command line argument process handling
-New option for iphone/ipod-touch in addition to ipod-video and default modes
-Uses ffmpeg for processing ipod/iphone videos (H.264 and AAC codecs encoded to mp4 format)
-General code cleanup and slight re-factoring
-More verbose help options

The main takeaway from this version is that mini_encoder.py is now capable of resizing mpg or avi video files for your ipod-video, iphone/ipod-touch or even your T-Mobile G1/Android, in addition to any other pmp player that is capable of handling avi or mpg video streams.

The default resolution is 320x240, but for the iphone/ipod-touch and G1, it bumps it up to 480x320 to fit nicely on the screen and utilize the larger screen size. See the help option for more info


$ ./mini-encoder.py --help
./mini-encoder.py - Encodes and resizes video files (avi or mpg) to fit
small screen resolution pmp devices. Resolution and codec formulas:

default - 320x240 (preserves original codecs from source video file)
ipod - 320x240 (re-encodes to mp4 using H.264 and AAC codecs)
iphone - 480x320 (re-encodes to mp4 using H.264 and AAC codecs)

Supply a path to the movie file you wish to encode (required):
./mini-encoder.py [options] --movie /path/to/file.avi
Options:
--version Print the version number of this program
-m, --movie Path to video file you wish to encode
-p, --ipod Encodes to mp4 format for use with ipod-video
-i, --iphone Encodes to mp4 format for use with iphone/ipod-touch

Usage: mini-encoder.py [options]

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-m INMOVIE, --movie=INMOVIE
Input video file to encode
-p, --ipod Encode to ipod-video format
-i, --iphone Encode to iphone/ipod-touch format

Example for encoding for iphone/ipod-touch:
./mini_encoder.py --iphone --movie /path/to/movie.avi


Requirements for running this program are:
1. A recent version of python
2. transcode package
3. ffmpeg package

Please feel free to download it and let me know what you think.

Sunday, March 8, 2009

Convert wav to mp3 for a directory [Linux Hacks]

There are some really nice Linux tools out there to do wav to mp3 conversion (lame, bladeenc etc). Here is a small shell script to run on a given directory that will convert all .wav files to .mp3:

wav2mp3.sh

Output:


$ ./wav2mp3.sh /home/nmaxwell/foo/
/usr/bin/bladeenc
Performing mp3 conversion on: /home/nmaxwell/foo/
Old filename: /home/nmaxwell/foo/song.wav
New filename: /home/nmaxwell/foo/song.mp3

BladeEnc 0.94.2 (c) Tord Jansson Homepage: http://bladeenc.mp3.no
===============================================================================
BladeEnc is free software, distributed under the Lesser General Public License.
See the file COPYING, BladeEnc's homepage or www.fsf.org for more details.

Files to encode: 1

Encoding: /home/nmaxwell/foo/song.wav
Input: 44.1 kHz, 16 bit, stereo.
Output: 128 kBit, stereo.

Completed. Encoding time: 00:00:07 (21.71X)

All operations completed. Total encoding time: 00:00:07


The script will run this conversion on any files it sees in the directory with the .wav extension.