Created
September 19, 2012 07:08
-
-
Save batako/3748114 to your computer and use it in GitHub Desktop.
FFmpeg : 動画からアスキートを生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEMP_FILE='.FILE_LIST.tmp' | |
make_temp_file() { | |
cd ${NAME} | |
ls -F | grep -v ./ > ${TEMP_FILE} | |
cd ../. | |
} | |
convert_png() { | |
BUFIFS=${IFS} | |
IFS= | |
exec 3< ${NAME}/${TEMP_FILE} | |
while read FL 0<&3 | |
do | |
T_NAME=${FL##*/} | |
T_FILE_NAME=${T_NAME%.*} | |
pngtopnm ${NAME}/${FL} | ppmtopgm | pgmtopbm -dither8 | pbmtoascii > ${NAME}/${T_FILE_NAME}.txt | |
rm ${NAME}/${FL} | |
done | |
exec 3<&- | |
IFS=${BUFIFS} | |
} | |
convert_jpg() { | |
echo ${TEMP_FILE} | |
BUFIFS=${IFS} | |
IFS= | |
exec 3< ${NAME}/${TEMP_FILE} | |
while read FL 0<&3 | |
do | |
T_NAME=${FL##*/} | |
T_FILE_NAME=${T_NAME%.*} | |
#jpegtopnm ${NAME}/${FL} | ppmtopgm | pnmscale -width 158 | pgmnorm | pgmtopbm | pbmtoascii -2x4 > ${NAME}/${T_FILE_NAME}.txt | |
jpegtopnm ${NAME}/${FL} | ppmtopgm | pnmscale -height 150 | pgmnorm | pgmtopbm | pbmtoascii > ${NAME}/${T_FILE_NAME}.txt | |
rm ${NAME}/${FL} | |
done | |
exec 3<&- | |
IFS=${BUFIFS} | |
} | |
if [ ! $# -eq 2 ] ; then | |
echo 'No Argument !' | |
exit | |
fi | |
if [ -f $2 ] ; then | |
FILE_NAME=${2##*/} | |
NAME=${FILE_NAME%.*} | |
rm -fr ${NAME} | |
mkdir ${NAME} | |
else | |
echo 'No File !'; | |
exit | |
fi | |
case $1 in | |
'-j' ) | |
ffmpeg -i $2 -f image2 ${NAME}/%d.jpg | |
make_temp_file | |
convert_jpg | |
;; | |
'-j2' ) | |
ffmpeg -i $2 -f image2 -vcodec mjpeg -qscale 1 -qmin 1 -qmax 1 ${NAME}/%d.jpg | |
make_temp_file | |
convert_jpg | |
;; | |
'-p' ) | |
#ffmpeg -i $2 -f image2 -vcodec png ${NAME}/%d.png | |
ffmpeg -i $2 -s qcif -f image2 ${NAME}/%d.jpg | |
make_temp_file | |
convert_png | |
;; | |
* ) | |
echo 'No Convert Type !' | |
exit | |
;; | |
esac | |
# Delete Temp File | |
rm -fr ${NAME}/${TEMP_FILE} | |
# Compression | |
rm -fr ${NAME}.zip | |
cd ${NAME} | |
zip ../${NAME}.zip ./* | |
cd ../. | |
# Delte Temp File | |
rm -fr ${NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment