2

I'm finding it difficult to word my question in a way I can search for the answer, my problem is as follows.....

I have a webcam that takes a photo every 2mins and saves as a numbered file, the first photo is taken at 0000hrs and is named image001.jpg, at 0002hrs image002.jpg and so on. At 2359hrs all the photos are turned in to 24hr time lapse video and saved as daily_video.mov. At 0000hrs (of the next day) the old image001.jpg is over written and the whole process repeated including generation of a new daily_video.mov. This is all working fine with the webcam doing the file naming and overwriting, and a cron job running fffmpeg once a day to make the video.

What I want to do now is make a time lapse video over say a month by copying every 30th file from the days images to a new folder and naming in a sequential order. ie. Day 1; image030.jpg, image060.jpg, etc... are renamed to Archive001.jpg, Archive002.jpg,etc... But on day 2; image030.jpg, image060.jpg etc... Will need to be named to Archive025.jpg, Archive026.jpg etc.. and repeat untill the end of the month copying files from the day to a sequentially increasing in name list of files to use at the end of month, where the process can be repeated.

Does that make sense?!!

1 Answers1

1

You could use a bash script like the following. Just call it at 2359hrs. Remeber to make it executable using chmod +x myScript I did not rename to Archive00X.jpg, but by adding the current date, they will be in proper alphabetical order.

example output:

cp files/image000.jpg >> archive/image_2012-08-29_000.jpg
cp files/image030.jpg >> archive/image_2012-08-29_030.jpg
....
  • adapt pSource and pDest to your paths (preferrably absolute paths)
  • adapt offset and maxnum to your needs. If maxnum is too big it will tell you some files are missing, but otherwise work properly.
  • Remove the echo lines if they disturb you ;)

Code:

#!/bin/bash

pSource="files"
pDest="archive"

offset=30
maxnum=721

curdate=`date "+%F"`

function rename_stuff()
{
 myvar=0
 while [ $myvar -lt $maxnum ]
 do
    forg=`printf image%03d.jpg ${myvar}`
    fnew=`printf image_%s_%03d.jpg ${curdate} ${myvar}`

    forg="$pSource/$forg"
    fnew="$pDest/$fnew"

    if [ -f "$forg" ]; then
     echo "cp $forg >> $fnew"
     cp "$forg" "$fnew"
    else
     echo "missing file $forg"
    fi

    myvar=$(( $myvar + $offset ))
done
}

rename_stuff
Daniel S
  • 456
  • 4
  • 17
  • Thanks for taking the time to answer my question, using the solution above and the answer from: http://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-sequential-numbers I will beable to acheive what I need. thanks. – user1631710 Sep 08 '12 at 19:19