Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/bash
- #default parameters
- tiles=19
- endPos=-5;
- startPos=5;
- tempDir=/tmp;
- oFileName=\${in}_preview.jpg;
- deleteIntermidiate=true;
- previewFile=true;
- if [[ $# == 0 ]]; then
- echo "movie snapshot creator, by Tsahee Zidenberg"
- echo "usage: $0 [options] <filenames> [new options] <new filenames>"
- echo " options:"
- echo " -b (Begin) first shot to take [$startPos]"
- echo " -e (End) last shot to take [$startPos]"
- echo " negative values count from end of file"
- echo " -n Number of shots [$tiles]"
- echo " -t Temporary dir to use [$tempDir]"
- echo " -o Output filename [$oFileName]"
- echo " \\\${in} for input filename"
- echo " -p Preview with eye of gnome [default behaviour]"
- echo " -NP No preview"
- echo " -D Don't delete intermidiate Files"
- echo "Time is always in seconds"
- echo "requires: mplayer, ImageMagick (convert, montage)"
- exit 1
- fi
- #input variable: integer, number of secounds
- #ouput: time as h:mm:ss
- printTime(){
- local hr min sec
- (( hr = ($1 +0) / 3600 ))
- (( min = ($1 +0 - hr*3600) / 60 ))
- (( sec = ($1 +0) % 60 ))
- if (( sec < 10 )); then
- sec=0$sec
- fi
- if (( min < 10 )); then
- min=0$min
- fi
- echo $hr:$min:$sec
- }
- processFile() {
- inputFile=$1;
- echo "Processing $inputFile:"
- #reading attributes from the file
- #
- fileAttributes=(`mplayer -identify -frames 0 -vo null -ao null $inputFile 2>/dev/null \
- | grep -e ID_LENGTH -e ID_VIDEO_WIDTH -e ID_VIDEO_HEIGHT -e ID_VIDEO_FORMAT \
- | sort | cut -d"=" -f2 | cut -d"." -f1`)
- fileLength=${fileAttributes[0]}
- fileVideoFormat=${fileAttributes[1]}
- fileVideoSize=${fileAttributes[2]}x${fileAttributes[3]}
- inputFileDir=`dirname "$inputFile"`
- inputFileDir=`cd "$inputFileDir"; pwd`
- #save directory and move to /tmp
- cd "$tempDir"
- #creating the title tile
- #
- curTile="tmp_${inputFile}_tile_title.jpg"
- rm -f $curTile
- time=$(printTime $fileLength)
- convert -size 200x200 xc:white -pointsize 16 -draw "text 0,30 ${inputFile}" -draw "text 0,60 \"$time\"" \
- -draw "text 0,90 \"${fileVideoSize}\"" -draw "text 0,120 \"${fileVideoFormat}\"" $curTile
- tileList[0]="$tempDir/$curTile"
- tileNLabelList[0]="$tempDir/$curTile"
- #preparations for the loop
- if (( endPos <= 0 )); then
- (( lastPos = fileLength + endPos ))
- else
- (( lastPos = endPos ))
- fi
- (( jump = (lastPos - startPos) / (tiles-1) ))
- curTileNo=1
- curPos=$startPos
- rm -f 00000001.jpg
- while (( curTileNo <= tiles )); do
- mplayer -frames 1 -ss $curPos -vo jpeg -ao null "$inputFileDir/$inputFile" -quiet >/dev/null 2>/dev/null
- curTile="tmp_${inputFile}_tile_${curTileNo}.jpg"
- mv -f 00000001.jpg "$curTile"
- tileList[$curTileNo]="$tempDir/$curTile"
- tileNLabelList[((curTileNo*3))]="-label"
- tileNLabelList[((curTileNo*3+1))]="$(printTime $curPos)"
- tileNLabelList[((curTileNo*3+2))]="$tempDir/$curTile"
- echo " $curTileNo/$tiles"
- (( curTileNo++ ))
- if (( curTileNo == tiles )); then
- curPos=$lastPos
- else
- (( curPos += jump ))
- fi
- done
- echo "joining tiles.."
- #change back to the original directory
- cd "$workingDir"
- #create the final image
- outFile=`in=$inputFile;eval echo $oFileName`
- rm -f "$outFile"
- montage "${tileNLabelList[@]}" "$outFile"
- if [[ $previewFile == true ]]; then
- eog "$outFile" &
- fi
- #remove temporary files
- if [[ $deleteIntermidiate == true ]]; then
- rm -f "${tileList[@]}"
- fi
- }
- workingDir=`pwd`
- while (( "$#" )); do
- if [[ -f "$1" ]]; then
- processFile "$1"
- shift 1
- elif [[ "$1" == "-p" ]]; then
- previewFile=true;
- shift 1
- elif [[ "$1" == "-NP" ]]; then
- previewFile=false;
- shift 1
- elif [[ "$1" == "-n" ]]; then
- (( tiles = $2 +0 ))
- shift 2
- elif [[ "$1" == "-b" ]]; then
- (( startPos = $2 +0 ))
- shift 2;
- elif [[ "$1" == "-e" ]]; then
- (( endPos = $2 +0 ))
- shift 2;
- elif [[ "$1" == "-t" ]]; then
- tmpDir="$2";
- if [[ ! -d tmpDir ]]; then
- echo "Not a directory: $2"
- exit -1;
- fi
- shift 2
- elif [[ "$1" == "-o" ]]; then
- oFileName="$2"
- shift 2
- elif [[ "$1" == "-D" ]]; then
- deleteIntermidiate=false;
- shift 1
- else
- echo "bad parameter: $1"
- echo "use: $0 with no parameters for help"
- exit -1
- fi
- done
Add Comment
Please, Sign In to add comment