#!/bin/bash # ------------------------------------------------------------------------------------------------------- # DESCRIPTION : # # IMAGES2MPG : convert images sequence on a MPEG files for create a VCD/SVCD/XVCD/DVD portfolio (with vcdimager) # # This script use this packages : 'ImageMagick' ver >= 5.4.8 [http://www.imagemagick.org/] # 'MjpegTools' ver >= 1.6.0 [http://mjpeg.sourceforge.net/] # # You give the images files names on the command line (see the options '--help'). # The images formats must be reconized by ImageMagick program. # # This script used this externals binary programs : # # - 'montage' from ImageMagick for resize the images for the TV screen size. # - 'composite' from ImageMagick for make the transition between images. # - 'convert' from ImageMagick for convert the images before MPEG encoding. # - 'identify' from ImageMagick for check the background image file size. # - 'ppmtoy4m' from MjpegTools for create a video stream from the image. # - 'yuvscaler' from MjpegTools for adapt the video stream size before MPEG encoding. # - 'mpeg2enc' from MjpegTools for encode the video stream in MPEG file. # - 'ogg123' from vorbis-utils to transcode an ogg-audio file to wav # - 'mpg123' to transcode an mp3-audio file to wav # - 'mp2enc' from MjpegTools to transcode a WAV sound file to a MP2 file. # - 'mplex' from MjpegTools for multiplexe the MPEG file and the MP2 sound and convert # the final MPEG file to a DVD/XVCD/SVCD/VCD format compatible with vcdimager program. # # You can use the 'KIPI' KDE frontend with this script. Look this URL : http://extragear.kde.org/apps/kipi # # Return value : 0 -> Process finish succefuly. # 1 -> Error. # # ------------------------------------------------------------------------------------------------------- # # ABOUT VIDEO TYPES AND FORMATS SUPPORTED BY THIS SCRIPT : # # Video type :: VCD : SVCD : XVCD : DVD : # :: : : : : : : : : # Video format :: PAL/SECAM: NTSC : PAL/SECAM: NTSC : PAL/SECAM: NTSC : PAL/SECAM: NTSC : # :: : : : : : : : : # Resolution :: 352x288 : 352x240 : 576x480 : 480x480 : 720x576 : 720x480 : 720x576 : 720x480 : # :: : : : : : : : : # Frame/s :: 25 : 30 : 25 : 30 : 25 : 30 : 25 : 30 : # :: : : : : # MPEG type :: MPEG1 : MPEG2 : MPEG2 : MPEG2 : # :: : : : : # Video CDR :: 74 mn : 60 mn : 50 mn : 15 mn : # duration :: : : : : # :: : : : : # Video :: 1,150 kbit/s : 2,500 kbit/s : 2,500 kbit/s : 8,000 kbit/s : # bitrate :: : : : : # :: : : : : # Sound format :: MP2 : MP2 : MP2 : MP2 : # :: : : : : # Audio :: 224 kbit/s : 224 kbit/s : 224 kbit/s : 224 kbit/s : # biterate :: : : : : # :: : : : : # DVD player :: excelent : good : medium : excelent : # compatibility:: : : : : # :: : : : : # Image :: medium : good : excelent : excelent : # restitution :: : : : : # # Notes : - The XVCD resolution is the same of DVD ! # # ------------------------------------------------------------------------------------------------------- # # AUTHOR : CAULIER gilles # # ------------------------------------------------------------------------------------------------------- # # TODO : # # * Add an option for select PAL or NTSC video format. # * Add transitions betwen the images in the MPEG sequence. # * Write a man page file with some examples and more informations. # * Don't use an default external black 'PNG' background image file. # * Add an option with the RVB color for the background image color. # * Add a trap signal fonction : clear temporary files when killed. # * Add an option for a specific temporary folder. # - Add DIVX support. # # ------------------------------------------------------------------------------------------------------- # LICENSE : # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA # 02110-1301, USA. # # ------------------------------------------------------------------------------------------------------- # CHANGELOG : # # March 2002 : Original release by Gilles CAULIER . # November 2002 : Add a convert image format fonction with ImageMagick. # Add resize the image for the TV screen with ImageMagick. # Add Endoding time measurement. # Add many images files on the same MPEG file. # Add using of temporary files. # Add some command line options. # Add encoding sound on the MPEG file. # December 2002 : Fix some bugs. # Add some command line parameters controls. # Add some English comments. # Add a video type command line option (PAL, NTSC, SECAM). # Remove '-F' option (frame rate value -> fixed by video type option) # Add an exiting test of input image files before encoding. # Add an exiting test of input audio files and mask file before encoding. # Add an exiting test if verbosity level is unknown. # Add image sequence duration value test. # Add an implementation for don't used a default 'black.png' file. ImageMagick create a # temporary PNG file for this. # Add warning if total duration is <=3 s. # Remove 3s image duration limitation. # Add test about image background size. # Add an option for define the background image RGB color. # Add a trap fonction for remove the temporary files. # Add a transition fonction with 'composite' binary program from ImageMagick package. # Add a final transition for the sequence. # Add this script to the MjpegTools project on sourceforge repository. # January 2003 : Add a manual page (on MjpegTools project package). # Add an option for use a temporary folder. # Add '--with-gui' option for run with 'kimg2mpg' KDE gui frontend program. # Change the IFS variable for a correct interpretation of the whitespaces in the path # files names. # Add DVD video format option. # Change trap fonction. # Change some console messages for the KDE GUI. # February 2003 : Update 'Kimg2mpg' KDE frontend WEB site URL. # September 2003: Moving to the Digikam project (http://digikam.sourceforge.net). # Add options for ImageMagick and MjpegTools binary folders informations. # October 2003 : Rename this file to 'images2mpg'. # # ------------------------------------------------------------------------------------------------------- # --------------------------------------FONCTIONS-------------------------------------------------------- #Clean the temporary file and exit. Used by the Trap fonction and at end of this script. CleanUp() { if [ $WITHGUI = 0 ]; then echo -e "Removing temporary files..." fi if [ -e "$TMPFILENAME.tmp.m2v" ]; then rm "$TMPFILENAME.tmp.m2v" fi if [ -e "$TMPFILENAME.tmp.jpg" ]; then rm "$TMPFILENAME.tmp.jpg" fi if [ -e "$TMPFILENAME.tmp.pnm" ]; then rm "$TMPFILENAME.tmp.pnm" fi if [ "$AUDIO_WAV" ]; then if [ -e "$TMPFILENAME.tmp.wav" ]; then rm "$TMPFILENAME.tmp.wav" fi if [ -e "$TMPFILENAME.tmp.mp2" ]; then rm "$TMPFILENAME.tmp.mp2" fi fi if [ "$MASK"="$TMPFILENAME.black.tmp.png" ]; then if [ -e "$MASK" ]; then rm "$MASK" fi fi if [ $TRANSITIONENABLE = 1 ]; then if [ -e "$TMPFILENAME.prev_trans.tmp.pnm" ]; then rm "$TMPFILENAME.prev_trans.tmp.pnm" fi if [ -e "$TMPFILENAME.next_trans.tmp.pnm" ]; then rm "$TMPFILENAME.next_trans.tmp.pnm" fi fi exit 0 } # ------------------------------------END OF FONCTIONS--------------------------------------------------- # --------------------------------------MAIN------------------------------------------------------------- # Trap shell Q_SIGNALS fonction. trap CleanUp 2 # Default parameters values. # Default MPEG video format. VIDEO_FORMAT="XVCD" # Default video type. VIDEO_TYPE="PAL" #Default Chroma subsampling mode (ppmtoy4m) PPMTOY4M_CHROMA_OPT="-S 420mpeg2" # Default verbosity level . # 0 -> Just the error messages or warnings. # 1 -> level 0 + informations messages. # 2 -> level 1 + debug messages. VERBOSE=0 # Default duration for one image in the MPEG sequence. Minimal value is 1s. IMAGEDURATION=10 # Default transition parameters. TRANSITIONENABLE=0 TRANSITIONDURATION=0 # Default temporary folder is local folder. TEMPORARYFOLDER="" # Default ImageMagick binary folder -> using PATH variable. IMBINFOLDER="" # Default MJPEGTools binary folder -> using PATH variable. MJPEGTBINFOLDER="" # Not running with 'KIPI' KDE gui frontend. WITHGUI=0 # Command line parameters analyse... CPT_IMG_FILE=0 if [ $# == 0 ]; then echo -e "No option specified... 'images2mpg -h' for more informations." exit 1 fi while test $# -gt 0; do OPTIONMESSAGE=$1 case $1 in # Verbosity... -v) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi VERBOSE=$1 ;; # Running with 'KIPI' KDE frontend... --with-gui) WITHGUI=1 ;; # Temporary folder... -T) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi TEMPORARYFOLDER=$1 IFS=$OLD_IFS ;; # Transition between images... -t) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi if [ $[$1 == 1 || $1 == 2 || $1 == 4 || $1 == 5 || $1 == 10 || $1 == 20] = 1 ]; then # Increment value for dissolving the images with the transition. DISSOLVEVALUEINC=$1 TRANSITIONENABLE=1 else echo -e "Bad transition speed value (must be 1, 2, 4, 5, 10, or 20) !" exit -1 fi ;; # Video format... -f) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi VIDEO_FORMAT=$1 ;; # Video type... -n) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi VIDEO_TYPE=$1 ;; # Chroma subsampling mode (ppmtoy4m option)... -S) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi PPMTOY4M_CHROMA_OPT="-S $1" ;; # Background image file... -b) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi if [ -s $1 ]; then MASKGEOMETRY=`$IDENTIFY_BIN -verbose $1 |grep Geometry |awk '{print $2}'` if [ $MASKGEOMETRY != "768x576" ]; then echo -e "The size of background image file '$1' isn't 768x576 pixels [$MASKGEOMETRY]!!!" exit -1 else MASK=$1 fi else echo -e "The background image file '$1' don't exist or can't be open !!!" exit -1 fi IFS=$OLD_IFS ;; # Background color... -c) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 else BACKGROUNDCOLOR=$1 fi ;; # Images duration... -d) shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi IMAGEDURATION=$1 if [ $[$IMAGEDURATION == 0] = 1 ]; then echo -e "Image duration value must be >= 1 !" exit -1 fi ;; # MP2 audio file... -a) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi if [ -s $1 ]; then AUDIO_MPEG=$1 else echo -e "The MP2 audio file '$1' don't exist or can't be open !!!" exit -1 fi IFS=$OLD_IFS ;; # WAV/MP3/OGG audio file... -w) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi if [ -s $1 ]; then AUDIO_WAV=$1 else echo -e "The WAV/OGG/MP3 audio file '$1' don't exist or can't be open !!!" exit -1 fi IFS=$OLD_IFS ;; # MPEG output file... -o) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi OUTPUT_MPEG_FILE=$1 IFS=$OLD_IFS ;; # Image input files... -i) OLD_IFS=$IFS IFS="\"" shift while [ $1 ]; do INPUT_IMAGE_FILES[CPT_IMG_FILE]=$1 CPT_IMG_FILE=`echo $(($CPT_IMG_FILE+1))` shift done IFS=$OLD_IFS ;; # MJPEGTools binary folder... -M) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi MJPEGTBINFOLDER=$1 IFS=$OLD_IFS ;; # ImageMagick binary folder... -I) OLD_IFS=$IFS IFS="\"" shift if [ -z $1 ]; then echo -e "Missing parameter after '$OPTIONMESSAGE' option !" exit -1 fi IMBINFOLDER=$1 IFS=$OLD_IFS ;; # Help... -h | --help) cat << EOF IMAGES2MPG [KIPI Project] - MPEG portfolio images multiplexer. Usage: images2mpg [options] -o -i Options: -v : verbose level [0:none=default, 1:infos+warnings, 2:debug]. --with-gui : running with 'KIPI' KDE GUI frontend [see http://extragear.kde.org/apps/kipi]. -t : enable transition between images with the speed [1=slow, 2, 4, 5, 10, 20=fast]. -T : use a specific folder for creating the temporary files (ex: '/tmp'). -f