Sunday 15 August 2010

h.264 - ios AVAssetWriter output invalid video format -


This code works to create videos from images. AVAssetWritter error and export output works fine without video - (.mov) but it fails in some cases the size of the image. 120 x 160 - failed to 180 x 640, 240 x 320, 160 x 213.333, 96 x 128 - to

P / S: Test on iPod 4 III 5.1

Size 120 x 160 Please help me solve this problem or any suggestions for other video encoder libraries will be welcomed. Thank you

This is my code

  - (minus) Writing Imejasomi: (NSArray *): With Cviyadilesek (float) delaySec toPath: (NSString *) path {/ / Delete file NSFileManager * fileMgr = [[NSFileManager alloc] init]; NSER * Error 2; If ([FileMgr Removal ItemAtPath: Path Error: & amp; Error 2]! = Yes) NSLog (@ "unable to delete file:% @", [error2 localized description]); UIImage * First = [Image Object Transmit: 0]; CGSize frame size = first Shape; NSLog (@ "Make Video:% F% F", Frame Size, Width, Frame Size.); NSError * Error = Zero; AVAssetWriter * videoWriter = [[AVAssetWriter alloc] initWithURL: [ns URL file URLWithPath: path] file types: AVFileTypeQuickTimeMovie error: & amp; Error]; If (error) {NSLog (@ "Error creating asset witter:% @", [error description]); } Int News Pixel = Frame Size. Width * Frame Size. height; Int bitsPerSecond; Float bitspikerkasal; // Assume that low-to-SD resolutions are targeted for streaming, and if using less numbers (numpixels <(640 * 480)) bitspiparel = 4.05; // This bitrate matches the quality produced by AVCaptureSessionPresetMedium or the other BitsPerixel = 11.4; // This bitrate matches the quality produced by AVCaptureSessionPresetHigh bitspacesecond = points pixels * bitspixel; Nsdikshnri * Vidokpressionsettings = [Nsdikshnri Dikshnrivitobjektsndkeys: Awvideokondec264, Awvideokodeke [Nsnmber Nmbervithinteger: Frnesizekvidth] Awveedoveedthkey [Nsnmber Nmbervithinteger: Frnesizekhait] Awvideoheigtkey [Nsdikshnri Dikshnrivitobjektsndkeys [Nsnmber Nmbervithinteger: Bittspersekand] Awvideovergebitrteke [Nsnmber Nmbervithinteger : 30], AVVideoMaxKeyFrameIntervalKey, zero], AVVideoCompressionPropertiesKey, zero]; AVAssetWriterInput * Author input = [[Awasatwartrinput light] initWithMediaType: AVMediaTypeVideo output settings: video Comprens Settings]; Author Inputs.exemediaDatinRial = Yes; NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init]; [Features object: [Yuenaianaitiaianti with Ansanm numbers: Kesivipikslformattaip_32arjibi] the Ka to: (Ansstiing *) Kesivipikslbfr Pikselfarmattapakey]; [Features set object: [UISINITInt: frame size with NSNM number number. For Wdth]: (nssting *) kcpxbufferwidthscake]; [Features set object: [UNINSNIT with NSNumber number: frame size. HEAVY] for KA: (NSSTING * KVPPxBaseFrequisite]]; AVAssetWriterInputPixelBufferAdaptor * Adapter = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput: authorInput sourcePixelBufferAttributes: attributes]; [Video adinput: author input]; // fixes all errors writerInput.expectsMediaDataInRealTime = Yes; // Start a session: [starting VoediaDriter]; [Videodriater start session: session time: kcm time zero]; CVPixelBufferRef Buffer = Faucet; Buffer = [self pixel buffer cigma: [first CGI image]]; BOOL Result = [Adapter Epind Pixel Buffer: Buffer With Presentation Time: KCM TimerJero]; If (results == none) fails on // 3 GS, but works on the iPhone 4 NSLog (@ "Failed to add buffer"); If (buffer) {cibbufrerere buffer); } Float delay Mili = delaySec * 25; Int fps = 30; Int i = 0; (For UIImage * imgFrame images) {if (adaptor.assetWriterInput.readyForMoreMediaData) {i ++; CMTime FrameTime = CMTimeMake (WilliamMillie, FPS); CMTime Last Time = CMTimeMake (late * i, fps); CMTime presentTime = CMTimeAdd (last time, frames); NSLog (@ "__Current time:% F", CMTMGetseconds (current time)); Buffer = [self pixel bufferframe CGI: [IMGFram CGImage]]; BOOL Result = [Adapter EpindPixelBuffer: Buffer with Presentation Time: Current Time]; If (result == none) fails on // 3 GS, but works on iPhone 4 {NSLog (@ "Failed to add buffer"); NSLog (@ "error is% @", [videodver error]); } If (buffer) {cibbler release (buffer); }} And {NSLog (@ "error"); I--; }} // End the session: [Author Input MarkSafinicious]; [Videodriist finishing]; CVPixelBufferPoolRelease (adaptor.pixelBufferPool); [Video Reliere Release]; [Author Input Release]; NSLog (@ "Movie successfully created");   

}

The width of the video should be divisible by 16.

No comments:

Post a Comment