ios - AVAssetWriter Writes Video but does not record AUDIO -
i have been successfull in making viedo (though blur) but have been unsuccessful in recording audio please help.
i using following code pls go through ans suggest solution or working tutorial.
i appending sample buffer using
[encoder._writerinput appendsamplebuffer:samplebuffer]; , app crashes when following statement called [encoder.audiowriterinput appendsamplebuffer:samplebuffer];
- (void) initpath:(nsstring*)path height:(int) height andwidth:(int) width bitrate:(int)bitrate { self.path = path; _bitrate = bitrate; [[nsfilemanager defaultmanager] removeitematpath:self.path error:nil]; nsurl* url = [nsurl fileurlwithpath:self.path]; //initialize video writer _writer = [avassetwriter assetwriterwithurl:url filetype:avfiletypempeg4 error:nil]; //initialize audio writer // audiowriter = [avassetwriter assetwriterwithurl:url filetype:avfiletypecoreaudioformat error:nil]; // nsdictionary* settings = @{ // avvideocodeckey: avvideocodech264, // avvideowidthkey: @(width), // avvideoheightkey: @(height), // avvideocompressionpropertieskey: @{ // avvideoaveragebitratekey: @(self.bitrate), // avvideomaxkeyframeintervalkey: @(150), // avvideoprofilelevelkey: avvideoprofilelevelh264baselineautolevel, // avvideoallowframereorderingkey: @no, // //avvideoh264entropymodekey: avvideoh264entropymodecavlc, // //avvideoexpectedsourceframeratekey: @(30), // //avvideoaveragenondroppableframeratekey: @(30) // } // }; nsdictionary* settings = @{ avvideocodeckey: avvideocodech264, avvideowidthkey: [nsnumber numberwithint:width], avvideoheightkey: [nsnumber numberwithint:height], avvideocompressionpropertieskey: @{ avvideoaveragebitratekey: [nsnumber numberwithint:bitrate], avvideomaxkeyframeintervalkey: @(150), avvideoprofilelevelkey: avvideoprofilelevelh264baselineautolevel, avvideoallowframereorderingkey: @no, avvideoh264entropymodekey: avvideoh264entropymodecavlc, avvideoexpectedsourceframeratekey: @(30), avvideoaveragenondroppableframeratekey: @(30) } }; audiochannellayout acl; bzero( &acl, sizeof(acl)); acl.mchannellayouttag = kaudiochannellayouttag_mono; nsdictionary *audiooutputsettings = [nsdictionary dictionarywithobjectsandkeys: [ nsnumber numberwithint: kaudioformatmpeg4aac ], avformatidkey, [ nsnumber numberwithint: 1 ], avnumberofchannelskey, [ nsnumber numberwithfloat: 44100.0 ], avsampleratekey, [ nsnumber numberwithint: 64000 ], avencoderbitratekey, [ nsdata datawithbytes: &acl length: sizeof( acl ) ], avchannellayoutkey, nil]; audiowriterinput = [avassetwriterinput assetwriterinputwithmediatype:avmediatypeaudio outputsettings:audiooutputsettings]; audiowriterinput.expectsmediadatainrealtime=yes; _writerinput = [avassetwriterinput assetwriterinputwithmediatype:avmediatypevideo outputsettings:settings]; _writerinput.expectsmediadatainrealtime = yes; [_writer addinput:audiowriterinput]; [_writer addinput:_writerinput]; }
Comments
Post a Comment