makedist-recordvm: create better and less preview images by decreasing rate; fix preview*.jpg images size

This commit is contained in:
Silvan Calarco 2012-07-22 17:21:25 +02:00
parent 91c16825d5
commit 3069b88a8f

View File

@ -7,14 +7,36 @@ EXECUTION_TIME=200
VIDEO_EXT=.flv
VIDEO_EXT2=.ogv
[ $1 ] || {
function usage() {
echo "Usage:"
echo "recordvm.sh iso_path"
echo "recordvm.sh iso_path [--recreate-images] [-h]"
echo
exit 1
}
ISO_PATH=$1
opts=($@)
while test -n "$1" ; do
case $1 in
"--recreate-images") RECREATE_IMAGES=1;;
"-h") usage; exit 0 ;;
*) if [ -z "$ISO_PATH" ]; then
ISO_PATH=$1
else
echo "Error: extra argument $1 specified; aborting."
usage
exit 1
fi
esac
shift
done
[ "$ISO_PATH" ] || {
echo "Error: ISO path was not specified; aborting."
usage
exit 1
}
ISO_DIR=`dirname $ISO_PATH`
ISO_NAME=`basename $ISO_PATH`
@ -23,57 +45,58 @@ ISO_NAME=`basename $ISO_PATH`
exit 1
}
echo "Preparing ISO image $ISO_PATH"
ln -sf $ISO_PATH $RECORDVM_DATA/recordvm.iso
echo "Starting virtual machine for $ISO_PATH"
export HOME=$RECORDVM_DATA
xinit -- $VBOX_DISPLAY &
if [ ! "$RECREATE_IMAGES" ]; then
echo "Preparing ISO image $ISO_PATH"
ln -sf $ISO_PATH $RECORDVM_DATA/recordvm.iso
echo "Starting virtual machine for $ISO_PATH"
export HOME=$RECORDVM_DATA
xinit -- $VBOX_DISPLAY &
if [ "$VBOX" ]; then
# -nocursor &
# &>$RECORDVM_DATA/recordvm.log &
#VBOX_USER_HOME=$RECORDVM_DATA/VirtualBox DISPLAY=:0 /opt/VirtualBox/VBoxSDL --startvm $VBOX_VMNAME --fixedmode 1024 768 32 >/dev/null &
trap "VBoxManage controlvm $VBOX_VMNAME poweroff" INT QUIT TSTP
if [ "$VBOX" ]; then
# -nocursor &
# &>$RECORDVM_DATA/recordvm.log &
#VBOX_USER_HOME=$RECORDVM_DATA/VirtualBox DISPLAY=:0 /opt/VirtualBox/VBoxSDL --startvm $VBOX_VMNAME --fixedmode 1024 768 32 >/dev/null &
trap "VBoxManage controlvm $VBOX_VMNAME poweroff" INT QUIT TSTP
sleepcnt=0
while true; do
if [ "`VBoxManage list runningvms | grep $VBOX_VMNAME`" ]; then
break
fi
sleepcnt=0
while true; do
if [ "`VBoxManage list runningvms | grep $VBOX_VMNAME`" ]; then
break
fi
# xwininfo -display $VBOX_DISPLAY -name "$VBOX_VMNAME - Oracle VM VirtualBox" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"
# [ "$WINID" ] && break
sleep 1
if [ $sleepcnt -gt 20 ]; then
echo "VirtualBox did not start; aborting."
exit 1
fi
let sleepcnt=sleepcnt+1
done
WINID=`xwininfo -display $VBOX_DISPLAY -name "$VBOX_VMNAME - Oracle VM VirtualBox" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"`
VBoxManage controlvm $VBOX_VMNAME reset
else
sleepcnt=0
while true; do
WINID=`xwininfo -display $VBOX_DISPLAY -name "QEMU (qemu-recordvm)" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"`
[ "$WINID" ] && break
if [ $sleepcnt -gt 20 ]; then
echo "qemu did not start; aborting."
exit 1
fi
let sleepcnt=sleepcnt+1
sleep 1
done
fi
sleep 1
if [ $sleepcnt -gt 20 ]; then
echo "VirtualBox did not start; aborting."
exit 1
fi
let sleepcnt=sleepcnt+1
done
WINID=`xwininfo -display $VBOX_DISPLAY -name "$VBOX_VMNAME - Oracle VM VirtualBox" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"`
VBoxManage controlvm $VBOX_VMNAME reset
else
sleepcnt=0
while true; do
WINID=`xwininfo -display $VBOX_DISPLAY -name "QEMU (qemu-recordvm)" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"`
[ "$WINID" ] && break
if [ $sleepcnt -gt 20 ]; then
echo "qemu did not start; aborting."
exit 1
fi
let sleepcnt=sleepcnt+1
sleep 1
done
fi
echo "Windowid is: $WINID"
echo "Windowid is: $WINID"
echo "Capturing window output"
mkdir -p $ISO_DIR/preview/
DBUS_SESSION_BUS_ADDRESS= HOME=$RECORDVM_DATA DISPLAY=$VBOX_DISPLAY xvidcap \
--cap_geometry 1024x768+0+0 \
--verbose 2 --gui no --audio no \
--time $EXECUTION_TIME --file $ISO_DIR/preview/${ISO_NAME}${VIDEO_EXT} \
--quality 100 >>$RECORDVM_DATA/recordvm.log
echo "Capturing window output"
mkdir -p $ISO_DIR/preview/
DBUS_SESSION_BUS_ADDRESS= HOME=$RECORDVM_DATA DISPLAY=$VBOX_DISPLAY xvidcap \
--cap_geometry 1024x768+0+0 \
--verbose 2 --gui no --audio no \
--time $EXECUTION_TIME --file $ISO_DIR/preview/${ISO_NAME}${VIDEO_EXT} \
--quality 100 >>$RECORDVM_DATA/recordvm.log
#recordmydesktop --no-frame --display $VBOX_DISPLAY --windowid $WINID -o $ISO_DIR/preview/$ISO_NAME.ogv --overwrite --no-sound --no-wm-check --fps 10 --no-cursor &
#echo "Sleeping $EXECUTION_TIME seconds..."
#sleep $EXECUTION_TIME
@ -85,46 +108,49 @@ DBUS_SESSION_BUS_ADDRESS= HOME=$RECORDVM_DATA DISPLAY=$VBOX_DISPLAY xvidcap \
# sleep 1
#done
echo "Powering off VM"
if [ "$VBOX" ]; then
VBoxManage controlvm $VBOX_VMNAME poweroff &
echo "Powering off VM"
if [ "$VBOX" ]; then
VBoxManage controlvm $VBOX_VMNAME poweroff &
count=0
while [ "`pidof VBoxManage`" ]; do
let count=count+1
sleep 1
if [ $count -gt 60 ]; then
killall -9 VBoxManage
break
count=0
while [ "`pidof VBoxManage`" ]; do
let count=count+1
sleep 1
if [ $count -gt 60 ]; then
killall -9 VBoxManage
break
fi
done
else
xkill -id $WINID -display $VBOX_DISPLAY
fi
done
else
xkill -id $WINID -display $VBOX_DISPLAY
fi
echo "Creating preview images"
rm -f $ISO_DIR/preview/*.jpg
ffmpeg -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} -r 1 -f image2 $ISO_DIR/preview/image-%03d.jpg >/dev/null
for i in `seq 200 -1 1`; do
f=`printf %03d $i`
ffmpeg -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} -r 0.1 -f image2 $ISO_DIR/preview/image-%02d.jpg >/dev/null
for i in `seq 22 -1 1`; do
f=`printf %02d $i`
[ -e $ISO_DIR/preview/image-$f.jpg ] && {
convert -size 320x200 $ISO_DIR/preview/image-$f.jpg $ISO_DIR/preview/preview.jpg
convert -size 400x300 $ISO_DIR/preview/image-$f.jpg $ISO_DIR/preview/preview-400x300.jpg
convert -resize 320x200 $ISO_DIR/preview/image-$f.jpg $ISO_DIR/preview/preview.jpg
convert -resize 400x300 $ISO_DIR/preview/image-$f.jpg $ISO_DIR/preview/preview-400x300.jpg
break
}
done
echo "Creating ${VIDEO_EXT2} video from ${VIDEO_EXT}"
if [ ! "$RECREATE_IMAGES" ]; then
echo "Creating ${VIDEO_EXT2} video from ${VIDEO_EXT}"
#ffmpeg -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2} >/dev/null
ffmpeg2theora -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2} >/dev/null
ffmpeg2theora -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2} >/dev/null
#cleanup old files
for f in `ls $ISO_DIR/preview/*${VIDEO_EXT}`; do
[ "$f" = "$ISO_DIR/preview/$ISO_NAME${VIDEO_EXT}" ] || rm -f $f
done
for f in `ls $ISO_DIR/preview/*${VIDEO_EXT2}`; do
[ "$f" = "$ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2}" ] || rm -f $f
done
for f in `ls $ISO_DIR/preview/*${VIDEO_EXT}`; do
[ "$f" = "$ISO_DIR/preview/$ISO_NAME${VIDEO_EXT}" ] || rm -f $f
done
for f in `ls $ISO_DIR/preview/*${VIDEO_EXT2}`; do
[ "$f" = "$ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2}" ] || rm -f $f
done
fi
echo "Done."
exit 0