Thursday, August 07, 2008

Script to reverse order of open documents in Photoshop

I am constantly scanning batches of documents into Photoshop and needed a way to reverse the order of the open documents. For example, I'm scanning 50 documents of a child growing up from age 0 to 20. I start with the baby picture and end with the picture of them at 20. When I'm done scanning I then want to save them in order, starting with 001.jpg as the youngest picture and 050.jpg as the oldest picture. Problem is, when I'm done scanning the active document is the oldest picture, and I often don't know exactly how many documents I've scanned, so I can't just start with 050.jpg and start counting down. If only I could reverse the order of the open documents - then I could start with 001.jpg and just end with whatever number of documents I scanned.

I used to do this by automating a save action and just saving all the documents and then reopening them. This worked OK because the documents were all Untitled-4, Untitled-5, etc, and I could open them in alphabetical order. But I thought that surely there must be a better way. I finally broke down and wrote a very simple vbscript to accomplish this task.

Here it is:
**************
'declare variables:
dim app
dim doc
dim arrDocs
dim strDocs

'set object reference to photoshop:
set app=createObject("Photoshop.Application")

'create a comma delimited string of all open photoshop documents:
for each doc in app.documents
strDocs=strDocs & doc.name & ","
next

'take off the last comma:
strDocs=left(strDocs,len(strDocs)-1)

'split the string into an array:
arrDocs=split(strDocs,",")

'iterate through the array in reverse order, making each document the active document as you go:
i=ubound(arrDocs)
do while i=>0
app.ActiveDocument=app.documents(arrDocs(i))
i=i-1
loop

'cleanup:
set app=nothing
*************************

Copy and paste the area between the asterisks into notepad, save it as reverseOrder.vbs, and double click it. Voila (assuming you have Photoshop open with all your documents open).

Your reason for wanting to reverse the order of open documents in Photoshop could be different, but at least this is a way to do it. I searched the web and couldn't find a way, so there you go. If there is a simple way, and I'm a moron for resorting to a script to accomplish something easily done another way, please let me know!

For more information on Photoshop scripting, refer to the Photoshop CS3 scripting guide, downloadable from Adobe, and maybe on your computer if you installed the content CD with the Master Collection (in my case, this is found in C:\Program Files\Adobe\Master Collection Content CD\Documentation\Scripting\Adobe Photoshop CS3)

Friday, May 09, 2008

From YouTube to Powerpoint

I get asked this question quite often: How can I take a video from YouTube (or some other video site) and put it in PowerPoint? Unfortunately, it's definitely not a drag and drop operation. These instructions are kind of long, but really not that difficult, and once you do it it's easy to figure it out. There are two basic ways to do it.
1 - Download the flv, get a flv player, associate flv files with the flv player, and link to the file in PowerPoint
2 - Download the flv, convert it to a wmv file, and insert it as a movie file in PowerPoint.

The latter is definitely preferable. So here are the instructions for both ways:
1 - Find the video on YouTube. Once you've located it, clear your browser cache. This isn't totally necessary, but makes the video easier to find. In Internet Explorer this is done via Tools -> Options -> Delete. If you're using IE and haven't done this for awhile (or ever) prepare to wait awhile while it clears the cache. I figure if you are using Firefox then you know how to do this.
2 - Load the video, or if you are already on the page with the video, refresh the page. Wait for the video to finish downloading - you don't need to play it all the way through (you can even pause it if you want) but let the red bar indicating how much it has downloaded progress all the way to the end.
3 - Once downloaded, go back to Tools -> Options and access your cache. If you are using Firefox, browse to your cache in windows explorer. In XP, this will be c:\Documents and Settings\[yourusername]\Local Settings\Application Data\Mozilla\Firefox\Profiles\[nameofyourprofile]\Cache. Make sure you are viewing protected operating system files or you won't see the necessary folders (in windows explorer: Tools -> Folder Options -> View -> UNcheck "Hide Protected Operating System Files"). The nameofyourprofile mentioned is probably the only folder listed, and probably ends in "default." Whether using IE or Firefox, sort the cache by size. The largest file is probably the video file you want, and for YouTube videos will likely start with "getVideo." Copy it to your computer somewhere, like your desktop, and rename it to MyVideo.flv (or whatever, as long as it ends in flv). You can also use Real Player to download the video easier than pulling it from your cache, but personally I hate Real Player, so I'm not going to encourage you to use it. There are also several web services out there that will create the flv for you to download if you give it the video ID, but why bother? It's easy enough to just get it from your cache.
4 - If you plan to convert it to a WMV to play inside PowerPoint, then go to step 5 - otherwise do step 4 and then you are done. If you are just going to link to the file in PowerPoint, then create a hyperlink in PowerPoint that points to the FLV file. You will need a FLV player installed on the computer that will be showing the PowerPoint. There are lots of them out there - Wimpy Flash Player is a good one - just a simple standalone exe (nothing to install). You do need to tell windows to use this program to open .flv files though - the easiest way to do this is just to double click the flv file, and when prompted, point Windows to "Wimpy FLV Player.exe" (wherever you put it) and make sure the box "Always use this program to open this kind of file" is checked.
5 - Again, there are lots of programs you could use to convert FLV to WMV. I recommend VLC Player from VideoLan. It's free (open source), and plays just about any kind of video or audio file, and can be used to convert from one type to the other. Download it and install it using the above link.
6 - Someone has already written instructions on how to use VLC to convert FLV to WMV, so I'm not going to reinvent the wheel, but let me know if the above link no longer works.
7 - Once converted to WMV, insert the file into PowerPoint as a movie file.

Please note that there are often copyright ramifications. Just because something is on YouTube doesn't mean that the person who put it there didn't violate copyright by putting it there in the first place.

Wednesday, April 30, 2008

Scripting JPGs to WMV to create Time Lapse videos

At my primary job I am responsible for 5 construction cameras that monitor a major downtown redevelopment project. These cameras provide video as well as take period snapshots, both of which can be accessed remotely via a web interface. The cameras are 4 Axis 232D+, and one Axis 233D. There's a ton I could write about this whole project, but I mainly wanted to document my current procedure for taking the JPG images and converting them to video files to be used in powerpoint, put on DVD, etc. I'm writing this for my own benefit and documentation, so things may be sketchy, feel free to ask me if you have any questions. This is a work in process...

These are PTZ cameras, and they are each programmed with 3-6 preset positions at which they take a still image, every half an hour from 8am to 6pm. That means that every half an hour I get still shots of about 20 different views. All of these views can be used to create time lapse videos. The powers that be would like a time lapse video of every sequence (or view) once per quarter. I use Adobe Premiere all the time, but it would be insane to try to accomplish this with that product - enter open source.

Ok, here is the basic workflow:

  1. Use windows find to get just the images I want. I'm using vista, so I can use advanced query syntax. The cameras take images every half an hour - for longer spanning time lapses I typically just want one picture per day. Because I want a certain time each day, I can't use date/time criteria for search, so I use the file name, which are all datetime stamped. Syntax for one per day:
    name:*16-0?-??-??.jpg

    syntax for range:
    name:*12-0?-??-??.jpg OR name:*13-0?-??-??.jpg OR name:*14-0?-??-??.jpg OR name:*15-0?-??-??.jpg OR name:*16-0?-??-??.jpg OR name:*17-0?-??-??.jpg OR name:*18-0?-??-??.jpg OR name:*19-0?-??-??.jpg OR

    The latter would give me all images at 12pm, 1,2,3,4,5,6,and 7pm. By the way, I use a vbs script to sort all the images the camera takes into folders for each camera, sequence, year, and quarter. Maybe I'll write about that part of it later.

  2. Once I've found the images I want, I process them with a utility called MakeAVI (http://sourceforge.net/projects/makeavi/). Two things I'd like to see in this program: drag and drop and command line scripting. I found some paid versions out there that do this, but I like free, and for the most part this program does the simple job it's programmed to do (a user on sourceforge actually took the source code and made it scriptable through a CLI, but neither the source or the binary for that is posted - I emailed to see if it was available). Because I can't drag from my search window into MakeAVI, I copy the files to an empty folder and then add the files from there. When using MakeAVI, I use the DivX encoder to compress the AVI files. Uncompressed takes longer and the file size is unnecessarily huge. I don't want to lose much quality, so my DivX settings are: Certification Profile: Home Theater Profile; Use presets to configure the encoder: checked; Rate control mode: 1 pass quality based; Target quantizer: 1; no other changes.

  3. Convert the DivX avi to a WMV file. Personally, I'd be happy with DivX, but these will be used in PowerPoint, so WMV is your best bet for compatability there. For this I use a slick little program called SUPER. It's basically a gui to a ton of different codecs and open source utilities. You can batch process, so I typically create all of my avi's first, then batch process them all to WMV. My settings in SUPER are: Output Container: WMV; Output Video Codec: WMV8; audio is disabled; Video Scale size: no change; aspect: no selection; Frame/Sec: 25; Bitrate: 4032 (quite high, I know, but I've found it needs to be at least this high to avoid blocky compression artifacts);Options: High Quality. SUPER is scriptable, so I may create a script to automatically process all my AVIs for me, but it's pretty easy to just add them manually and batch process them.


Other notes:
Because the files are all on a server on my network, it would be a pain to copy all the files locally that I needed. So I use offline files in Vista. Vista handles caching all the files locally, then when I want to process them I tell Vista to work offline. The when processing the images it uses the local copies.

I'm working on a script to automatically copy the appropriate images I need into various folders, all ready to be processed with MakeAVI, rather than having to do a windows search, and copy routine, like in step #1.

Saturday, December 22, 2007

Eliminating shaky frame holds

In a previous blog I mentioned I'd talk about getting good frame holds, so I'd better be true to my word. See my blog about getting good slow motion in Premiere for details on why frame holds can be shaky - I won't duplicate that here.

Shaky frame holds can be a sure sign of amateur work, but it's very easy to fix. The basic rule is this: ALWAYS deinterlace your frame hold clip (field options on the clip). It's now a still shot, so you don't need interlacing, and it can cause shakiness in any area of the frame where details differs from field to field (which is why someone's hand may be shaky in the frame hold when the rest is perfectly still). Some people prefer to simply export the frame and put the still .bmp or .tif on the timeline - that works too.

One other guideline - do not stretch out a frame hold clip by using speed - move the end point instead. Slowing it down too much (even though it's only one frame) can cause Premiere to do wierd things. If you're already at the end of your clip and need it to frame hold for more time, then repeat it - don't stretch the time. If you can't repeat it because you want a consistent zoom/pan across the entire frame hold, then put the individual clips in a separate sequence and then nest the sequence and zoom in on the sequence (which will be one "clip").

One other note - with CS3's time remapping feature, you can now gradually slow the footage down to a still, something I've longed to be able to do inside of Premiere for quite some time. Very cool. The deinterlacing rule still applies on the still frame.

Labels: ,

Monday, November 12, 2007

VOB Files and Adobe Premiere - Editing from DVD

I often find myself being given DVDs as source videos for a project. Whether it's creating a wedding video, a sports highlight film, a tribute video, or some other project, more and more people have their video footage on DVDs (only) these days. Obviously this is not a great situation for editing - the video file has already been compressed, so you've already lost quality to begin with. But the fact is that you have to work with what you've got.

You'd think that getting the files off the DVD to edit in Premiere (or the NLE of your choice) would be simple - copy the VOB files and drop them into Premiere. Oh that life were so simple. Premiere doesn't recognize VOB files. So you rename them to .MPG (or .AVI) and drop them into. That seems to work until you put one on the timeline and get no audio. If the DVD used AC3 as the audio track, then you'll have no audio because you can't bring an AC3 file into Premiere. I wish you could, but you can't - I think it's a copyright thing. Maybe you're lucky and the DVD you have was created using MPEG-1 Layer II as the audio. You drop it on the timeline and get audio but it just doesn't play back very well. Premiere stutters and playback is so bad it's unusable.

I've used a slew of tools to try to make this process easy on me and while there is no "Easy button" I've figured out something that works for me.

Enter VirtualDubMod. You can download it from sourceforge at:
http://sourceforge.net/project/showfiles.php?group_id=65889
Yeah, I know - it hasn't been updated forever, but it still works great. Sure it's not the most user friendly and pretty "open-source-ish" and to be honest I don't know what half of its features actually do, but it's a wonderful tool. The basic idea is that you open each VOB file and save it as an AVI. What? Render each file? That will take forever and gobs of hard disk space! Don't fret just yet, keep reading. (I'll talk using different tools to edit the compressed files later, but I prefer to edit with DV AVI files).

The first thing is getting the files off the DVD. Sure you can just copy them, and most of the time that works (for non-encrypted files) but sometimes it doesn't, you can get very weird results. For best results, I use another great little utility called DVDDecrypter. Its main purpose is really to break the Macrovision (or other) encryption on copyrighted DVDs and let you get at the video files. But that's a legal gray area, and that's not what I actually use it for. Most of the DVDs I'm given to use are not copy-protected. You can download DVDDecrypter from:
http://www.dvddecrypter.org.uk/

