Friday, December 3, 2010

Bulk renaming files and animations

It is sometimes useful to bulk rename files and create animations.

I had 1000s of images that were in sequential order of the form ghrsst_YYMMDD_reg.tdf.reg.jpg that I needed to rename to img0001.jpg, img0002.jpg, etc.

To do so I did the following:
$ rename 's/_reg.tdf.reg.jpg/.jpg/' * # replace all the "_reg.tdf.jpg" with just ".jpg"
$ rename 's/ghrsst_/0/' *.jpg # replace all the "ghrsst_" with "0"
$ x=1; for i in *jpg; do counter=$(printf %07d $x); ln -s "$i" img"$counter".jpg; x=$(($x+1)); done

Then to make the animation from the linked files:
$ ffmpeg -f image2 -r 8 -i img%07d.jpg -b 8000k -s 1920x1080 Ghrsst.mp4


This makes a nice high resolution animation of the jpg images you created.

See this link for the animation. WARNING: This animation is ~180 MB!!!

Cheers
Bjorn

No comments:

Post a Comment