video frame export with preview

I apologize if this has been addressed elsewhere. I’ve searched the forums, but haven’t found anything addressing my need.

Here’s my request. I have an AppleScript Studio application I built in XCode that posts video clips to a remote server using FTP and a web service. Works great. Now, I would like to allow the user to see their video file, move the playback position to a particular frame, then capture the current frame as a JPG. The real catch is that I need the code to work on 10.3 and 10.4 and not be dependent on QT Pro. This app is used on a lot of computers and I have no way of making QTPro available on all those machines.

I am completely open to purchasing a commercial or shareware application/plug-in if that makes it easier. If there is an open-source/freeware solution available, I am also quite keen on donating to the cause as well.

I think you in advance for your help.

Joel Clermont

To my recollection, this hasn’t been covered here. There are, though, many threads in cocoa forums throughout the internet covering this topic, so all we need to do is use some of that code and mix it in with AS. First, I’ll mention that I was able to do this in a few different ways. I started by creating a bitmap from the view using “initWithFocusedViewRect” from the nsview class. Despite my attempts to tweak the data, I couldn’t get the resolution of the final jpg to be worth *#&%. I tried a couple other methods and variations, all with the same poor results.

Ultimately, I ended up at the following solution. It takes a screenshot of the whole screen and places in on the clipboard. Then, some obj-c code reads the clipboard and makes a jpg out of the area of the screenshot that was occupied by the view.

First, create a subclass of NSObject. I named mine SCObject, for ScreenCapture… as it’s good to give your subclasses descriptive and unique names. Create both the interface(.h) and implementation(.m) files, and place the following code in them, respectively.

Then, use something like the following code to set up the required variables and make a call to your subclass…

on clicked theObject
	if name of theObject is "Screencapture" then
		set theFilePath to "/Users/YOU/Desktop/Test.jpg" --> Where to save the jpg
		set theView to (movie view "myMovieView" of window "myMovieWindow") --> The view to grab a pic of
		set showController to (controller visible of theView) --> Do we need to hide the controller?
		
		(* Hide the controller while we take a pic *)
		if showController then call method "showController:adjustingSize:" of theView with parameters {no, yes}
		
		(* Grab a screenie and put it in the clipboard *)
		do shell script "screencapture -c -x -t png"
		
		(* Use obj-c method to crop screenie and create an image *)
		call method "createImageFromView:saveToFile:" of class "SCObject" with parameters {theView, theFilePath}
		
		(* Put the controller back the way we found it *)
		if showController then call method "showController:adjustingSize:" of theView with parameters {yes, yes}
	end if
end clicked

As I said, this is the method that I used which yielded the best quality image. There are plenty of other ways to do this, and whether they are better or worse depends entirely on image quality and reliability. The one thing that worries me about this code is using the clipboard as an intermediate step. Ultimately, if you could do this with another method and still get exact screen-res quality, you’d have found a better method.

Good luck, and let me know if this doesn’t work and perhaps we could find someone with some actual image experience to help us with getting the bitmaprep using one of the other methods.

j

About your resolution problems, did you:

NSImage* source;
[source setScalesWhenResized: YES];

iMagine Photo is a free AppleScript tool that can process the individual frames of a movie.

The last script on the webpage:
Register a .EU.COM domain today! Shows you how to render individual frames of a movie.

The last script on the webpage:
Register a .EU.COM domain today! blends two images together, but the important part for what you want shows you how to create an image file from the final rendered image.

I am kind of busy right now, but if you managed to put together a script from this to suit your needs but needed help with a specific problem then I would be more than happy to help.

Kevin

I must say I’m impressed with the quick, yet thorough, replies. Unfortunately I may need a little bit more guidance to apply your suggestions. For example, I’m not entirely sure how to even get the movie control on my application. I assume that’s what you refer to as “myMovieView” and “myMovieWindow” in the AppleScript above.

Would you mind dumbing it down a bit for me and including a few more steps? In the meantime I will begin taking a stab at applying your suggestions and let you know how far I get.

As for the post regarding iMagine Photo, I tried viewing your documentation links, but the pages did not resolve. Maybe it’s a temporary condition. I will try again later today.

Bad timing. That’s the first time mywebsite has been down in over 2 1/2 years that I know of. My service provider is aware of the problem and working on it. I’ll let you know when you can check out the pages.

Thanks
Kevin

website is working now.

Kevin