Linux Gp2x Video Conversion Script


Megatog615

Member
Joined
Dec 25, 2006
Messages
163
CODE
#!/bin/bash
# Copyright (C) 2007 Evan Goers
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Input/Output Files(Do not change):
INPUTFILE="$1"
OUTPUTFILE="$(echo $INPUTFILE | sed 's_^.*/(.*)\.[^.]*$_\1_')"
OUTPUTDIR="$2"

# Current pass(this is the starting number; do not edit):
PASS="1"

function convert {
nice \
ffmpeg -i $INPUTFILE \
-pass $PASS \
-vcodec mpeg4 \
-vtag DIVX \
-s 320x240 \
-r 29.97 \
-aspect 4:3 \
-acodec mp2 \
-ar 44100 \
-ab 192k \
$OUTPUTDIR/$OUTPUTFILE.gp2x.avi
}

function credits {
echo "GP2X ffmpeg video conversion script."
echo "Most of the work was done by me, Evan Goers."
echo "A couple other things done by David Severwright."
}

function usage {
echo "Usage:"
echo "gp2xconvert <inputfile> [outputdir]"
echo "inputfile must exist. After the conversion is done,"
echo "a file named <inputfile>.gp2x.avi will be present"
echo "in the current directory(default), or another directory"
echo "of your choice, indicated by the second argument."
}

if [ -z $1 ]; then
usage;
exit 1
fi

if [ -z $2 ]; then
OUTPUTDIR="."
else
OUTPUTDIR="$2"
fi

if [ -e $INPUTFILE ]; then
credits;
convert;
PASS="2"
convert;
exit 0
else
echo '"$INPUTFILE" does not exist. Please try again.'
usage;
exit 1
fi

(Updated 09/08/07)

Please provide improvements. I also released this(or tried to for that matter) under the GPLv2. If I implemented the GPL license wrong(or if it's better that I shouldn't), please inform me. I will correct it as soon as I can. It is the first time I've ever used the GPL license so please forgive me for any mistakes.

I'm not sure of the best and most optimized video specs that the GP2X can handle. However, videos converted with this script will and do work on the GP2X. If someone could help me get the best optimized conversion values that would be nice.
 
Last edited by a moderator:
detect the framerate of the input file and encode accordingly maybe also the audio rate
 
I just updated the script. It now does two passes for better quality. Videos done with the older script looked worse than YouTube videos.
 
Will this only work within Linux?

And how do you run it?

Eddie
 
ffmpeg is a lot faster sometimes. mencoder has a lot of features but the point here is to resize and re-encode the file to a compatible format for GP2X, and that is where ffmpeg shines.
 
Few funnies..

Didn't like filenames with spaces in:

CODE

./Gp2xConv "/home/Movies/Chemical Brothers - The Salmon Dance.avi"
./Gp2xConv: line 56: [: too many arguments
./Gp2xConv: line 67: [: too many arguments
"$INPUTFILE" does not exist. Please try again.
Usage:
gp2xconvert <inputfile> [outputdir]
inputfile must exist. After the conversion is done,
a file named <inputfile>.gp2x.avi will be present
in the current directory(default), or another directory
of your choice, indicated by the second argument.



And when I encoded a file without spaces, it ask if I wanted to overwrite half way though:

CODE


Input #0, avi, from 'salmon.avi':
Duration: 00:03:57.2, start: 0.000000, bitrate: 1364 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 624x352, 25.00 fps
Stream #0.1: Audio: mp3, 44100 Hz, stereo, 160 kb/s
File './salmon.avi.gp2x.avi' already exists. Overwrite ? [y/N] y
Output #0, avi, to './salmon.avi.gp2x.avi':



Can't try the video since I'm using a remote desktop to my ubuntu box to test this. Will try playing on my windows machine tonight.
 
Well much better than me - I know bugger all about shell scripts.

Video seems to play ok though. Damn useful to me since my avi's live on my linux box, so saves me copying accross to the windows box tying that up with encoding.

If I can figure out what the script is doing I'll dig into them probs.
 
I'm getting my GP2X in the mail tomorrow. Hopefully this script works well.

Before I was using ffmpeg to encode a video, and then using avidemux to encode again!

UPDATE: This script certainly encodes blockier than the ffmpeg to avidemux encode...and this was starting with youtube videos...
 
Yup. I have to figure out the encoding issues. Usually ffmpeg does resizing rather well. I guess it depends on the kind of video you're trying to re-encode.
 
Back
Top