Embedding Movies in Quartz Composer : Image Structures

gtoledo3's picture

It is possible to embed a movie in Quartz Composer, by following these steps:

  1. Convert the movie to an image sequence.

  2. Convert that sequence to a multipage document (like a pdf or gif).

  3. Place an Image patch on the surface of the QC Editor.

  4. Select the Image patch. Go to Settings, using the Patch Inspector. Under Image Options, select Extract All Images. Choose Import From File, choose your file, then select Open to load it into the Image patch.

    Now, the Image patch will output a structure of all frames from your movie/image sequence. By connecting a Structure Index to the output of the Image patch, and then connecting the output of the Structure Index patch to a Billboard (or other patches that render an input image), one will render the first frame in the sequence.

  5. Connect an Image Dimensions patch to the output of the Structure Index. Connect the Width and Height outputs to the Width and Height Inputs of the Billboard patch. To obtain both Width and Height Inputs for the Billboard patch, select the Patch Inspector, go to Settings, and select Custom Size.

    One should now have a Billboard rendering the first frame of the Image Sequence, referencing said Image for it's Width and Height.

  6. Now, select another Structure Index. Connect the output of the Image Patch to this Structure Index, and the output to the existing Billboard.

    By using an Interpolation or LFO patch, one could play through frames, but a good starting point for movie playback is to create a looper macro with definable FPS. There are multiple ways to achieve this. An easy way is to :

  7. Take the Patch Time, and multiply by an Operand using the Math patch, which will become the Frame Rate of the playback.

  8. Then, take a Math Expression patch and enter "a % b" into Settings.

    In this case, "a" will take the output of the Math patch. Place a Structure Count patch on the Editor, connect the input to the output of the Image patch, and the output Count to input "b" on the Math Expression patch.

  9. Take the second Structure Index that you created, and which should be connected to the Billboard, and connect the output Result of the Math Expression patch to the Index input of the Structure Index. Enter in the desired playback rate, by changing the multiplicative Operand on the Math Patch. Publish this input and call it Frame Rate.

...and you're done! One should have a qtz that is playing back an embedded movie, with ability to define the rate of playback.

For an example of this, reference the attached file.


I've tested this with multi-page pdf's and gif images, though I'm guessing that multi-page tiff would likely work as well.

For creating your own from scratch, it's easy to convert movies to Image Sequences using Quicktime's Export to Image Sequence ability. From that point one, can use a utility program to create a gif, or use Preview to convert to pdf.

I would think it would be possible to merge a pdf document by using Preview, and according to some unofficial documentation I've read, but when I drop multiple pdf's onto the sidebar in Preview, it doesn't give me a "bound"/merged document. I've used an older free utility called "pdfsam", which will successfully create a merged pdf document with correct ordering.

For the sake of size (and cost of quality), one may want to reopen the merged pdf in Preview and Save using the "Reduce File Size" Quartz Filter option.

The creation of Image Sequence from movie, to merged pdf or gif file seems like something that should be scriptable, to avoid having to use various applications to prep the Image document, but I haven't investigated the automation of that process yet.

embedded_movie.qtz1.57 MB

gtoledo3's picture
Re: Embedding Movies in Quartz Composer : Image Structures

Hmm, smokris, the numbering on my original post was correct in my entry field, but it posted oddly (with 1, 2 where 5, 6 should be, and so on). If I quote the post, I can see that it was numbered correctly, and that the problem happened on the Drupal end.

cybero's picture
Re: Embedding Movies in Quartz Composer : Image Structures

Regarding making a PDF from a QuickTime Image sequence I do the following

a - output an image sequence to a folder.

b - select all the image files and drag the folder contents over the Preview icon [Dock or Applications folder].

c - open up the Preview sidebar and select all the images in the sidebar.

d - Alt + Command + P = Print all selected images.

e - at the printer dialog box, elect to print to PDF [ might require the Guttenberg drivers].

f - outputs a PDF to the directory of your choice.