Ok, now you've got a bunch of .VOB files on your hard drive. It's time for VirtualDubMod. The first thing is that VirtualDubMod will create uncompressed AVI files. Many people think that's what they want, but actually it isn't. What you want (for optimal editing in Premiere) are DV AVI files, which VirtualDubMod doesn't make (out of the box). You have to get a DV AVI codec, which can be suprisingly hard to find. I use the Panasonic DV codec because it's free and you can download it from:
http://www.free-codecs.com/download/Panasonic_DV_Codec.htm
which also contains instructions on installing it. Once installed, it will show up as an available codec in VirtualDubMod (save as -> select AVI as the file type -> click change button -> select Panasonic DV Codec.) Now you can open the VOB file directly with VirtualDubMod and save it as a DV avi file and bring it into Premiere. Life's getting better (we're not done yet)!

Sometimes I have 10-12 DVDs of a whole football season and I need to make a highlight video. Sometimes the VOB files are little 5 minute clips on the DVD (depending on how it was created), so there are hundreds of VOB files. I don't want to open each one individually and click save as hundreds of times and wait for each file to transcode. Here's where VirtualDubMod gets cool. You can save that task for later, and then run them all at once with "Job Control." Ok, so that's better, but I still need to open the file (which takes a few seconds by itself), click save as, and give it a file name. That can still take forever. This brings me to the real reason I'm writing this article: scripting the VOB to AVI Job Control list for VirtualDubMod.

I wrote a little vbs utility (I know, you PHP and perl gurus out there are gagging) to search through a directory structure, find all the VOB files, and create a job control script that can be opened in VDubMod. (download link below) Ok, now your work flow looks like this:
1 - Use DVDDecrypter to get the VOB files onto your hard disk, in a separate folder for each DVD, all in the same parent folder. (I use two machines for this so I have two going at once, then copy the VOBs over to the same machine later)
2 - Run my script to create the Job Control List for VDubMod
3 - Open VDubMod, load the script, hit start and watch it crank away.
4 - Go to bed. It's going to be awhile. (Or if you have a fancy enough processor do something else while it's processing, like write a blog about it, which is what I'm doing write now. :-) )

Here is the script (lots of programs might complain about you downloading a VBS file, so I've renamed the extension to JRR. Rename it back to VBS after downloading):
createVirtualDubModJobs.jrr

My script is VERY unrefined, as I just created it. I'll probably refine it and upload a better version, but it works. You just need to edit the script and find the variables that set the parent folder for all your VOB files and the destination folder. The script assumes you have one parent folder with one or more subfolders that contain VOB files. Feel free to tweak to your liking.

Yes this will take gobs of hard disk space. Yes you still need to copy all the VOB files from the disks to your computer. Yes you still need to wait for VirtualDobMod to transcode all the VOB (MPEG II) files to DV AVI files.

Can't I just edit the VOB files in Premiere you ask? Yes - sort of. You can get a AVISynth Premiere Plugin, but it's a complicated, laborious process that you can't really script (have to do each VOB one by one). Also, I haven't played with it a lot, but I haven't had much luck getting it to work with Premiere CS3 anyway. If you want to look into it, here's the instructions and all download links for the relevant utilities:
http://www.wrigleyvideo.com/forum/index.php?s=776d0be8c3c99092874bce53a3756694&showtopic=22869

Labels: ,

Wednesday, June 20, 2007

ATI Avivo Video Converter

I originally posted this on a different blog, but thought it was relevant for this blog as well:

This is a great product when it works. The accelerated rendering of AVI to MPEG2 is lightning fast, and is the main reason I purchased this card. HOWEVER, in true ATI fashion, the gui that lets you accomplish this is buggy. Specifically, if I export a movie to AVI from Adobe Premiere Pro and then try to encode it to DVD format (or MPEG2) with the Avivo Video Converter, the application will crash every time you try to move the slider bar to adjust the bitrate. I am putting this in my blog in the hopes that by some miracle someone else will stumble across it who may have found a workaround for this problem. It's driving me crazy. I have this expensive video card virtually sitting idle in my machine because I don't want to encode professional DVD video at a bitrate of 6.0 Mbps - I always use 7.0 Mbps and sometimes 8.0 Mbps. I've been working with ATI on this issue for 6 MONTHS now, and have been throu SIX, count 'em SIX driver revisions. There support is horrific at best to work with - they simply do not listen to what you are telling them. I have submitted trouble tickets, feedback to the catalyst crew, and feature requests. They have all fallen on deaf ears, and their support cannot give me a solution.

Labels:

Monday, June 04, 2007

Slow Motion in Premiere

With the new Premiere CS3, there's lots of talk about using the time remapping feature for variable slow motion (progressively slowing the clip down or speeding it up.) This is something that previously required After Effects, so it's pretty exciting to have that in Premiere. But that's not what I want to write about - I'm more interested in writing about how to achieve good slow motion results in Premiere Pro, especially when dealing with interlaced footage.

As a wedding videographer (and a sports videographer, where this article is even MORE relevant), I use slow motion ALL THE TIME. A little slow motion and the right song can do wonders for otherwise ordinary footage. But sometimes that slow motion causes your footage to become jerky, especially when using very low speeds with interlaced footage. What's the best way to get smooth slow motion (aside from filming at a higher frame rate)? I was struggling with this issue just tonight and came up with what seems (so far anyway - I need to test with more clips) to be a good solution.

First, let me address what is SUPPOSED to work, but doesn't seem to, or doesn't work all that great. First, Adobe will tell you to use the frame blend option. In my tests, this seemed to make little or no difference. Some will tell you to use integer multiples for your speed so that Premiere doubles (or triples, etc.) the frame rate evenly (50% = 2x, 33.33% = 3x, 25% = 4x, etc.). Again, with the particular clip I was having trouble with tonight, that seemed to help a LITTLE, but barely. Then there's always the time remapping feature in After Effects, but I wanted a solution that just uses Premiere. I've also come across suggestions to use the ReelSmart Twixtor plug-in - I haven't tried it - I don't really want to drop several hundred dollars on a plugin just to get good slow motion - shouldn't Premiere be able to handle this natively?

Enter the Posterize Time effect. Generally I've used this effect for slowing down frame rates when I actually want the footage to be jerky. Ever seen those commercials when they want to make something look really bad (like the competitor's product) or news stories about some nefarious scheme and they play footage in black and white with really jerky footage? There are rare occasions (think billion dollar man slomo sequences) where you actually want jerky footage. The plugin is also sometimes used to attempt to make 60i footage look like 24p to achieve a film look.

