From http://www.cocoachina.com/iphonedev/toolthain/2011/1010/3342.html
The source code is shared by tanhaogg, a Forum member. The recording screen and sound effect functions are implemented.
because the recording screen function needs to be added to the project some time ago, like Tom, you can record and share the video.
I have never been familiar with audio and video, and this information is hard to find.
one of the foreign forums wrote a custom view called screencaptureview (the specific Code can be selected by Google ), the main principle is to regularly paint the screen, and then build audio files based on the key frame, but the efficiency is not very good, the actual work There are still many problems.
So I like to stand on the shoulders of giants and start YY from here. I wrote a thcapture Class Based on its principle (why do I always like the beginning of th, I really don't understand, haha). It is mainly used to set recording-related attributes,
In addition, there is a thcaptureutilities class, which currently provides a method to achieve the mixing of video and audio.
1. The following describes some of the methods:
Thcapture has three attributes:
Framerate is used to set the frame rate for recording. It is the number of frames recorded in a second.
Capturelayer is used to set the layer you want to record.
Delegate is Program Everyone understands
There are two recording-related methods
// Start recording
-(Bool) startrecording;
// End recording
-(Void) stoprecording;
Two recording callback Methods
// Recording successful
-(Void) recordingfinished :( nsstring *) outputpath;
// Recording failed
-(Void) recordingfaild :( nserror *) error;
2. The directory in the thcaptureutilities class has only one class method.
// The audio and video merging. Action format is as follows:
//-(Void) mergedidfinish :( nsstring *) videopath witherror :( nserror *) error;
+ (Void) mergevideo :( nsstring *) videopath andaudio :( nsstring *) audiopath andtarget :( ID) Target andaction :( SEL) action;
You can understand the role of this method based on the method name.
currently, the code can work well, but the recorded results are not very good and need to be optimized, it is expected that some performance optimizations will be provided by the following experts:
for convenience, I wrote an example to achieve that 10 seconds of video recording will be used and saved to the album, download, try out, and provide comments
Source codeDownload: Thscreencaptureviewtest_1.1.0_latest version. Zip (552 K)
Original post address: http://www.cocoachina.com/bbs/read.php? Tid-73869.html