ios4 - AVAssetWriter startWriting fails on iPod Touch 3rd Gen / OS 4.2.1 -
my app creates mp4 file. i've verified code have works on following devices:
- ipad (os 4.3.2)
- iphone4 (os 4.2.1)
- iphone 3gs (os 4.2.1)
.. init fails on ipod touch 3rd gen running os 4.2.1.
this related another question on here, i'm seeing on a different ios device , i've included init code here. other question, i've tried different pixel formats bitrates, avassetwriter's status changes avassetwriterstatusfailed after calling startwriting function.
any ideas appreciated. know mp4 creation possible on device because i've downloaded app fine on same device code fails on.
here minimal code video setup.
#import "avfoundation/avfoundation.h" #import "avfoundation/avassetwriterinput.h" #import "avfoundation/avassetreader.h" #import "foundation/nsurl.h" void videosetuptest() { int width = 320; int height = 480; // setup codec settings. int nbitspersecond = 100000; nsdictionary *codecsettings = [nsdictionary dictionarywithobjectsandkeys: [nsnumber numberwithint: nbitspersecond], avvideoaveragebitratekey, nil]; // create avassetwriterinput. nsdictionary *outputsettings = [nsdictionary dictionarywithobjectsandkeys: avvideocodech264, avvideocodeckey, codecsettings, avvideocompressionpropertieskey, [nsnumber numberwithint: width], avvideowidthkey, [nsnumber numberwithint: height], avvideoheightkey, nil]; avassetwriterinput *assetwriterinput = [avassetwriterinput assetwriterinputwithmediatype: avmediatypevideo outputsettings: outputsettings]; [assetwriterinput retain]; // create avassetwriterpixelbufferadaptor. nsdictionary *pixelbufferadaptorattribs = [nsdictionary dictionarywithobjectsandkeys: [nsnumber numberwithint: kcvpixelformattype_32bgra], kcvpixelbufferpixelformattypekey, [nsnumber numberwithint: width], kcvpixelbufferwidthkey, [nsnumber numberwithint: height], kcvpixelbufferheightkey, nil]; avassetwriterinputpixelbufferadaptor *pixelbufferadaptor = [avassetwriterinputpixelbufferadaptor alloc]; [pixelbufferadaptor initwithassetwriterinput: assetwriterinput sourcepixelbufferattributes: pixelbufferadaptorattribs]; // figure out filename. nsarray *paths = nssearchpathfordirectoriesindomains( nsdocumentdirectory, nsuserdomainmask, yes ); nsstring *documentsdirectory = [paths objectatindex:0]; char szfilename[256]; sprintf( szfilename, "%s/test.mp4", [documentsdirectory utf8string] ); unlink( szfilename ); printf( "filename:\n%s\n\n", szfilename ); // create avassetwriter. nserror *perror; nsurl *url = [nsurl fileurlwithpath: [nsstring stringwithutf8string: szfilename]]; avassetwriter *assetwriter = [avassetwriter alloc]; [assetwriter initwithurl:url filetype:avfiletypempeg4 error:&perror]; // bind these things , start! assetwriterinput.expectsmediadatainrealtime = yes; [assetwriter addinput:assetwriterinput]; // // ** note: here's call [assetwriter status] starts returning avassetwriterstatusfailed // on ipod 3rd gen running ios 4.2.1. // [assetwriter startwriting]; }
i've come conclusion ipod touch 3rd gen can't create .mp4 videos, period. make sense - why include video encoding hardware on device doesn't have camera capture videos with?
the thing making me think could create .mp4 videos had app able create them ipod touch 3. upon analyzing app's .mp4 video, h.263 (mpeg-4 part-2) video created ffmpeg. (whereas avfoundation create h.264 videos if can @ on device).
Comments
Post a Comment