FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Convert PICTs into a QT movie


By the by, didn't Mars give you some code once to put a PICT into a movie frame or was that the other way around? :-)

Actually, he gave the code to me. It wasn't really code per se, more like a few steps to follow. Basically a port to FBII of the C that is given in the same steps in "Inside Mac Quicktime" for adding media to a track. I wrote him groveling for some help with making a movie a long time ago and he was kind enough to take the time to reply. All that is below. This info has survived being lost in two hard drive crashes and recoveries. Time to make it safer on more hard drives.

What Andy means (and I) is a sequential PICTs to QT Movie thingie. The holy grail of FB exporting. Something that lets you add your sequential application generated PICTs or gWorld direct to a Quicktime movie track so you can export a new movie. Me and Andy both have written Quicktime Guru man Lon McQillin (sp?). I never got a reply, and Andy got somewhat a better response promising code but no followup. I guess he is either busy or doesn't want us moving in on any portion of his market for his $100 apps. ;=)

I was going to eventually get this figured out and be list hero, but don't have time to delve into this again until next month, so maybe this will be enough of a roadmap for somebody. Andy's initial attempts helped kill my harddrive I think . ;) (I like to kid him about that even if it was something else)

Anybody coming up with anything as a result of this is duty bound to share it with the list.

Spec:
1. Allow for existing numbered PICTs to be imported into a new Quicktime Movie (pict.001,pict.002,pict.003) etc.
2. Allow for direct gWorld to Quicktime addition to new track, for new Movie (my preferred) If number one is achieved, doing this should be easy, as a gWorld is already involved. Adding any application generated image is what I mean, as opposed to an import of an already existing PICT image.
3. Allow for addition of single frame to beginning or end of existing Movie

Bonus: Generate nice standard Compression options and keyframe dialog.

A good starting point I think would be to use the Offscreen.bas ("pixel manipulation") from the FB II or FB3 example. Already allows for opening of a PICT into an offscreen gWorld. Just need another scratch one I think to do the compression.

Anybody needing the Apple supplied C example of such a beast that already works let me know. Or it can be found at Apple's Web site under Quicktime development. Probably a better way to get it.

Beware the line wrap in the below code when using any of it. Some of the calls are lonnnnngggg.

'==========================
========Begin Mars' help letter==========
=========
Step 1. Create a file for the movie to live in.

DIM theMovie&
err = FN CREATEMOVIEFILE(@myFSSpec, _"crea", 0, _createMovieFileDeleteCurFile, 
                         @resRefNum, @theMovie&)
The zero is for the script code. Zero means roman, which is generally what you want anyway.

Step 2. QT needs a way to find this movie. We'll use an alias.
DIM movieDataRefH&
err = FN NEWALIAS(_nil, @myFSSpec, @movieDataRefH&)
Step 3. Create a new video track for this movie.
DIM theTrack&, theMedia&
theTrack& = FN NEWMOVIETRACK(theMovie&, FN LONG2FIX(width%), FN 
LONG2FIX(height%), kNoVolume)
Step 4. Create a media element for this video track. (No, I don't get it either.)
theMedia& = FN NEWTRACKMEDIA(theTrack&, _VideoMediaType,  _kVideoTimeScale, 
                             movieDataRefH&, _"alis")
Step 5. Prepare to add your graphics to the track media element.
err = FN BEGINMEDIAEDITS(theMedia&)
This is where you would create a scratch GWorld. We'll use theGWorld& to refer to this GWorld. Presumably, it is the same height and width as the track you created above.
We also assume that in the process of creating the GWorld, you fill out the movieFrame rect according to the size of the movie.
DIM movieFrame.8
DIM theGWorld&, thePixMapH&, compressedDataPtr&, imageDescH&, maxCompressedSize&
DIM curSample&
Step 6. Set up a place to store compressed data in while adding frames to the media.
isLocked% = FN LOCKPIXELS(theGWorld&.portPixMap&)
thePixMapH& = FN GETGWORLDPIXMAP(theGWorld&)

err = FN GETMAXCOMPRESSIONSIZE(thePixMapH&, movieFrame.top%, _kMgrChoose, _codecNormalQuality, 
                               _"rle ", _anyCodec, &maxCompressedSize&)
compressedDataH& = FN NEWHANDLE(maxCompressedSize&)
err = FN MOVEHHI(compressedDataH&)
err = FN HLOCK(compressedDataH&)
imageDescH& = FN NEWHANDLE(4)

CALL GETGWORLD(@oldPort&, @oldGDeviceH&)
CALL SETGWORLD(theGWorld&, _nil)
Step 7. Add frames to the media element.
err = FN COMPRESSIMAGE(thePixMapH&, movieFrame.top%, _codecNormalQuality, _"rle ",  
                       imageDescH&, [compressedDataH&])
err = FN ADDMEDIASAMPLE(theMedia&, compressedDataH&, 0, imageDescH&..dataSize&, 10, 
           imageDescH&, _kAddOneVideoSample, _kSyncSample, @sampleDuration&)
Note that the "10" specifies how long this frame lasts. The units are 1/600 of a second. Therefore, 10 means one tick. You don't have to use the same amount of time for every frame, but it does make for smoother animation.

Also note that I have used the constant _"rle " in this and the previous step. That is the name of the compressor to use. rle is a very simple, stupid compressor that is fast but not terribly efficient. It works well on images with large areas of flat colour. I believe the constant _"jpeg" also works.

Repeat Step 7 until you are out of frames.

Step 8. Finish adding graphics to the track media element
CALL SETGWORLD(oldPort&, oldGDeviceH&)
CALL DISPOSHANDLE(imageDescH&)
CALL DISPOSHANDLE(compressedDataH&)
'Dump your GWorld in here, unless you need it again later.
err = FN ENDMEDIAEDITS(theMedia&)
Step 9. Add the track media element into the track.
mediaDuration& = FN GETMEDIADURATION(theMedia&)
err = FN INSERTMEDIAINTOTRACK(theTrack&, _kTrackStart, _kMediaStart, mediaDuration&, _kFix1)
I have no idea what _kFix1 means.

Step 10. Add a resource describing this movie into our data file.
DIM resID%
resID% = 0'Res ID of zero means "let QuickTime pick a unique ID".
err = FN ADDMOVIERESOURCES(theMovie&, resRefNum%, @resID%, myFSSpec.fName$)
Step 11. Close the movie and finish up.
err = FN CLOSEMOVIEFILE(resrefNum%)
CALL DISPOSEMOVIE(theMovie&)
'============END Mars quoted Material
Robert Covington