ANYWAY, I discovered that I can actually use this effect to INCREASE the frame rate of my clip and give me better slow motion. Of course,I'm not literally increasing the frame rate of the source footage - that would require reshooting at a higher frame rate. I'm just "pretending" or telling Premiere that it's a higher frame rate. To be honest, I don't know EXACTLY what Premiere does when you use this filter with a higher frame rate than the source footage, but from my empirical evidence, whatever it does, it works pretty well.

First, I asked myself what Premiere actually has to do to slow down footage. Well, it has to increase the number of frames playing in a given time frame. If I play back my footage at 50%, it needs twice as many frames to make the same clip take twice as long at the same frame rate. The extra frames are accomplished through interpolation. So taken to an extreme, at 10%, each frame would now be doubled 10 times. You can see how this would lead to jerky footage - instead of the picture changing 30 times per second (or each field changing 30 times per second, or 60 times overall, to be more accurate dealing with interlaced footage), the frame will only change 3 times per second. So I came up with this formula, which may be completely baseless, so take it for what it's worth - it just seemed to work. Original FPS / speed = FPS for Posterize Time filter. So my original clip is 30fps, I want to slow it down to 40%. 30 / .4 = 75. I apply the posterize time effect, set the frame rate to 75, and by golly, it looks pretty good. Of course, it still looks pretty good when the fps is set to 30, so the formula really isn't that important, just the concept of using the posterize time effect.

Realistically, I've found that Premiere does slow motion just fine at 50% and above. It's only when you drop below that that you start to have problems...and using progressive footage is a whole different story, as is the definition many consumer camera manufacturers use to define "progressive." The reason I mentioned sports videography at the beginning of this article is because jerky footage (as well as interlacing artifacts) is much worse when there is more action happening in the clip, or when the camera itself is moving quickly. There is more change in the image from frame to frame (or field to field). I've found that as you increase the fps on the posterize time effect, you can end up smoothing the video, but blurring it more, especially for high action shots. The frame blending and interpolation process attempts to sort of take the middle ground when creating extra frames, so when there's greater differences between each frame and each field, those created frames can be quite blurry. When slowing high action shots down to extreme slow speeds, you have a trade off between clarity and smoothness with the posterize time effect.

Related to this article is achieving good frame holds - ones that don't shake violently. That's another topic related to interlacing - maybe I'll address that another time...

Labels: ,