Adapting Apple's QTKit Tutorial for Command Line


i've got apple's basic capture application working shiny looking cocoa gui around it:

http://developer.apple.com/document...1.html#//apple_ref/doc/uid/tp40004574-ch4-sw2

however, started looking qtkit because attempts ffmpeg/ffserver (linux originating command line tools) capture i-sight turned out impossible (from i've read ffmpeg doesn't support os x when comes capture devices).

wanted build small cli tool captures video i-sight , streams on http in compressed/encoded form, ffmpeg/ffserver on linux. taking apple's little tutorial linked above hopeful wouldn't difficult , learning experience in mac programming anyway.

i've done built app , compiled fine (also spent time fiddling gui adjustments in ib). i'm trying run without gui. i've pretty tried using foundation , qtkit frameworks dropping qtcaptureview qtcapturesession.

happens main() method runs in split second , application exits. happens fast i-sight light doesn't blink. how i, inside command line objective-c app, qtcapturesession stay open until hit ctrl+c? need start new thread session , sleep current thread? pretty @ loss.

here's code i've tried far:

main.m
code:
#import <foundation/foundation.h>  #import "classes/recordmecontroller.h"    int main(int argc, char *argv) {  	nsautoreleasepool *pool = [[nsautoreleasepool alloc] init];    	recordmecontroller *controller = [[recordmecontroller alloc]  			initwithoutputfilepath:@"/users/chris/movie.mov"];  	[controller startrecording];  	  	[controller release];  	  	[pool release];  	  	return 0;  }
classes/recordmecontroller.h
code:
#import <foundation/foundation.h>  #import <qtkit/qtkit.h>    @interface recordmecontroller : nsobject {  	qtcapturesession *mcapturesession;  	qtcapturedeviceinput *mcapturedeviceinput;  	qtcapturemoviefileoutput *mcapturemoviefileoutput;  	nsstring *mmoviesavepath;  }    - (id)initwithoutputfilepath:(nsstring *)path;  - (void)startrecording;  - (void)stoprecording;    @end
classes/recordmecontroller.m
code:
#import "recordmecontroller.h"    @implementation recordmecontroller    - (void)dealloc {  	[mcapturesession release];  	[mcapturemoviefileoutput release];  	[mcapturedeviceinput release];  	[super dealloc];  }    - (id)initwithoutputfilepath:(nsstring *)path {    	//set save path  	mmoviesavepath = path;  	  	//start capture session  	mcapturesession = [[qtcapturesession alloc] init];  	  	bool success = no;  	nserror *error;  	  	//find default device  	qtcapturedevice *device = [qtcapturedevice  						defaultinputdevicewithmediatype:qtmediatypevideo];	  	if (device) {  		success = [device open:&error];  		  		if (!success) {  			//handle error here  		}  		  		//create new input device  		mcapturedeviceinput = [[qtcapturedeviceinput alloc] initwithdevice:device];  		  		//add input session  		success = [mcapturesession addinput:mcapturedeviceinput error:&error];  		  		if (!success) {  			//handle error here  		}  		  		//create output  		mcapturemoviefileoutput = [[qtcapturemoviefileoutput alloc] init];  		  		//add output session  		success = [mcapturesession addoutput:mcapturemoviefileoutput error:&error];  		  		if (!success) {  			//handle error here  		}  		  		//tell output controller instance  		[mcapturemoviefileoutput setdelegate:self];  		  		//start session  		[mcapturesession startrunning];  	}  	  	return self;  }    - (void)startrecording {  	[mcapturemoviefileoutput recordtooutputfileurl:[nsurl  						fileurlwithpath:mmoviesavepath]];  }    - (void)stoprecording {  }    - (void)captureoutput:(qtcapturefileoutput *)captureoutput  						didfinishrecordingtooutputfileaturl:(nsurl *)outputfileurl  						forconnections:(nsarray *)connections  						duetoerror:(nserror *)error  {  	//roughly translates finder -> open -> myrecordermovie.mov  //	[[nsworkspace sharedworkspace] openurl:outputfileurl];  }    @end
 

i know thread 2 years old, did ever find solution this? i'm in same boat.

i've got main method waits stdin give commands , recorder class dirty work, code. i've tried extending recorder nsthread, doesn't make difference.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Upgrade Eligibility?

need help with itunes 7.7

How to change Apple IDs on iPhones