Removed old files, added first forked version

This commit is contained in:
Jan Jastrow 2022-01-19 09:38:28 +01:00
parent 5c408595fc
commit 9a7df69c48
4 changed files with 57 additions and 201 deletions

View File

@ -1,74 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)+>
<!ELEMENT policy (#PCDATA)>
<!ATTLIST policy domain (delegate|coder|filter|path|resource) #IMPLIED>
<!ATTLIST policy name CDATA #IMPLIED>
<!ATTLIST policy rights CDATA #IMPLIED>
<!ATTLIST policy pattern CDATA #IMPLIED>
<!ATTLIST policy value CDATA #IMPLIED>
]>
<!--
Configure ImageMagick policies.
Domains include system, delegate, coder, filter, path, or resource.
Rights include none, read, write, and execute. Use | to combine them,
for example: "read | write" to permit read from, or write to, a path.
Use a glob expression as a pattern.
Suppose we do not want users to process MPEG video images:
<policy domain="delegate" rights="none" pattern="mpeg:decode" />
Here we do not want users reading images from HTTP:
<policy domain="coder" rights="none" pattern="HTTP" />
Lets prevent users from executing any image filters:
<policy domain="filter" rights="none" pattern="*" />
The /repository file system is restricted to read only. We use a glob
expression to match all paths that start with /repository:
<policy domain="path" rights="read" pattern="/repository/*" />
Any large image is cached to disk rather than memory:
<policy domain="resource" name="area" value="1GB"/>
Define arguments for the memory, map, area, and disk resources with
SI prefixes (.e.g 100MB). In addition, resource policies are maximums for
each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB
exceeds policy maximum so memory limit is 1GB).
-->
<policymap>
<!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
<!-- <policy domain="resource" name="memory" value="2GiB"/> -->
<!-- <policy domain="resource" name="map" value="4GiB"/> -->
<!-- <policy domain="resource" name="area" value="1GB"/> -->
<!-- <policy domain="resource" name="disk" value="16EB"/> -->
<!-- <policy domain="resource" name="file" value="768"/> -->
<!-- <policy domain="resource" name="thread" value="4"/> -->
<!-- <policy domain="resource" name="throttle" value="0"/> -->
<!-- <policy domain="resource" name="time" value="3600"/> -->
<!-- <policy domain="system" name="precision" value="6"/> -->
<!--policy domain="cache" name="shared-secret" value="passphrase"/>
<policy domain="coder" rights="none" pattern="EPHEMERAL" />
<policy domain="coder" rights="none" pattern="URL" />
<policy domain="coder" rights="none" pattern="HTTPS" />
<policy domain="coder" rights="none" pattern="MVG" />
<policy domain="coder" rights="none" pattern="MSL" />
<policy domain="coder" rights="none" pattern="TEXT" />
<policy domain="coder" rights="none" pattern="SHOW" />
<policy domain="coder" rights="none" pattern="WIN" />
<policy domain="coder" rights="none" pattern="PLT" />
<policy domain="path" rights="none" pattern="@*" />
< disable ghostscript format types -->
<!--policy domain="coder" rights="none" pattern="PS" />
<policy domain="coder" rights="none" pattern="EPS" />
<policy domain="coder" rights="none" pattern="PDF" />
<policy domain="coder" rights="none" pattern="XPS" />-->
</policymap>

72
th.sh
View File

