From d89876b6332426b17c726e9bddffb561fcee30d8 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Sun, 5 Jan 2025 00:41:14 +0100 Subject: [PATCH] refactoring the build system --- tools/README.md | 4 ++ tools/encode.sh | 14 ++++++ tools/fonctions.sh | 53 +++++++++++++++++++++ tools/linkfarmer.sh | 111 +++++++++++++++++++++++++++++++++++++++++++ tools/plot-timing.sh | 56 ++++++++++++++++++++++ 5 files changed, 238 insertions(+) create mode 100644 tools/README.md create mode 100755 tools/encode.sh create mode 100644 tools/fonctions.sh create mode 100755 tools/linkfarmer.sh create mode 100755 tools/plot-timing.sh diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..f479a6d --- /dev/null +++ b/tools/README.md @@ -0,0 +1,4 @@ +# Tools + +Build system and utilities. + diff --git a/tools/encode.sh b/tools/encode.sh new file mode 100755 index 0000000..c3b7314 --- /dev/null +++ b/tools/encode.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e ; set -u + +if [ $# == 1 ] +then + srcdir=$1 +else + srcdir="essai" +fi + +source tools/fonctions.sh + +ff_encodage $srcdir wip.mp4 diff --git a/tools/fonctions.sh b/tools/fonctions.sh new file mode 100644 index 0000000..03967dc --- /dev/null +++ b/tools/fonctions.sh @@ -0,0 +1,53 @@ + +set -eu + +# -------------------------------------------------------------- +ralentisseur () +{ +temps=$1 + +load=$(awk '{print int($1)}' < /proc/loadavg) +# echo " load is $load" | tee -a WS/log +if [ $load -gt 10 ] ; then + attente=$(( $temps + ($RANDOM % 90) )) + echo "ralentir $0 $SEQNAME $attente" # | tee -a WS/log + sleep $attente +fi +} + +# -------------------------------------------------------------- + +ff_encodage() +{ +SRCDIR="$1" +FILMNAME="$2" + +echo "Encoding $SRCDIR to $FILMNAME" | tee -a WS/log +ffmpeg -nostdin \ + -y -r 30 -f image2 -i frames/${SRCDIR}/%05d.png \ + -metadata artist='--[ tTh ]--' \ + -metadata title='-- HexaCone --' \ + -c:v libx264 \ + -pix_fmt yuv420p \ + -tune film \ + $FILMNAME + +# wc -c $FILMNAME | tee -a WS/log +} +# -------------------------------------------------------------- + +mp_encodage() +{ +# +# NOT WORKING ! +# +mencoder 'mf://frames/*.png' \ + -mf \ + fps=24 \ + -ovc lavc \ + -lavcopts vcodec=mpeg4 \ + -o output.avi +} + +# -------------------------------------------------------------- +# -------------------------------------------------------------- diff --git a/tools/linkfarmer.sh b/tools/linkfarmer.sh new file mode 100755 index 0000000..6e2b9b0 --- /dev/null +++ b/tools/linkfarmer.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +set -e ; set -u + +IDX=0 +SPOOL="frames/Spool" +SEQNAME="none" +TMP="WS/tmp.png" + +source tools/fonctions.sh + +# ------------------------------------------------------- +# /!\ this function just copy the +# file to the spool dir, so +# you can use it for tmp pics. +# +addfile () +{ +src="$1" +dstname=$(printf "%s/%05d.png" $SPOOL $IDX) +# echo "$src -> $dstname" +# ln --force --symbolic $src $dstname +cp -f $src $dstname +IDX=$(( IDX + 1 )) +} +# ------------------------------------------------------- +linkfarm () +{ +SRC="frames/$1" +echo "linkfarm $SRC" | tee -a WS/log + +local NBRE=30 +for foo in $(seq 0 $NBRE) +do + addfile "$SRC/00000.png" +done + +for src in "$SRC"/* +do + addfile $src +done + +for foo in $(seq 0 $NBRE) +do + addfile "$SRC/00359.png" +done +sync +} +# ------------------------------------------------------- +faire_le_titre () +{ +echo "faire le titre" + +local NBRE=190 +for foo in $(seq 0 $NBRE) +do + Ypos=$(( 500 - ( foo / 2 ) )) + convert "WS/negatif.png" \ + -gravity north \ + -font Courier-Bold \ + -pointsize 96 \ + -fill white \ + -annotate +0+${Ypos} "HexaCone(s)" \ + ${TMP} + # identify ${TMP} + addfile ${TMP} +done +} +# ------------------------------------------------------- +faire_la_fin () +{ +local NBRE=120 +for foo in $(seq 0 $NBRE) +do + Ypos=$(( foo + 100 )) + convert "WS/negatif.png" \ + -gravity north \ + -font Courier-Bold \ + -pointsize 48 \ + -fill white \ + -strokewidth 2 -stroke gray30 \ + -annotate +0+${Ypos} \ + "tTh des Bourtoulots\n2025" \ + ${TMP} + # identify ${TMP} + addfile ${TMP} +done +} +# ------------------------------------------------------- + +rm frames/Spool/*.png + +tools/plot-timing.sh +faire_le_titre + +linkfarm hexabenz +linkfarm orbite +linkfarm topview +linkfarm passage +linkfarm scene +linkfarm essai + +tools/plot-timing.sh +faire_la_fin + +ff_encodage Spool full.mp4 + + + + + diff --git a/tools/plot-timing.sh b/tools/plot-timing.sh new file mode 100755 index 0000000..6b59da4 --- /dev/null +++ b/tools/plot-timing.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +set -ue + +TMPFILE="/dev/shm/plot-timing.tmp" +IMAGE="timing.png" + +echo ; figlet "plot timing" ; echo +wc WS/mp4.timing | tee -a WS/log + +grep "passage" WS/mp4.timing | awk ' \ +BEGIN { \ + nbrames=360; \ + for (foo=0; foo $3) mini[$2] = $3; \ + if (maxi[$2] < $3) maxi[$2] = $3; \ + } \ + \ +END { \ + for (foo=0; foo 0) { \ + mean = accu[foo] / count[foo]; \ + printf "%4d %4f %4d %4d\n", foo, mean, \ + mini[foo], maxi[foo]; \ + } \ + } \ + } \ +' > $TMPFILE + +# cat -n $TMPFILE | tail # ; exit + +gnuplot << __EOC__ + set term png size 1024,768 + set output "timing.png" + set grid + set xrange [:360] + set yrange [0:] + set title "HexaCone : temps de rendu" + set xlabel "numéro de la trame" + set ylabel "temps en secondes" + plot "/dev/shm/plot-timing.tmp" u 1:4 w l t "maximum", \ + "/dev/shm/plot-timing.tmp" u 1:3 w l t "minimum", \ + "/dev/shm/plot-timing.tmp" u 1:2 w l t "moyenne", +__EOC__ + +convert -negate $IMAGE WS/negatif.png +