mirror of
https://github.com/JanJastrow/ViThumbs.git
synced 2024-11-23 15:49:55 +01:00
Update th.sh
This commit is contained in:
parent
cc30ec41fa
commit
1120487207
26
th.sh
26
th.sh
@ -22,7 +22,7 @@ if [[ $# != 4 ]]; then
|
|||||||
echo "wrong number of arguments
|
echo "wrong number of arguments
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
./thumbnails.sh NFRAMES TILE SIZE INPUT
|
. th.sh NFRAMES TILE SIZE INPUT
|
||||||
|
|
||||||
NFRAMES is the number of frames (thumbnails) to generate, e.g., 16;
|
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;
|
TILE is in the form 'MxN' (where M * N should match NFRAMES), e.g., 4x4;
|
||||||
@ -37,27 +37,28 @@ Example:
|
|||||||
"
|
"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
#ffmpeg -start_at_zero -copyts -ss 00:00:14 -i Rammstein\ -\ Radio.mp4 -vf "drawtext=fontfile=/path/to/Arial.ttf:fontsize=45:fontcolor=yellow:box=1:boxcolor=black:x=(W-tw)/2:y=H-th-10:text='%{pts\:gmtime\:0\:%H\\\\\\:%M\\\\\:%S}'" -vframes 1 output.png
|
|
||||||
|
|
||||||
NFRAMES=$1
|
NFRAMES=$1
|
||||||
TILE=$2
|
TILE=$2
|
||||||
SIZE=$3
|
SIZE=$3
|
||||||
INPUT=$4
|
INPUT=$4
|
||||||
|
#duration in h:m:s for caption
|
||||||
#DURATION=$(ffprobe -loglevel error -show_streams "$4" | grep duration= | cut -f2 -d= | head -1)
|
|
||||||
DURX=$(ffmpeg -i "$4" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
|
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] }')
|
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]+')
|
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}')
|
FILESIZE=$(du -sm "$4" | awk '{print $1}')
|
||||||
# generate thumbnails in the /tmp folder
|
# generate thumbnails in the /tmp folder
|
||||||
TMPDIR=/tmp/thumbnails-${RANDOM}/
|
TMPDIR=/tmp/thumbnails-${RANDOM}/
|
||||||
mkdir $TMPDIR
|
mkdir $TMPDIR
|
||||||
#filame
|
|
||||||
|
|
||||||
for (( VARIABLE=0; VARIABLE<NFRAMES; VARIABLE++ ))
|
for (( VARIABLE=0; VARIABLE<NFRAMES; VARIABLE++ ))
|
||||||
do
|
do
|
||||||
|
#time at which next snapshot is taken and avoiding blank last snapshot: seconds.xx
|
||||||
OFFSET=$(echo "scale=2;$VARIABLE*$DURATION/$NFRAMES+$DURATION/$NFRAMES/2" | bc)
|
OFFSET=$(echo "scale=2;$VARIABLE*$DURATION/$NFRAMES+$DURATION/$NFRAMES/2" | bc)
|
||||||
|
#how many zeros we add to temp file thumbnail: bla0009.jpp bla0099.jpg bla0999.jpg
|
||||||
if [ $VARIABLE -gt 9 ];then
|
if [ $VARIABLE -gt 9 ];then
|
||||||
ZEROS="00"
|
ZEROS="00"
|
||||||
if [ $VARIABLE -gt 99 ];then
|
if [ $VARIABLE -gt 99 ];then
|
||||||
@ -69,22 +70,21 @@ if [ $VARIABLE -gt 9 ];then
|
|||||||
else
|
else
|
||||||
ZEROS="000"
|
ZEROS="000"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#ffmpeg -start_at_zero -copyts -ss $OFFSET -i "$4" -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:fontsize=45:fontcolor=yellow:box=1:boxcolor=black:x=(W-tw)/2:y=H-th-10:text='%{pts\:gmtime\:0\:%H\\\\\\:%M\\\\\:%S}'" -vframes 1 ${TMPDIR}$ZEROS$VARIABLE.jpg
|
|
||||||
ffmpeg -start_at_zero -copyts -ss $OFFSET -i "$4" -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:fontsize=45:fontcolor=white::shadowcolor=black:shadowx=2:shadowy=2:box=1:boxcolor=black@0:x=(W-tw)/40:y=H-th-10:text='%{pts\:gmtime\:0\:%H\\\\\\:%M\\\\\:%S}'" -vframes 1 ${TMPDIR}$ZEROS$VARIABLE.jpg
|
ffmpeg -start_at_zero -copyts -ss $OFFSET -i "$4" -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:fontsize=45:fontcolor=white::shadowcolor=black:shadowx=2:shadowy=2:box=1:boxcolor=black@0:x=(W-tw)/40:y=H-th-10:text='%{pts\:gmtime\:0\:%H\\\\\\:%M\\\\\:%S}'" -vframes 1 ${TMPDIR}$ZEROS$VARIABLE.jpg
|
||||||
done
|
done
|
||||||
|
#combine thumbnails together
|
||||||
montage ${TMPDIR}*.jpg -background white -geometry +5+5 -tile $TILE ${TMPDIR}output.jpg
|
montage ${TMPDIR}*.jpg -background white -geometry +5+5 -tile $TILE ${TMPDIR}output.jpg
|
||||||
|
#put info about video in textfile
|
||||||
echo $4 >>${TMPDIR}myfile.txt
|
echo $4 >>${TMPDIR}myfile.txt
|
||||||
echo $RES >>${TMPDIR}myfile.txt
|
echo $RES >>${TMPDIR}myfile.txt
|
||||||
echo "$FILESIZE Mb" >>${TMPDIR}myfile.txt
|
echo "$FILESIZE Mb" >>${TMPDIR}myfile.txt
|
||||||
echo $DURX >>${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
|
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
|
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)
|
thewidth=$(identify -ping -format %w ${TMPDIR}th.jpg)
|
||||||
convert ${TMPDIR}text1.jpg -crop ${thewidth}x150+0+0 ${TMPDIR}text.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
|
montage ${TMPDIR}text.jpg ${TMPDIR}th.jpg -background white -geometry +0+0 -tile 1x2 thumbnails-${RANDOM}.jpg
|
||||||
|
Loading…
Reference in New Issue
Block a user