-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandrovideo
executable file
·195 lines (180 loc) · 5.99 KB
/
androvideo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
####################################################################################
# Androvideo - Harel Malka 2009
# http://www.harelmalka.com
#
# A bash script to help convert video files for usage in the android based HTC G1/Magic
# handsets. I've done this script for myself mainly, so it assumes you're using a debian
# based distro for the setup portion of the script. If you don't have apt, you'll have
# to do the leg work and get all the pre-equisites sorted out yourself.
# The conversion is pretty straight forward but requires the h263 decode/encode libs
# and ffmpeg to be compiled against them. When you perform the setup portion the script
# will *attempt* to do all for you, but this is only an attempt.
# What is supposed to happen is:
# * Get all build dependencies for ffmpeg via apt.
# * Gets a few libs ffmpeg will need, subversion, checkinstall and build-essentials
# * Downloads the amr shared libs from http://www.penguin.cz/~utx/amr and attempts to compile/install
# * Gets latest ffmpeg from svn and attempts to compile/install with the amr libs included
# * Get rid of all downloaded files and compiled pre-install crap
#
# I could not have done this without the very good help from these resources:
# http://www.linuxquestions.org/questions/linux-mobile-81/androidg1-and-video-converted-via-ffmpeg-h263-687163/
# http://po-ru.com/diary/up-to-date-ffmpeg-on-ubuntu-hardy/
# http://tldp.org/LDP/abs/html/
# http://www.penguin.cz/~utx/amr
#
# some variable and function definitions
RESOLUTION="480x320" # default resolution
AUDIO_CHANNELS="1"
AUDIO_SAMPLING_RATE="16000"
AUDIO_BIT_RATE="32000"
FRAME_RATE="13"
declare -a VIDEO_FILES # array to hold the files to covert
convert () {
echo "Converting ${1}"
ffmpeg -i "$1" -s "$RESOLUTION" -vcodec mpeg4 -acodec libfaac -ac 1 -ar "$AUDIO_SAMPLING_RATE" -r "$FRAME_RATE" -ab "$AUDIO_BIT_RATE" -aspect 3:2 "$1.mp4"
}
setup () {
# check if we're root
if [ "$UID" -ne "0" ]
then
echo "You must be root to run the setup script."
exit 87 # Not root exit code
fi
# check for apt to get dependencies. Otherwise warn.
# Note that for ubuntu distro's prior to Jaunty replace libmp3lame-dev with liblame-dev
if which apt-get
then echo "Apt found. Getting dependencies"
sudo apt-get build-dep ffmpeg
sudo apt-get install libmp3lame-dev libfaad-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 \
liba52-0.7.4-dev libx264-dev libdts-dev libgsm1-dev checkinstall build-essential subversion
else
echo "Your system does not have Apt. You'll need to make sure you have the following dependencies:"
echo "liblame-dev libfaad-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 "
echo "liba52-0.7.4-dev libx264-dev libdts-dev libgsm1-dev checkinstall build-essential subversion"
echo ""
echo "Continue [Y/N]"
read YESNO
if [ $YESNO != "Y" ]
then echo "Sort it out, and run Setup again"
exit 1
fi
fi
echo "Performing setup. Please duck and cover."
# create a temp directory to work in
mkdir tmp-worker
cd tmp-worker
# download the amr libs to handle h263 decode/encode
wget "http://ftp.penguin.cz/pub/users/utx/amr/amrnb-7.0.0.2.tar.bz2"
wget "http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.3.tar.bz2"
# get ffmpeg from svn
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
# unzip end untar
tar -xjvf amrnb-7.0.0.2.tar.bz2
tar -xjvf amrwb-7.0.0.3.tar.bz2
# configure, compile and install the libs
cd amrwb-7.0.0.3
./configure
make
make install
cd ../amrnb-7.0.0.2
./configure
make
make install
# configure compile and install latest ffmpeg with the h263 decoders
cd ffmpeg
./configure --enable-gpl --enable-libamr_nb --enable-libamr_wb --enable-libmp3lame \
--enable-libvorbis --enable-libfaac --enable-libfaad --enable-nonfree \
--enable-decoder=h263 --enable-encoder=h263
make
checkinstall
cd ../
rm -rf tmp-worker
echo "Done! Carry on..."
}
help () {
echo "This conversion works on HTC G1 or Magic models. "
echo "You're welcome to try on other OS/models as well (at own risk)."
echo ""
echo "Options:"
echo " -r Video resolution. Default to 480x320"
echo " -c Number of audio channels. Default to 1."
echo " -sr Audio sampling rate. Default to 16000"
echo " -br Audio bit rate. Default to 32000"
echo " -fr Frame rate. Default to 13 fps."
echo ""
echo "Androvideo can also attempt to setup required decoders and compile ffmpeg against them using:"
echo " androvideo -s (or androvideo --setup) "
echo ""
}
##############################################################################
# Start
echo "--------------------------------------------------------------------"
echo "Androvideo - The Android video convertor"
echo "Harel Malka, May 2009"
echo "http://www.harelmalka.com"
echo ""
echo "Usage: androvideo [OPTIONS] [FILE] [FILE]... "
echo "Try: 'androvideo -h' for more help"
echo ""
echo "THERE IS NO WARRANTY WHATSOEVER. USE AT OWN RISK!"
echo "I AM NOT RESPONSIBLE FOR ANY DAMAGE CAUSED TO YOU OR YOUR COMPUTER."
echo "--------------------------------------------------------------------"
echo ""
# work out the command line arguments
while [ $# -gt 0 ]; do
case "$1" in
-s|--setup)
setup
exit 1
;;
-h|--help)
help
exit 1
;;
-r)
RESOLUTION="$2"
shift
;;
-c)
if [ "$2" -gt 2 ]
then
echo "ERROR: -c (Audio channels) option must be 1 or 2"
exit 0
else
AUDIO_CHANNELS="$2"
shift
fi
;;
-sr)
AUDIO_SAMPLING_RATE="$2"
shift
;;
-br)
AUDIO_BIT_RATE="$2"
shift
;;
-fr)
FRAME_RATE="$2"
shift
;;
* )
VIDEO_FILES=( "${VIDEO_FILES[@]}" "$1" )
;;
esac
shift # Check next set of parameters.
done
# display conversion parameters
echo "--------------------------------------------------"
echo "Coversion parameters:"
echo " Resolution: ${RESOLUTION}"
echo " Audio Channels: ${AUDIO_CHANNELS}"
echo " Audio Sampling Rate: ${AUDIO_SAMPLING_RATE}"
echo " Audio Bit Rate: ${AUDIO_BIT_RATE}"
echo " Video Frame Rate: ${FRAME_RATE}"
echo ""
# perform the conversions
for FILE in "${VIDEO_FILES[@]}"
do
convert $FILE
done