E Chalaron wrote:
Hence the patch included in my previous email
E

Thanks for that E.  I am glad to have an opportunity to improve my script.

New script attached is now using find instead of ls *

It is also improved in a few other places (spaces in filenames work okay, error outputs properly suppressed).

Graham
#/bin/sh

#Create cinelerra style text file listing image paths for each frame

#this script can be called standalone or from within the animate script
#it takes three parameters: filetype (png or jpg) (default is to try and 
determine what file type is in the directory), framerate (default is 12) and 
directory to index (default is the directory from which the script is called)
#you probably need to make sure you choose a legitimate cinelerra frame rate 

#examples:

#animtext
#(this uses default framerate of 12, does its own checking of the filetype in 
the directory, and uses the current directory)
#
#animtext jpg 23.976 animations/sources/1/
#
#animtext jpg 30 /home/gray/animations/sources/2/

hd=`echo ~`

startdir=$PWD

if [ $1 ]
then
   filetype=$1
else
   #check png and jpgs
   #needs refinement as, for instance, .jng would be considered legitimate in 
this test 
   ls -1 $sourcedir | grep ".[pj][np][g]" > "${hd}"/animreadytemptext.txt
   #select the first that appears in any of those categories
   testfile=$(cat "${hd}"/animreadytemptext.txt | sed -n 1p)
   #run the imagemagick identifier to make sure of what it is
   test=`identify ${testfile}`
   if echo ${test} | grep JPEG -q
   then
      filetype=jpg
   elif echo ${test} | grep PNG -q
   then
      filetype=png
   fi
fi

mmv '*.jpeg' '#1.jpg' > /dev/null 2>&1
mmv '*..JPEG' '#1.jpg' >/dev/null 2>&1
mmv '*.PNG' '#1.png' >/dev/null 2>&1

#rename .jpeg .jpg * 2>/dev/null
#rename .JPEG .jpg * 2>/dev/null
#rename .PNG .png * 2>/dev/null
#following code fails now my distro doesn't support rename

filetype=$(echo $filetype | tr '[A-Z]' '[a-z]' | sed '+s+e++')

echo
echo 'This script will create a Cinelerra compliant text index of the 
'${filetype}' image files in the directory.  The index will be called 
'${filetype}'.txt and will be created in the same directory as the images 
themselves.  With cinelerra open up this text-index file to access the 
animation.  If you move the image files or the directory then you will need to 
recreate this index file.'
echo
if [ $1 ]
then
   echo 'Creating a text file listing the '${filetype}' files.'
else
   echo 'Creating a text file listing the '${filetype}' files. (Use 1st 
parameter to over-ride)'
fi
echo


if [ $2 ]
then
   framerate=$2
   echo 'Using framerate '${framerate}'.'
else
   framerate=12
   echo 'Default framerate of 12 will be used. (Use second parameter to 
specify).'
fi

echo

if [ $3 ]
then
   if [ ${3:0:1} = "/" ]
   then
   indexdir=${3}
   else
   indexdir=`echo $PWD`'/'${3}
   fi
   #add trailing backslash
   if [ ${indexdir:(-1)} = '/' ]
   then
   indexdir=${indexdir}
   else
   indexdir=${indexdir}'/'
   fi
   echo 'Indexing files in the '${indexdir}' directory.'
else
   indexdir=`echo $PWD'/'`
   echo 'Indexing files in the current directory.  (Use third parameter to 
override).'
fi


echo

#list filenames in correct order

cd "${indexdir}"

#ls -1 "'${indexdir}'"*.${filetype} > "${hd}"/animreadytemptext.txt
#ls -1 *.${filetype} > "${hd}"/animreadytemptext.txt
find -H . -name '*.'${filetype} -type f | sed '+s+\.\/++' |
sort > "${hd}"/animreadytemptext.txt

#
#in my case having thousands of frames
#makes the ls command in Graham script to fail...
#If you want to patch your scripts with the find line..
#it should work for any amount of files 
#(find . -name \* -type f | sort | xargs cat) | \
#pngtoy4m etc .... \ y4mtoqt -o reelname.mov 
#The issue with it is that it does double up the data at some point so #with 
about 100 GB for a 20 minutes movie I need 200 GB.. a bit of a #waste really. 
#Of course, ls * is a big no-no if you have 34000 files. ls . does the same.
#find -H . -name '*.jpg' -type f | sort



if [ "${filetype}" = jpg ]
then
  filetypeheader="JPEGLIST"
else
  filetypeheader="PNGLIST"
fi

#create filetype header

echo ${filetypeheader} > "${hd}"/animreadytemptext2.txt
echo `echo $filetypeheader | sed 'i# First line is always'` >> 
"${hd}"/animreadytemptext2.txt

echo "# Frame rate:" >> "${hd}"/animreadytemptext2.txt
echo ${framerate} >> "${hd}"/animreadytemptext2.txt

testfile=$(cat "${hd}"/animreadytemptext.txt | sed -n 1p)
#size=identify ${indexdir}${testfile}
size=`identify ${indexdir}${testfile}`

#create Width header
echo "# Width:" >> "${hd}"/animreadytemptext2.txt
identifyfiletype=$(echo -n $filetypeheader | sed '+s+LIST++')
width=`echo $size | sed '+s+.*'${identifyfiletype}' ++' | sed '+s+x.*++'`
echo $width >> "${hd}"/animreadytemptext2.txt

#create Height header
echo "# Height:" >> "${hd}"/animreadytemptext2.txt
if [ "${filetype}" = "png" ]
then
height=`echo ${size} | sed '+s+.*PNG [0-9]*x++' | sed '+s+ [0-9]*x[0-9]*.*++'`
else
height=`echo ${size} | sed '+s+.*JPEG [0-9]*x++' | sed '+s+DirectClass.*++'`
fi
echo $height >> "${hd}"/animreadytemptext2.txt

#create list of files with full paths

for f in `cat "${hd}"/animreadytemptext.txt | tr ' ' '@'`
do
   destfile=${indexdir}`echo ${f} | sed 's/@/ /g'`
   echo ${destfile} >> "${hd}"/animreadytemptext2.txt
done

#save the list and cleanup
filename=$(echo $filetype | tr '[A-Z]' '[a-z]')'list.txt'

mv "${hd}"/animreadytemptext2.txt "${indexdir}${filename}"

rm "${hd}"/animreadytemptext.txt

cd "${startdir}"

echo "Completed."
echo

Reply via email to