g - open in Preview and if you wanted to, re-save anew but with the option to reduce file size from the Quartz Filter menu. Amazing to see 9MB become 718KB.

Useful post BTW.

smokris's picture
Re: Embedding Movies in Quartz Composer : Image Structures

(Markdown looks for lines starting with a number followed by a period and a space, and turns them into HTML ordered list items. Every time an ordered list stops and starts again, the numbering restarts --- this is part of the HTML spec. You can work around it by indenting intervening paragraphs, which places the paragraph inside the list item, instead of stopping the list, showing the paragraph, and starting another list. I modified your post to do this.)

dust's picture
Re: Embedding Movies in Quartz Composer : Image Structures

glad you brought this up as I have been doing some animations this way for a bit. I actually wrote a nifty Action script for this. well not that nifty could be done post in qc but the script basically adds an alpha channel to an image frame then selects the alpha inverses the alpha selection mask and erases the mask from the image deletes the alpha channel saves the file as a png. I then batch process all frames with that action then use cyberos method for making a PDF. this results in a compressed movie file with transparencies that can embedded and cycled through. now we need to figure out how to embed an audio file

toneburst's picture
Re: Embedding Movies in Quartz Composer : Image Structures

This is a really cool method, I can see myself using this in the future. Any chance of posting that AppleScript dust?

Nice one guys.


gtoledo3's picture
Re: Embedding Movies in Quartz Composer : Image Structures

I see what was hosing me up on using Preview... (I'm on a test seed right now). When I first drag onto the sidebar, and "select all" it doesn't select all the first time I try it, even if an image is highlighted. It will only select all the second time I "select all". I guess I'll file a bug.

As far as the transparency goes, it's interesting to approach that on the front end, but also extremely easy to do with CI. Probably saves FPS though.

What would be interesting to me is a script/straightforward conversion of movie file to gif or multipage pdf (or tiff... still haven't tested, but I will take a wild guess that it likely works), moreso than a script that did something with alpha channels on multiple images (I think something like that may be in GIMP, come to think of it). It's funny that Quicktime Pro exports to Image Sequence, but not to any standards that are "multi-page", so to speak.

Though I think that embedding can be hard on QC, in initially loading a qtz if it's a large file size, there's something appealing in having access to every frame in a movie in this way. It's an efficient technique for other things that may not be immediately apparent - for instance, I've been playing with some particle scenes that use image sequences as part of the setup, to gain way more apparent particles, and animations deterministic on collision with boundaries/coordinates. It's also very interesting for pseudo "growing" looks, by having many "vine" type animation sequences of say, 10 frames, which randomize each time you click on a point on the QC Viewer... those kind of things. It also really lends itself to layering.

It's always been possible/standard technique to load single images into QC, and build image structures with javascript (or the queue) to do stuff sort of like this, but it's really heavy duty when one considers the implications of easily flying in and embedding thousands of images that are laid out as a structure from the start.

I stumbled on the idea in a round about way from my endless fascination with the Image Loader, and that it's one patch in QC that can natively embed all kinds of info. You can use a qtz as a shell in that way, by renaming an arbitrary file as an image type, loading it into a qtz., then later, holding Option on the Import field in Settings, saving the file, and renaming it to it's original file extension. The lightbulb went off for me, weirdly, when I was looking at Settings on a mesh patch, and saw the option to import as separate meshes... that strangely jogged my memory about the fact that "Pages.qtz" (a thorn in my side for it's broken mesh filter), loads the pdf as an image structure.

Also, a project I commissioned from Kosada about a year ago led me to thinking about this, as well as a random discussion between cwright and tkoelling on-list about lack of animated gif support in QC (guys, guess what, there isn't lack of animated giff support...but maybe it was in reference to Quicktime playback?) so it's a combo of factors.

Interestingly, I don't get lag time when actually running qtz's that use large imbedded image structures though, once the file has loaded... I guess because it only has to call for one frame at a time?