picture_transcode () { local VIDEO_SRC="$1" local VIDEO_DST="$2" local VIDEO_FPS="$3" local VIDEO_GEOMETRY="$4" local PICTURE_TIME="$5" local CURRENT_DIR=`pwd` local PICTURE_EXT="" local VIDEO_FRAME_HZ="" local MPEG_TO_ENC_N="" local PICTURE_X="" local PICTURE_Y="" local VIDEO_X="" local VIDEO_Y="" local PICTURE_MOVE_X="" local PICTURE_MOVE_Y="" local PICTURE_FRAMES="" local TEMPORARY=`tempfile` # touch $TEMPORARY # if [ "$VIDEO_FPS" = "25" ] then MPEG_TO_ENC_N="p" PICTURE_FRAMES=$((25 * $PICTURE_TIME)) else MPEG_TO_ENC_N="n" PICTURE_FRAMES=$((30 * $PICTURE_TIME)) fi # VIDEO_X=`echo $VIDEO_GEOMETRY | sed "s/x[0-9]*$//"` VIDEO_Y=`echo $VIDEO_GEOMETRY | sed "s/^[0-9]*x//"` # # Convert keeping the aspect ratio. # convert -scale $VIDEO_GEOMETRY $VIDEO_SRC $TEMPORARY.jpg # # Get geometry. # PICTURE_X=`identify $TEMPORARY.jpg | sed "s/^.* JPEG \([0-9]*\)x\([0-9]*\).*$/\1/"` PICTURE_Y=`identify $TEMPORARY.jpg | sed "s/^.* JPEG \([0-9]*\)x\([0-9]*\).*$/\2/"` # # Calculate pixel shift to get a centered image. # PICTURE_MOVE_X=$((($VIDEO_X - $PICTURE_X) / 2)) PICTURE_MOVE_Y=$((($VIDEO_Y - $PICTURE_Y) / 2)) # # Create a gray background # convert -geometry $VIDEO_GEOMETRY! \ -fill gray \ -colorize 100% \ $VIDEO_SRC $TEMPORARY.bg.jpg # # Put the image on the center. # composite -geometry +$PICTURE_MOVE_X+$PICTURE_MOVE_Y \ $TEMPORARY.jpg \ $TEMPORARY.bg.jpg \ $TEMPORARY.x.jpg # # Convert to a YUV4MPEG video. # jpeg2yuv -n $PICTURE_FRAMES -I p -f $VIDEO_FPS -j $TEMPORARY.x.jpg | \ mpeg2enc -n $MPEG_TO_ENC_N -f 3 -b 200 -o $TEMPORARY.m2v # # Create a silent audio track of 1/30 s. # dd if="/dev/zero" bs=4 count=1600 | \ toolame -b 128 -s 48 /dev/stdin $TEMPORARY.mp2 # # Multiplex video and audio for DVD. # mplex -f 8 -V -o $VIDEO_DST \ $TEMPORARY.m2v \ $TEMPORARY.mp2 # # Remove temporary files. # rm -f $TEMPORARY* }