Do you know where your variables are? | |
PerlMonks |
Time for Some Movie Magickby abitkin (Monk) |
on Oct 14, 2004 at 14:12 UTC ( [id://399213]=CUFP: print w/replies, xml ) | Need Help?? |
Background:
So, let's say there's a webcam out there, with pictures taken at regular intervals. No, not that type of webcam, I'm talking about one of outdoors, so you can see what's happening outside your little cube. Now staring and refreshing at that little image 24/7/365 isn't really your cup of tea. I mean, shouldn't you use wget to grab the images for you? So suddenly, you have hundreds of images, but what good are they? I mean yeah, it's cool to say you have a record of them, but there must be a better use. After scratching your head for a while it dawns on you, what about an animated gif? I mean wouldn't that show you what was happening better than that little jpg you have? So after some digging you find image magick, and you start to conver these jpgs into an animated gif, when it hits you, animated gifs are bad. Too few colors, and compress jpgs to gif sucks. What's a developer to do? After a little more thought it dawns on you, that perhaps a movie would be a better format. After playing with image magick some more you find that it can convert jpgs into mpgs. Wonderful! So for a few days you convert everything into the same movie. Each time your cron job runs, it gets progressively longer. Finally, when it takes 72 minutes to run, you say enough. It's time to start searching for a better way. Perhaps if you just did smaller time increments. So with this new goal you start off on trying to make your scripts understand that an image only belongs to a day, and that you want movies of each day. Enter this cool use for perl. FYI: in this little trip down my train of thought, all the references to you are actually thoughts I had. This is the calling script that the cron job kicks off. It should download the images, and rename them to epoch seconds. Fifth, yes I know I shouldn't use system as I do, but in this particular case, I figured the chances of actually having this hole exploited was low, especially since I know the names of all the images before hand.
So now we get to the perl (finally.) Things you should note, first you should have write access to . Second, this uses a persistent data structure. Third, becuase of it's persistent data structure, it would be bad to have more than 1 copy running at the same time in the same path. Fourth, yes I know there can be a lot of time improvements, but those are minimal compared with the time it takes to run convert on 10+ images.
Feel free to comment away, suggest improvements, ect. One thing to note, mpgs can be catted together, thus reducing the time taken even more; however, I did discover a couple cases where the images were updated as wget was running, thus it missed an image, (which it filled in later using the kickoff script.) Also note, rsync commands can be added to the kickoff script to upload the movies automatically. The results of all this are here. == Kwyjibo. A big, dumb, balding North American ape. With no chin.
Back to
Cool Uses for Perl
|
|