recording quicktime with sound in sync

also, try this:

at the end of finishMovie() comment out this line:

DisposeMovie (movie);

it seems to help :slight_smile:

-zach

Hello

Im trying to get this code to work on a mac with 10.5 on. But when it in the addFrame code comes to the CompressImage part, it crashes with an cannot acces memory error. Any body knows why?

hi halfdanj. I’m getting a bad access error as well. To me it looks like something’s overwriting memory and trashing things but that’s just a hunch at this point. hmm.

ah two small fixes for the mac:

there was a small bug here:

  
  
    for (int i = 0; i < h; i++){  
		gwAddress = gwAddressBase + i * gwWidth;  
		myData = data + i * myWidth;  
		for (int j = 0; j < w; j++){  
			memcpy(gwAddress+1, myData, 3);  
			/*gwAddress[1] = myData[2];  
			gwAddress[2] = myData[1];  
			gwAddress[3] = myData[0];*/  
			gwAddress+= 4;  
			myData+= 3;  
		}  
	}  
  

the inner for loop was written as:

for (int i = 0; i < w; i++){

not

for (int j = 0; j < w; j++){

second problem was this code in testApp.h:

  
  
	saver.listCodecs();  
	saver.setCodecType(2);  
	saver.setCodecQualityLevel(OF_QT_SAVER_CODEC_QUALITY_NORMAL);  
	saver.setup(320,240,"output.mov");  
  

the codec type for 2 was not a good one on some systems (or caused trouble in compression). On my system, it’s “Apple Pixlet Video”. commenting that uses motion jpeg, the default, or you can try others… I don’t know yet why this fails, but it does…

comment it out and it’s all good:

  
  
	saver.listCodecs();  
	//saver.setCodecType(2);  
	saver.setCodecQualityLevel(OF_QT_SAVER_CODEC_QUALITY_NORMAL);  
	saver.setup(320,240,"output.mov");  
  

I’ll reupload this shortly – just thought I’d point out the fixes…

take care!
zach

just tried this on mac osx and works very well.

initially without the two fixes by zach it was not working as the file was created but not filled with data, it was always 0 bytes in size.

applying the two fixes it works nicely, thank zach!

I’ve put here the working project, maybe can be useful to someone with a mac.

hey, this is wonderful! I have been dreaming of an equivalent to processings moviemaker for some time but not had time to address it, this is it. Not only is it great for a lot of projects based on video, by going through ofImage.grabScreen() it also makes it easy to record videos of animations etc made in oF… thanks! I hope this gets really solid and goes into the main oF api…

[quote author=“claudio”]
I’ve put here the working project, maybe can be useful to someone with a mac.[/quote]

this is really cool! I’ve been looking for some multiplatform way of recording video for a while and this is the first easy+working solution I’ve found.

I am not getting any audio in the file though… is this code supposed to record audio as well? The topic title suggests it should but looking at the code I only see it grabbing / recording the video stream. (I was testing it with the built-in iSight, could that also be the problem?)

Hi all ,

I’ve tried to get this example running on windows, and I like it… runs so fast and using JPEG motion (14) it’s great option for reduce the Ram level of memory.

but I’ve got error when the QtVideoSaver makes setup. I’ve read some comment about the long of the path, an it’s true… executing the example directly on “c:” it’s runnig fine. Just with some debug tool , I’ve see the value of fsSpec after nativePathNameToFSSpec have some dash at the end of the path name “ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ…” :evil:

There are any solution?

May be cleaning the variable after the function return this awfull value… any trick?

the best

Hi again,

If someone want to try it…the zip

Is the entire project in Vs2005. There are some images inside, then you can test it directly.
Mainly the app, look for images inside images folder, charge all the jpeg images and make a movie. This run fine only one time, when you try to repeat the operation , then the app crash when try to create the second video.

The best

i think i found the bug otherside and halfdanj are referring to.
in ofQtVideoSaver add the following line before line 485:

  
SetGWorld(pSavedPort, hSavedDevice)  

now i am able to record two videos simultaneously…

hope that helps

best
joerg

Super ! It is going so fine

Thank you!

I’m loving the video saver utility! one strange thing I’m getting however is that If I call finishMovie() from within ofSimpleApp::exit() then I get this error:

AddMovieResource failed -2095

Any ideas? I looked at the source and it is coming from here:

  
 sResId = movieInDataForkResID;  
    osErr = AddMovieResource  
      (  
      movie,                           /* movie to create moov atom from     */  
      sResRefNum,                      /* file to receive the moov atom      */  
      &sResId,                         /* id num of movie resource (res fork)*/  
      (unsigned char *) fileName.c_str()                      /* name of movie resource (res fork)  */  
      );  
    if (osErr)   
      {   
      printf ("AddMovieResource failed %d\n", osErr);   
      goto bail;   
      }  

(Old thread, sorry) I’ve just been using this and it works well on my mac but I too need to capture audio into the movie file. Has anyone developed this further to do this?

This works for me if you already have a wave file saved on your disk and with the side-effect of having an additional empty audio track.

Add this to the ofxQtVideoSaver.cpp

  
  
void ofQtVideoSaver::addAudioTrack(string audioPath)  
{  
	OSErr err;  
	Handle dataRef = NULL;  
	FSSpec    fileSpec;  
	short audioMovieRefNum = 0;  
	short audioMovieResId = 0;  
	Movie audioMovie = NULL;  
	Track audioCopyTrack = NULL;  
	Media audioCopyMedia = NULL;  
	Track destTrack = NULL;  
	Media destMedia = NULL;  
  
	destTrack = NewMovieTrack (movie, 0, 0, kFullVolume);  
	destMedia = NewTrackMedia (destTrack, SoundMediaType,  
                            30. * 100, /* Video Time Scale */  
                            nil, 0);  
      
	err = BeginMediaEdits (destMedia);  
      
	char * p = new char[audioPath.length()+1];  
    strcpy(p, audioPath.c_str());  
    NativePathNameToFSSpec(p, &fileSpec, 0L);  
      
	err = OpenMovieFile(&fileSpec, &audioMovieRefNum, fsRdPerm);  
	err = NewMovieFromFile(&audioMovie, audioMovieRefNum, &audioMovieResId, NULL, newMovieActive, NULL);  
	err = CloseMovieFile(audioMovieRefNum);  
      
	SetMovieTimeScale(audioMovie, 30.*100);  
      
	audioCopyTrack = GetMovieTrack(audioMovie, 1);  
	audioCopyMedia = GetTrackMedia(audioCopyTrack);  
      
	long duration = GetMovieDuration(audioMovie);  
      
	err = AddEmptyTrackToMovie (audioCopyTrack, movie, nil, nil, &destTrack);  
	err = InsertTrackSegment(audioCopyTrack, destTrack, 0, duration, 0);  
	err = EndMediaEdits(destMedia);  
}  
  

and the appropriate declaration in the .h file:

  
  
void	addAudioTrack(string audioPath);  
  

Maybe someone can figure out why it saves 2 audio tracks!? Otherwise, if you are going to do anything with this video file, I’d recommend using something like ffmpeg to strip out the extra audio track out with the “map” command… or you could have some funny results when importing online or converting to another format etc…

e.g.

  
  
ffmpeg -i in.mov -map 0:0 -map 1:1 out.mov   
  

I’m going from memory on that so I hope it is correct!

Sorry I don’t know how to capture the audio at the same time but it should be along these lines… the Quicktime docs have a lot of nice tutorial code etc…

Hope that helps,
pkmital

Works great in 0.06!

ofxMovieSaver
MovieSaver-example

1 Like

going the check the MovieSaver with OSX however with WIN it doesn’t work.

I’d tried to switch OF_SWITCH_TO_DSHOW_FOR_WIN_VIDCAP with OF_VIDEO_CAPTURE_QUICKTIME but then the video grabber failed to compile.

any clue ?

Roee

i’m trying compile the MovieMaker example but always i get an error at fclose(pFile); in the ofxQtVideoSaver.cpp

  
  
#ifdef TARGET_WIN32  
FILE * pFile;  
pFile = fopen (fileName.c_str(),"w");  
fclose (pFile);  
  

can someone help me ???

[quote author=“jefftimesten”]Works great in 0.06!

ofxMovieSaver
MovieSaver-example[/quote]

Well, when i try to compile it says (on OS X): error: ‘NativePathNameToFSSpec’ was not declared in this scope, any ideas.

to fix for 0.06, I commented out the audio saving code (where that line was) and threw into a new xcode project (might have been not really 0.06). can you try this :

http://www.openframeworks.cc/files/movieSaverMac006.zip

take care!
zach

I tried the Xcode project. I was able to record video no problem but still no audio. :frowning: Just letting you know my results.

Peace

OF 0.06
OS X 10.5.6
MacBook Pro 15