diff --git a/th.sh b/th.sh index 6b3e62f..1044e15 100644 --- a/th.sh +++ b/th.sh @@ -6,26 +6,23 @@ # 2. ImageMagick with modified policy.xml (avaliable on this git) # # Usage: -# ./th.sh NFRAMES TILE SIZE INPUT +# . th.sh COLUMNS ROWS SIZE INPUT # -# NFRAMES is the number of frames (thumbnails) to generate, e.g., 16; -# TILE is in the form "MxN" (where M * N should match NFRAMES), e.g., 4x4; +# COLUMNS means number of columns; +# ROWS means nubler of rows; # SIZE is the length of the longer side of the output, e.g., 1920 if you want # to get an 1920*1080 output image; # INPUT is the path to the input file; -# OUTPUT is the path to the output file (make sure intermediate directories -# exist). # # Example: -# . th.sh 16 4x4 1920 video.mp4 +# . th.sh 3 14 1920 video.mp4 if [[ $# != 4 ]]; then echo "wrong number of arguments Usage: -. th.sh NFRAMES TILE SIZE INPUT - -NFRAMES is the number of frames (thumbnails) to generate, e.g., 16; -TILE is in the form 'MxN' (where M * N should match NFRAMES), e.g., 4x4; +. th.sh COLUMNS ROWS SIZE INPUT +COLUMNS means number of columns;TILE is in the form 'MxN' (where M * N should match NFRAMES), e.g., 4x4; +ROWS means nubler of rows; SIZE is the length of the longer side of the output, e.g., 1920 if you want to get an 1920*1080 output image; INPUT is the path to the input file; @@ -33,32 +30,23 @@ OUTPUT is the path to the output file (make sure intermediate directories exist). Example: -. th.sh 16 4x4 1920 video.mp4 +. th.sh 3 14 1920 video.mp4 " return 1 fi - -NFRAMES=$1 -TILE=$2 +NFRAMES=$(echo "scale=0;$1*$2" | bc) +TILE=$(echo "$1x$2") SIZE=$3 INPUT=$4 -#duration in h:m:s for caption DURX=$(ffmpeg -i "$4" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,) -#duraion in seconds for thumnail generatin DURATION=$(ffmpeg -i "$4" 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }') -#resolution of video for caption RES=$(ffmpeg -i "$4" 2>&1 | grep -oP 'Stream .*, \K[0-9]+x[0-9]+') -#filesize in Mb for catopn FILESIZE=$(du -sm "$4" | awk '{print $1}') -# generate thumbnails in the /tmp folder TMPDIR=/tmp/thumbnails-${RANDOM}/ mkdir $TMPDIR - for (( VARIABLE=0; VARIABLE>${TMPDIR}myfile.txt echo $RES >>${TMPDIR}myfile.txt echo "$FILESIZE Mb" >>${TMPDIR}myfile.txt echo $DURX >>${TMPDIR}myfile.txt -#convert textfile in jpg, NB modified policy.xml is needed convert -size ${SIZE}x150 -fill black -interline-spacing 10 -background white -pointsize 20 -gravity west caption:@${TMPDIR}myfile.txt ${TMPDIR}text1.jpg -#resize combined thumbnails convert ${TMPDIR}output.jpg -resize ${SIZE}x${SIZE} ${TMPDIR}th.jpg -#resize info's width to match combined thumbnails thewidth=$(identify -ping -format %w ${TMPDIR}th.jpg) convert ${TMPDIR}text1.jpg -crop ${thewidth}x150+0+0 ${TMPDIR}text.jpg -#combine info and thumbnails into output file montage ${TMPDIR}text.jpg ${TMPDIR}th.jpg -background white -geometry +0+0 -tile 1x2 thumbnails-${RANDOM}.jpg