#!/bin/bash ## Anime Studio preview render nautilus script. ## version 0.3.2 (090120) ## Created by David Rylander, 2009, www.rylanderanimation.se ## Creative Commons Attribution-Share Alike 3.0 licenced (http://creativecommons.org/licenses/by-sa/3.0/) ## Dependencies of this script; Anime Studio Pro, FFmpeg, Sox. ##### Variables ##### mypath="`pwd`" #get current path. for filename in "$@" do origstartframe=$(grep frame_range "$mypath/$filename" | cut -d ' ' -f 2) origendframe=$(grep frame_range "$mypath/$filename" | cut -d ' ' -f 3) fps=$(grep fps "$mypath/$filename" | cut -d ' ' -f 2) fpsdecimal=`echo "1 / $fps" | bc -l` soundpath=$(grep soundtrack "$mypath/$filename" | cut -d ' ' -f 2 | sed 's/"//g') done #TODO, kolla om bara en fil är vald och om denna har .anme ändelse. Annars avbryt. ##### Create temp-folder ##### if [ ! -d preview-temp ] then mkdir preview-temp fi sleep 1 ##### User set custom frame range. ##### startframe=$(zenity --entry --text "startframe:" --entry-text $origstartframe); endframe=$(zenity --entry --text "endframe:" --entry-text $origendframe); ##### Render AS-file. ##### for filename in "$@" do /usr/local/bin/AnimeStudioPro_5.6/AnimeStudioPro -r "$mypath/$filename" -start $startframe -end $endframe -f PNG -halfsize yes -o $mypath/preview-temp/preview-render_.png done ##### Check if soundtrack exists where it should be. ##### for filename in "$@" do if [ -z $soundpath ]; then soundtrack="" elif [ -e $mypath/$soundpath ]; then soundtrack=$mypath/$soundpath elif [ -e $soundpath ]; then soundtrack=$soundpath else soundtrack="" #if we can't find the audio in specified path (i.e is windows path) fi done ##### Get length, padding and trimming. ##### for filename in "$@" do if [ $startframe = $origstartframe ]; then pad1=0 trim1=0 elif [ $startframe -gt $origstartframe ]; then startcrop=`echo "($startframe - $origstartframe) * $fpsdecimal" | bc -l` pad1=0 trim1=$startcrop elif [ $startframe -lt $origstartframe ]; then startpad=`echo "($origstartframe - $startframe) * $fpsdecimal" | bc -l` pad1=$startpad trim1=0 fi done audlength=`echo "($endframe - $startframe) * $fpsdecimal" | bc -l` for filename in "$@" do if [ $endframe = $origendframe ]; then pad2=0 trim2=$audlength elif [ $endframe -gt $origendframe ]; then endpad=`echo "($endframe - $origendframe) * $fpsdecimal" | bc -l` pad2=$endpad trim2=$audlength elif [ $endframe -lt $origendframe ]; then endcrop=`echo "($origendframe - $endframe) * $fpsdecimal" | bc -l` pad2=0 trim2=`echo "$audlength - $endcrop" | bc -l` fi done ##### Render audio ##### for filename in "$@" do if [ $soundtrack != "" ]; then sox $soundtrack $mypath/preview-temp/audio-temp.wav pad $pad1 $pad2 trim $trim1 $trim2 tempaudio="-i $mypath/preview-temp/audio-temp.wav" else tempaudio="" fi done ##### Renumber image sequence to start with #0001 ##### if [ ! -e $mypath/preview-temp/preview-render_0001.png ]; then cd $mypath/preview-temp/ sleep 1 #behövs lite paus annars missar omnumreringen filerna... ( for f in * do currprefix=${f%[0-9][0-9][0-9][0-9]*} test "x$prevprefix" = "x$currprefix" && ((i++)) || i=1 mv -i "$f" "${f/[0-9][0-9][0-9][0-9]/$(printf %04d $i)}" prevprefix=$currprefix done ) cd .. fi ##### Render image sequence and audio to video file. ##### ffmpeg -qmax 5 $tempaudio -i $mypath/preview-temp/preview-render_%04d.png -vcodec mpeg4 -r $fps -y preview-render.mp4 ##### Clean and make tidy. ##### rm -rf $mypath/preview-temp/ echo "Animation preview rendered!"| zenity --title AS-preview-render --text-info