mkvmerge --split size:32m ./heihu01.mp4 -o ./heihu01.%05d.mp4
for i in `ls heihu01.*.mp4`; do hadoop fs -put $i movies/; done
hadoop fs -mkdir movies_input
hadoop fs -mkdir movies_put
1、編寫腳本
#!/bin/bash
set -x
id="`whoami`"
mkdir -p /tmp/\$id
host=\`hostname\`
pwd=\`pwd\`
uid=\`whoami\`
put_dir='movies_put'
while read line; do
input=\$line
filename=\`basename \$input\`
echo "\$uid@\$host:\$pwd> hadoop fs -get \$input /tmp/\$id/\$filename"
echo "\$uid@\$host:\$pwd> ffmpeg -y -i /tmp/\$id/\$filename -s qcif -r 20 -b 200k -vcodec mpeg4 -ab 64k -ac 2 -ar 22050 -acodec libfaac output-\$filename.3gp"
echo "\$uid@\$host:\$pwd> hadoop fs -put output-\$filename \${put_dir}"
done
rm -rf /tmp/\$id
EOF
chmod a+x test_mapper.sh
cat movies_aa |./test_mapper.sh
hadoop jar /usr/local/hadoop/contrib/streaming/hadoop-streaming-1.0.2.jar -input movies_input -output movies_output -mapper test_mapper.sh -file test_mapper.sh
hadoop fs -cat /user/$(whoami)/movies_output/part-00000 | head
八、使用hadoop streaming執行轉碼
1、編寫腳本
#!/bin/bash
id="hduser"
mkdir -p /tmp/\$id
host=\`hostname\`
pwd=\`pwd\`
uid=\`whoami\`
put_dir='movies_put'
cd "/tmp/\$id"
true > a
while read line; do
input=\$line
filename=\`basename \$input\`
echo "\$uid@\$host> hadoop fs -get \$input /tmp/\$id/\$filename"
/usr/local/hadoop/bin/hadoop fs -get \$input /tmp/\$id/\$filename 2>&1
echo "\$uid@\$host> ffmpeg -y -i /tmp/\$id/\$filename -s qcif -r 20 -b 200k -vcodec mpeg4 -ab 64k -ac 2 -ar 22050 -acodec libfaac output-\$filename.3gp"
ffmpeg -y -i /tmp/\$id/\$filename -s 320*240 -r 20 -b 200k -vcodec mpeg4 -ab 64k -ac 2 -ar 22050 -qscale 5 -acodec libfaac output-\$filename.3gp < a 2>&1
/usr/local/hadoop/bin/hadoop fs -put output-\$filename.3gp \${put_dir} 2>&1
echo "\$uid@\$host> hadoop fs -chown \$id \${put_dir}/output-\$filename.3gp"
/usr/local/hadoop/bin/hadoop fs -chown \$id \${put_dir}/output-\$filename.3gp 2>&1
done
rm -f a
rm -rf /tmp/\$id
EOF
chmod a+x mapper.sh
2、本地執行測試
-rw-r--r-- 3 hduser supergroup 19584280 2012-05-28 13:53 /user/hduser/movies_put/output-heihu01.00001.mp4.3gp
-rw-r--r-- 3 hduser supergroup 14872878 2012-05-28 13:54 /user/hduser/movies_put/output-heihu01.00002.mp4.3gp
-rw-r--r-- 3 hduser supergroup 12052800 2012-05-28 13:55 /user/hduser/movies_put/output-heihu01.00003.mp4.3gp
-rw-r--r-- 3 hduser supergroup 11174014 2012-05-28 13:53 /user/hduser/movies_put/output-heihu01.00004.mp4.3gp
-rw-r--r-- 3 hduser supergroup 15713836 2012-05-28 13:55 /user/hduser/movies_put/output-heihu01.00005.mp4.3gp
-rw-r--r-- 3 hduser supergroup 13084511 2012-05-28 13:56 /user/hduser/movies_put/output-heihu01.00006.mp4.3gp
pwd=\`pwd\`
-rw-r--r-- 3 hduser supergroup 19584280 2012-05-29 14:15 /user/hduser/movies_put/output-heihu01.00001.mp4.3gp
-rw-r--r-- 3 hduser supergroup 14872878 2012-05-29 14:16 /user/hduser/movies_put/output-heihu01.00002.mp4.3gp
-rw-r--r-- 3 hduser supergroup 12052800 2012-05-29 14:17 /user/hduser/movies_put/output-heihu01.00003.mp4.3gp
-rw-r--r-- 3 hduser supergroup 11174014 2012-05-29 14:15 /user/hduser/movies_put/output-heihu01.00004.mp4.3gp
-rw-r--r-- 3 hduser supergroup 15713836 2012-05-29 14:16 /user/hduser/movies_put/output-heihu01.00005.mp4.3gp
-rw-r--r-- 3 hduser supergroup 13084511 2012-05-29 14:17 /user/hduser/movies_put/output-heihu01.00006.mp4.3gp
-rw-r--r-- 3 hduser supergroup 86175913 2012-05-29 14:17 /user/hduser/movies_put/output.3gp