set -e -u -o pipefail # convert src.bmp -distort SRT "xcenter ycenter scalefactor clockwiseangle" dst.bmp # e.g.: convert src.bmp -distort SRT "370 320 2 15" dst.bmp # 20 degrees not dramatic enough # 40 degrees too much # 35 somewhat silly but maybe ok on average function bmprot() { picwidth=$1 destdir=$2 framespeed=$3 xorigin=$(echo "scale=2; 390/960*$picwidth"|bc) yorigin=$(echo "scale=2; 410/960*$picwidth"|bc) x=0 for i in *.bmp; do # :( messed up, less rotation than intended with this lower fps because incremental rather than relative factor and angle factor=$(echo "scale=2; 1 + 0.06*$x*$framespeed"|bc) angle=$(echo "scale=2; 1.5*$x*$framespeed"|bc) convert $i -distort SRT "$xorigin $yorigin $factor $angle" ../$destdir/$i.bmp x=$((x+1)) done } function run1() { vidsrc=$1 startpos=$2 #duration=$3 endpos=$3 thresh=$4 turdsize=$5 rendersize=$6 zoom=${7:-} blur=$8 filter=$9 #slideshowrate=4.995 #slideshowrate=2.997 ifps=${10} slideshowrate=$(echo "scale=10; 29.97/$ifps"|bc) #actualrate=29.97 actualrate=30000/1001 # 960 gets less noisy than 4K # 29.97/2 = 14.985 # 29.97/6 = 4.995 LOWRES=960 # even less noisy? not helping much though and losing detail #LOWRES=480 # maybe this? #LOWRES=240 mkdir -p $vidsrc.out/src #ffmpeg -ss $startpos -t $duration -i $vidsrc -r $slideshowrate -vf scale=$LOWRES:-1 $vidsrc.out/src/frame%04d.bmp ffmpeg -ss $startpos -to $endpos -i $vidsrc -r $slideshowrate -vf scale=$LOWRES:-1 -debug_ts $vidsrc.out/src/frame%04d.bmp #exit 1 ffmpeg -y -ss $startpos -to $endpos -i $vidsrc -c copy $vidsrc.out/$vidsrc.origclip.mp4 cd $vidsrc.out # if too big. but fullhd result is ok #for i in *.bmp; do (mkbitmap -x -f 4 -s 2 -3 -t 0.47 $i -o bit/$i.pbm; mogrify -resize 50% bit/$i.pbm) & done # no need for this trickery with a clean environment if false; then mkdir -p masked cd src for i in *.bmp; do (composite mask.png $i ../masked/$i.bmp) & done wait cd .. else ln -sfn src masked fi if [ "$zoom" = "zoom" ]; then rm -rf masked mkdir -p masked cd src bmprot $LOWRES masked 1 cd .. # awful hack but this really is a corner case # only use with "nuppi" via the zoom flag if true; then mkdir -p origframes ffmpeg -i $vidsrc.origclip.mp4 -vf scale=1920:-1 origframes/frame%04d.bmp mkdir -p origrotation cd origframes bmprot 1920 origrotation "1/$ifps" cd .. ffmpeg -y -framerate $actualrate -pattern_type glob -i 'origrotation/*.bmp' -i $vidsrc.origclip.mp4 -c:v libx264 -map 0:0 -map 1:1 -r $actualrate -pix_fmt yuv420p $vidsrc.rotated.mp4 fi exit 1 fi mkdir -p bit cd masked # bigger filter, thicker lines but more squiggly for i in *.bmp; do (mkbitmap -x --blur $blur --filter $filter --scale 1 --cubic --threshold $thresh $i -o ../bit/$i.pbm) & done wait cd .. #echo "TEMP HACK"; return mkdir -p svg cd bit # debug border for engraving layout, might have to keep for i in *.pbm; do mogrify -shave 10x10 -bordercolor white -border 5 -bordercolor black -border 5 $i & done wait # --alphamax just makes the outer border a circle, no help with noise detail # can't see how --opttolerance would do much here # --unit doesn't do much, other than break completely when too bad (0.1) POT="potrace --alphamax 1.0 --opttolerance 0.2 --unit 10 --turdsize $turdsize --svg" # millimeters not good for ffmpeg, gets scaled badly if [ $PREVIEW = "y" ]; then for i in *.pbm; do $POT -o ../svg/$i.svg $i & done wait else for i in *.pbm; do $POT -o ../svg/$i.svg -W 90mm -H 50.625mm $i & done wait echo hello production cd ../.. return fi cd .. mkdir -p back #for i in *.svg; do convert $i -resize 3840x2160 ../back/$i.png & done cd svg #sed -i -e 's/stroke="none"/stroke-width="0.001in" stroke="black"/' *.svg for i in *.svg; do convert $i -resize $rendersize ../back/$i.png & done wait cd .. #ffmpeg -y -framerate $slideshowrate -pattern_type glob -i 'back/*.png' -c:v libx264 -r $actualrate -pix_fmt yuv420p out.mp4 ffmpeg -y -framerate $slideshowrate -pattern_type glob -i 'back/*.png' -i $vidsrc.origclip.mp4 -c:v libx264 -map 0:0 -map 1:1 -r $actualrate -pix_fmt yuv420p $vidsrc.out.mp4 cd .. } FRAMESTART=1 function run2() { vidsrc=$1 rendersize=$6 ifps=${10} #slideshowrate=$(echo "scale=10; 29.97/$ifps"|bc) slideshowrate=$(echo "30000/$ifps"|bc)/1001 actualrate=30000/1001 cd $vidsrc.out src="../../captured/jpg" clipframes=$(ls svg/*|wc -l) ls $src/*|tail -n+$FRAMESTART|tail -n$clipframes|sed s/^/"file "/ > photolist.txt mkdir -p cap cd cap ln -sfn $(ls -1 ../$src/*|tail -n+$FRAMESTART|head -n$clipframes) . cd .. set -x ffmpeg -y -framerate $slideshowrate \ -pattern_type glob -i 'cap/*.JPG' \ -vf scale=$rendersize \ -c:v libx264 -qp 0 -debug_ts -pix_fmt yuv420p $vidsrc.photos.mp4 set +x FRAMESTART=$((FRAMESTART+clipframes)) cd .. } # thresh closer to 0.5 makes the image more sensitive to lines, and to noise # or 3840x2160 for final render but this is easier for now res=1920x1080 PREVIEW="y" # y/n function run() { run1 "$@" } # testi #run IR7_0199.MP4 00:00:05 00:00:06 0.47 100 $res # pussista, onpa hankala. ehkä pois leipägraffasta #run IR7_0202.MP4 1 4 0.47 100 $res # # but FIXME: audio not in sync. frame-exact timecodes? # 1. lookup where this start lies regarding fps: convert to seconds, multiply by fps, convert back # 2. extract audio as-is from orig, video from these # 3. concat all # vid start end thresh trd res mode b f ifps #run IR7_0205.MP4 1:10.137 1:11.24 0.494 100 $res norm 3 5.5 10 # paahtimeen #run IR7_0206.MP4 40.2 43.1 0.494 400 $res zoom 3 4.5 10 # nuppi #run IR7_0207-1.MP4 3.6 4.7 0.494 400 $res norm 2 4.5 10 # vipu #run IR7_0207-2.MP4 2:2.35 2:3.0 0.494 500 $res norm 2.5 5.5 15 # pomp #run IR7_0208.MP4 3.3 4.3 0.492 800 $res norm 4 5.5 10 # paahtimesta #run IR7_0213.MP4 4.2 8.4 0.494 700 $res norm 6 5.5 20 # voiveitsi #run IR7_0214.MP4 2.3 4.3 0.490 200 $res norm 5 4.5 15 # heilutus run IR7_0205.MP4 1:10.137 1:11.271 0.494 100 $res norm 3 5.5 10 # paahtimeen run IR7_0206.MP4 40.174 43.11 0.494 400 $res zoom 3 4.5 10 # nuppi run IR7_0207-1.MP4 3.57 4.705 0.494 400 $res norm 2 4.5 10 # vipu run IR7_0207-2.MP4 2:2.322 2:3.023 0.494 500 $res norm 2.5 5.5 15 # pomp run IR7_0208.MP4 3.27 4.304 0.492 800 $res norm 4 5.5 10 # paahtimesta run IR7_0213.MP4 4.171 8.408 0.494 700 $res norm 6 5.5 20 # voiveitsi run IR7_0214.MP4 2.269 4.304 0.490 200 $res norm 5 4.5 15 # heilutus ## XXX those were without blur, does that affect turdsize? # 1. leipä pussista # 2. alkuperäinen video # 3. leipävideo, ehkä "glitch-fade" sisään # 4. lisää leipää pussista # 5. leipärender soi vähän nopeammin # 6. toistuu 4-5 kunnes ei enää leipää # 7. leipätallenneasetelma zoom out # 8. ei enää leipää pussissa -pätkä # 9. laserlaitepätkä