@ -1,72 +0,0 @@
#!/bin/bash
#
#
# Dependencies/Requirements:
# 1. ffmpeg
# 2. ImageMagick with modified policy.xml (avaliable on this git)
#
# Usage:
# . th.sh COLUMNS ROWS SIZE INPUT
#
# 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;
#
# Example:
# . th.sh 3 14 1920 video.mp4
if [[ $# != 4 ]]; then
echo "wrong number of arguments
Usage:
. 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;
OUTPUT is the path to the output file (make sure intermediate directories
exist).
Example:
. th.sh 3 14 1920 video.mp4
"
return 1
fi
NFRAMES=$(echo "scale=0;$1*$2" | bc)
TILE=$(echo "$1x$2")
SIZE=$3
INPUT=$4
DURX=$(ffmpeg -i "$4" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
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] }')
RES=$(ffmpeg -i "$4" 2>&1 | grep -oP 'Stream .*, \K[0-9]+x[0-9]+')
FILESIZE=$(du -sm "$4" | awk '{print $1}')
TMPDIR=/tmp/thumbnails-${RANDOM}/
mkdir $TMPDIR
for (( VARIABLE=0; VARIABLE<NFRAMES; VARIABLE++ ))
do
OFFSET=$(echo "scale=2;$VARIABLE*$DURATION/$NFRAMES+$DURATION/$NFRAMES/2" | bc)
if [ $VARIABLE -gt 9 ];then
ZEROS="00"
if [ $VARIABLE -gt 99 ];then
ZEROS="0"
if [ $VARIABLE -gt 999 ];then
ZEROS=""
fi
fi
else
ZEROS="000"
fi
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
montage ${TMPDIR}*.jpg -background white -geometry +5+5 -tile $TILE ${TMPDIR}output.jpg
echo $4 >>${TMPDIR}myfile.txt
echo $RES >>${TMPDIR}myfile.txt
echo "$FILESIZE Mb" >>${TMPDIR}myfile.txt
echo $DURX >>${TMPDIR}myfile.txt
convert -size ${SIZE}x150 -fill black -interline-spacing 10 -background white -pointsize 20 -gravity west caption:@${TMPDIR}myfile.txt ${TMPDIR}text1.jpg
convert ${TMPDIR}output.jpg -resize ${SIZE}x${SIZE} ${TMPDIR}th.jpg
thewidth=$(identify -ping -format %w ${TMPDIR}th.jpg)
convert ${TMPDIR}text1.jpg -crop ${thewidth}x150+0+0 ${TMPDIR}text.jpg
montage ${TMPDIR}text.jpg ${TMPDIR}th.jpg -background white -geometry +0+0 -tile 1x2 thumbnails-${RANDOM}.jpg

View File

@ -1,52 +1,38 @@
#!/bin/bash
#
#
# Dependencies/Requirements:
# 1. ffmpeg
# ImageMagick dependence is REMOVED
#
# Usage:
# . th.sh COLUMNS ROWS SIZE INPUT
#
# 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;
#
# Example:
# . th.sh 3 14 1920 video.mp4
if [[ $# != 4 ]]; then
echo "wrong number of arguments
Usage:
. 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;
OUTPUT is the path to the output file (make sure intermediate directories
exist).
Example:
. th.sh 3 14 1920 video.mp4
"
return 1
if [ -z "$1" ]; then
echo "usage: ./thumbgen.sh INPUT [COLUMNS=5] [ROWS=5] [SIZE=1600]"
exit
fi
NFRAMES=$(echo "scale=0;$1*$2" | bc)
TILE=$(echo "$1x$2")
SIZE=$3
INPUT=$4
DURX=$(ffmpeg -i "$4" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
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] }')
RES=$(ffmpeg -i "$4" 2>&1 | grep -oP 'Stream .*, \K[0-9]+x[0-9]+')
FILESIZE=$(du -sm "$4" | awk '{print $1}')
TMPDIR=/tmp/thumbnails-${RANDOM}/
# Define variables
INPUT=$1
COLUMNS=$2
if [ -z "$COLUMNS" ]; then
COLUMNS=5
fi
ROWS=$3
if [ -z "$ROWS" ]; then
ROWS=5
fi
SIZE=$4
if [ -z "$SIZE" ]; then
SIZE=1600
fi
NFRAMES=$(echo "scale=0;$COLUMNS*$ROWS" | bc)
DURX=$(ffmpeg -i "$INPUT" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
DURATION=$(ffmpeg -i "$INPUT" 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] }')
RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$INPUT")
FILESIZE=$(du -sm "$INPUT" | awk '{print $1}')
FONT="/System/Library/Fonts/Supplemental/PTMono.ttc"
METADATA_PX=90
TMPDIR="/tmp/thumbnails-${RANDOM}/"
mkdir $TMPDIR
for (( VARIABLE=0; VARIABLE<NFRAMES; VARIABLE++ ))
do
OFFSET=$(echo "scale=2;$VARIABLE*$DURATION/$NFRAMES+$DURATION/$NFRAMES/2" | bc)
if [ $VARIABLE -gt 9 ];then
ZEROS="00"
if [ $VARIABLE -gt 99 ];then
@ -56,18 +42,34 @@ if [ $VARIABLE -gt 9 ];then
fi
fi
else
ZEROS="000"
ZEROS="000"
fi
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.jpeg
# Create thumbnails
ffmpeg -start_at_zero -copyts -ss $OFFSET -i "$INPUT" -vf "drawtext=fontfile=$FONT:fontsize=45:fontcolor=white::shadowcolor=black:shadowx=2:shadowy=2:box=1:boxcolor=black@0:x=(W-tw)/40:y=H-th-20:text='%{pts\:gmtime\:0\:%H\\\\\\:%M\\\\\:%S}'" -vframes 1 ${TMPDIR}$ZEROS$VARIABLE.png
done
ffmpeg -pattern_type glob -i "${TMPDIR}*.jpeg" -filter_complex tile=$TILE:margin=4:padding=4:color=white ${TMPDIR}output.jpg
echo " $4" >>${TMPDIR}myfile.txt
echo " $RES" >>${TMPDIR}myfile.txt
echo " $FILESIZE Mb" >>${TMPDIR}myfile.txt
echo " $DURX" >>${TMPDIR}myfile.txt
thewidth=$(ffmpeg -i ${TMPDIR}output.jpg 2>&1 |grep Video|awk '{ split( $8, pieces, /[x,]/ ) ; print pieces[1] }')
theheight=$(ffmpeg -i ${TMPDIR}output.jpg 2>&1 |grep Video|awk '{ split( $8, pieces, /[x,]/ ) ; print pieces[2] }')
theheight=$(echo "scale=0;$theheight*$SIZE/$thewidth" | bc)
ffmpeg -i ${TMPDIR}output.jpg -vf scale=${SIZE}x${theheight} -vframes 1 ${TMPDIR}th.jpg
theheight=$(echo "$theheight+150" | bc)
ffmpeg -f lavfi -i color=white:${SIZE}x${theheight} -i ${TMPDIR}th.jpg -filter_complex "[0:v][1:v] overlay=0:150,drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:fontsize=20:fontcolor=black:x=30:y=20:textfile=${TMPDIR}myfile.txt" -vframes 1 th${RANDOM}.jpg
# Merge thumbnails into tile image
ffmpeg -pattern_type glob -i "${TMPDIR}*.png" -filter_complex tile=${COLUMNS}x${COLUMNS}:margin=4:padding=4:color=white ${TMPDIR}output.png
# Output metadata to file
echo "Filename: $INPUT" >>${TMPDIR}metadata.txt
echo "Resolution: $RES" >>${TMPDIR}metadata.txt
echo "Filesize: $FILESIZE Mb" >>${TMPDIR}metadata.txt
echo "Duration: $DURX" >>${TMPDIR}metadata.txt
# Get dimensions of tile image
thewidth=$(ffmpeg -i ${TMPDIR}output.png 2>&1 |grep Video|awk '{ split( $6, pieces, /[x,]/ ) ; print pieces[1] }')
theheight=$(ffmpeg -i ${TMPDIR}output.png 2>&1 |grep Video|awk '{ split( $6, pieces, /[x,]/ ) ; print pieces[2] }')
# Redefine height & scale (according to $SIZE)
scaledheight=$(echo "scale=0;$theheight*$SIZE/$thewidth" | bc)
ffmpeg -i ${TMPDIR}output.png -vf scale=${SIZE}x${scaledheight} -vframes 1 ${TMPDIR}th.png
# Add space to the top of the image
finalheight=$(echo "$scaledheight+$METADATA_PX" | bc)
# Add Metadata
ffmpeg -f lavfi -i color=black:${SIZE}x${finalheight} -i ${TMPDIR}th.png \
-filter_complex "[0:v][1:v] overlay=0:$METADATA_PX,drawtext=fontfile=$FONT:fontsize=20:fontcolor=white:x=10:y=10:textfile=${TMPDIR}metadata.txt" \
-vframes 1 th${RANDOM}.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 KiB