[bglug] A grande richiesta... Lazy scripts

k|b|s kbs@bglug.it
Mer 11 Gen 2006 10:00:51 CET


A grande richiesta dei /numerosissimi/ partecipanti all'incontro di ieri sera,
vi posto alcuni script.

*asciify* -->
Converte un immagine nel corrispettivo in ascii, 1024x768, ottima risoluzione.
Required: imagemagick, aview/asciiview, X.

--8<-- CUT HERE --8<-- 
#!/bin/sh

# Output image extension
# jpg, png, ecc.
ext=png

if test $# -eq 0
then
	        echo "usage: asciify [infile]"
	        echo ""
	        exit
fi

pwd=`pwd $1`
rname=`basename $1 | awk -F "." '{print $1}'`

convert "$pwd/$1" tmpimage.pnm

#xterm -fn 5x7 -geometry 220x120 -e aview -dim -bold -reverse -normal -driver slang tmpimage.pnm &

xterm -font "-misc-fixed-*-r-normal-*-6-*-*-*-*-*-*-*" -geometry 260x130 -e aview -dim -bold -reverse -normal -driver slang tmpimage.pnm &

sleep 2 && xwd -out tmpimage.xwd -nobdrs -name 'aview'
pkill aview
#convert tmpimage.xwd imgAA-`date '+%d.%m.%y-%H:%M:%S'`.$ext
convert tmpimage.xwd $rname.$ext
rm tmpimage*
exit
--8<-- CUT HERE --8<-- 

Convertire video per il telefonino.
Metodo 1: usa direttamente ffmpeg, ma se il video è corrotto o è di formati
balordi (vedi .wmv ecc.) non è ottimale.
*ff23gp* -->

--8<-- CUT HERE --8<-- 
#!/bin/sh
ffmpeg -i $1 -b 500 -acodec amr_nb -ar 8000 -ac 1 -ab 32 -vcodec h263 -s qcif -r 10 $2
--8<-- CUT HERE --8<-- 

Metodo 2: mplayer/mencoder per estrazione video e ffmpeg per l'audio. Va con
tutto.
*movie23gp* -->

--8<-- CUT HERE --8<-- 
#!/bin/sh

if test $# -eq 0 
then
	echo "usage: movie23gp [infile]"
	echo ""
	exit
fi

pwd=`pwd $1`
tmp=~/tmp

rname=`basename $1 | awk -F "." '{print $1".3gp"}'`


cd $tmp

mencoder "$pwd/$1" -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:-2 -o movie.avi -ofps 12

mplayer -vo null -ao pcm -af resample=8000,volume=+4db:sc "$pwd/$1" 

ffmpeg -i movie.avi -i audiodump.wav -b 48 -ac 1 -ab 12 -map 0.0 -map 1.0 $rname

cd -
mv $tmp/$rname .

rm $tmp/audiodump.wav $tmp/movie.avi
--8<-- CUT HERE --8<-- 

Lamerata gigante. Conversione dei video in ascii. Se avete il tempo di
aspettare l'estrazione di tutti i frames e la loro conversione...
*movie2ascii* -->

--8<-- CUT HERE --8<-- 
#!/bin/sh

# Cambia a tuo piacimento:
TMP=/home/kbs/tmp/AAmovie

##########################
if test $# -eq 0 
then
	echo "usage: movie2ascii [infile]"
	echo ""
	exit
fi

mkdir -p $TMP
mkdir -p $TMP/video
mkdir -p $TMP/audio
chmod 700 $TMP

JPG1=$TMP/jpg1
if [ ! -d $JPG1 ]; then
  mkdir -p $JPG1
  chmod 700 $JPG1
fi

JPG2=$TMP/jpg2
if [ ! -d $JPG2 ]; then
  mkdir -p $JPG2
  chmod 700 $JPG2
fi

PNMS=$TMP/pnms
if [ ! -d $PNMS ]; then
  mkdir -p $PNMS
  chmod 700 $PNMS
fi

AA=$TMP/AA
if [ ! -d $AA ]; then
  mkdir -p $AA
  chmod 700 $AA
fi

pwd=`pwd $1`
rname=`basename $1 | awk -F "." '{print $1".mpg"}'`

# Extracting video
cd $JPG1
mplayer "$pwd/$1" -benchmark -noframedrop -nosound -vo jpeg

# extracting audio
ffmpeg -i "$pwd/$1" -vn -acodec mp3 -ac 2 -ar 44100 -ab 128 $TMP/audio/audio.mp3

# converting jpgs
export tot=`ls $JPG1 | wc -l`

for i in `seq -f %08g.jpg 1 $tot`
do
	convert -quality 100 -crop 720x360+0+60 $i $JPG2/"`basename "$i" .jpg`.jpg"
done
rm -rf $JPG1/*
#
cd $JPG2
for i in `seq -f %08g.jpg 1 $tot`
do
	jpegtopnm $i > $PNMS/"`basename "$i" .jpg`.ppm" 2>/dev/null
done
rm -rf $JPG2/*

# converting pnm
cd $PNMS
for i in `seq -f %08g.ppm 1 $tot`
do 
xterm -font "-misc-fixed-*-r-normal-*-6-*-*-*-*-*-*-*" -geometry 260x130 \
	-e aview -driver slang $i &
	sleep 1 && xwd -out $AA/"`basename "$i" .ppm`.xwd" -nobdrs -name 'aview'
	pkill aview
done
rm -rf $PNMS/*

# converting xwd dump
cd $AA
for i in `seq -f %08g.xwd 1 $tot`
do
	convert -crop 1080x720+0+10 -geometry 720x480 $i $JPG2/"`basename "$i" .xwd`.jpg"
done
rm -rf $AA/*

# converting to raw ppp
cd $JPG2
for i in `seq -f %08g.jpg 1 $tot`
do
	convert $i $PNMS/"`basename "$i" .jpg`.ppm"
done
rm -rf $JPG2/*


# creating stream
cd $PNMS
cat *.ppm | ppmtoy4m | mpeg2enc -q 7 -F 1 -a 3 -4 1 -2 1 -P -I 0 -N 0 -o $TMP/video/vid.m2v
rm -rf $PNMS/*

cd -
# audio+video
mplex -f 8 -M -V -o "$rname" $TMP/video/vid.m2v $TMP/audio/audio.mp3

#rm -rf $AA $JPG1 $JPG2 $PNMS $TMP/audio $TMP/video
rm -rf $TMP
--8<-- CUT HERE --8<-- 

Vuoi vedere un immagine in ascii ad alta risoluzione? Buona per il mailcap di
mutt...
Richiede asciview.
*aahqview* -->

--8<-- CUT HERE --8<-- 
#!/bin/sh
#xterm -fn 5x7 -geometry 220x120 -e asciiview -driver slang $1
xterm -font "-misc-fixed-*-r-normal-*-6-*-*-*-*-*-*-*" -geometry 260x130 -e asciiview -driver slang $1
--8<-- CUT HERE --8<-- 

Il tutto ovviemente sotto GPL2.

-- 
No messages found in this outgoing virus.
k|b|s ~> mailto `echo ti.gulgb@sbk|'rev'`


Maggiori informazioni sulla lista bglug