Issues with the "Movie Importer" patch while rendering with QCRenderer

Marxon13's picture

I am writing a program for OS X Lion that is basically a video mixer. I create a QCRenderer with my patch using initOffScreenWithSize:colorSpace:composition:. I then programmatically pass video from a camera and a path to a movie file to two separate inputs of the patch. The movie file is then loaded by a "Movie Importer" patch. The problem is that the movie importer returns an error and no movie.

The error is: *** Message from : ERROR: Running movie on thread 0x109106000 while initialized on thread 0x1053b5000

This message appears upon processing most of the frames, sometimes it works. This is what I'm doing to get an image from the QCRenderer.

[offscreenQCRenderer renderAtTime:[NSDate timeIntervalSinceReferenceDate] arguments:nil]; NSImage *frame = [offscreenQCRenderer createSnapshotImageOfType:@"NSImage"];

Inside the patch I the "Movie Importer" patch time is set to external, and I pass it a modified patch time; looping the overall patch time with a "Round" patch to the length of the movie.

Any help with fixing this is greatly appreciated.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cybero's picture
Re: Issues with the "Movie Importer" patch while rendering ...

Hello Marxon13 and welcome to posting upon this forum. Haven't recently ghosted upon the quartzcomposerdev list but if you aren't already registered with that list you might also find further help there in addition to any you receive herein upon this forum, many , if not most of which forum's subscribers are also contributors to that list. Do you find that you obtain problems with the core composition to your application itself within Quartz Composer?

Marxon13's picture
Re: Issues with the "Movie Importer" patch while rendering ...

No, If I have the composition open in Quartz Composer itself, there are no issues.

Marxon13's picture
Re: Issues with the "Movie Importer" patch while rendering ...

I've managed to figure out QT is not exactly thread safe. Coupled with the QCQuickTimePlayer error showing two threads, I believe threading is my main issue here. I still have no idea where to begin fixing this though.

gtoledo3's picture
Re: Issues with the "Movie Importer" patch while rendering ...

Bingo... I think I remember something about it dealing with using QCRenderer too? Search the QC developer lists/google on this, it's come up a ton of times, and I think it's been fleshed out well enough that if you had to deal with it, it would be clear. I haven't really had to deal with it hands on, and have used the v002 movie player or kineme's video tools as a quick workaround. I know there's sample QC app projects that run movies through qtz's as well at the apple developer center.

Marxon13's picture
Re: Issues with the "Movie Importer" patch while rendering ...

There is only one example of a QCRenderer using a QC Patch with a "Movie Importer", it is called "Quartz Composer Matrix". It is very old and the .nib, .qtz, and the project file won't open. But noticing it was PPC gave me a few ideas.

After doing some threading and QTKit research I've narrowed down the problem. The issue is that apples's example is for PPC, so it is 32bit, which eliminates the threading issue. I'm creating for 64bit Intel, so QTKit is not directly supported, only some of it works. I would have to rewrite the QTKit class to make the portion I need thread safe.

I can't use Kineme's video tools, because it uses private API's, and this app is for the app store (I wish I could use it though, because it works beautifully without lag). I don't want to use v002 movie player because it is the buggiest thing I have ever seen. It crashed my application randomly, crashed my graphics card, and caused kernel panics.

I'm going to try to turn the "Movie Importer" into a published image output, and use AVFoundation to pass frames of a movie to the input port. I was going to use AVAssetReader, until I found out it does not process frames at anywhere near real time. Now I'm looking at AVPlayer, which works in real time. It outputs to a CALayer. Can I pass this to QC, or do I have to convert it first? I can't seem to find a list of input image types from apple, but they did mention that a NSImage and CIImage can be passed to QC.

gtoledo3's picture
Re: Issues with the "Movie Importer" patch while rendering ...

Edit

.lov.'s picture
Re: Issues with the "Movie Importer" patch while rendering ...

Be sure you are using the QCRenderer on the same thread on you created it. The issue will gone.

gtoledo3's picture
Re: Issues with the "Movie Importer" patch while rendering ...

Yeah, I knew tamas would chime in bc he's fleshed this out on list before. Looking at the archives, the resolution is gone into in detail. A little googling works wonders.

Marxon13's picture
Re: Issues with the "Movie Importer" patch while rendering ...

You don't happen to have a copy of apple's "QCRenderer Thread Guidelines" do you? I've seen references but apple doesn't have it anymore.

I figured out how to check threads and figured out that createSnapshotImageOfType: was being called on about 6 different threads. Which probably also explains what I believe to be a leaking texture when actually recording the QCRenderer output.

My plan is to start by making a single thread QCRenderer with the "Movie Importer" patch. Then I'll make another version making the replacing the patch with a published image input and supply the image with an AVPlayer. I'll then go with whichever is faster. Right now, my guess is the AVPlayer version as the QCRenderer will have to do less work to render the final output.

.lov.'s picture
Re: Issues with the "Movie Importer" patch while rendering ...

It just was a small technical note: https://developer.apple.com/library/mac/#qa/qa1538/_index.html

Anyway, don't use createSnapshotImageOfType: if performance is a go.

gtoledo3's picture
Re: Issues with the "Movie Importer" patch while rendering ...

Hey, if you remember, please report back on your findings with using the AVFramework and performance (I've been working through the examples today, and have noticed a few things it can do in the process that are really nifty, and I'm intrigued). Thanks! :-)