API File | Description |
TXUGCRecord.h | Shooting videos |
TXUGCRecordListener.h | Shooting callbacks |
TXUGCRecordEventDef.h | Shooting events |
TXUGCRecordTypeDef.h | Definitions of basic parameters |
TXUGCPartsManager.h | Video segment management class, which is used for multi-segment shooting and segment deletion |
- (void)viewDidLoad {// Create a view to display camera preview_videoRecordView = [[UIView alloc] initWithFrame:self.view.bounds];[self.view addSubview:_videoRecordView];// 1. Configure recording parametersTXUGCSimpleConfig * param = [[TXUGCSimpleConfig alloc] init];param.videoQuality = VIDEO_QUALITY_MEDIUM;// 2. Start preview, set parameters and specify the view for preview[[TXUGCRecord shareInstance] startCameraSimple:param preview:_videoRecordView];// 3. Set recording effects (example: add beauty filter)TXBeautyManager *manager = [[TXUGCRecord shareInstance] getBeautyManager];[manager setBeautyStyle:TXBeautyStyleSmooth];[manager setBeautyLevel:5];// Set the delegate for video recording to receive progress and completion notifications[TXUGCRecord shareInstance].recordDelegate = self;// Start recording[[TXUGCRecord shareInstance] startRecord];。。。。。。// Stop recording[[TXUGCRecord shareInstance] stopRecord];}// Recording completion callback-(void) onRecordComplete:(TXUGCRecordResult*)result{if (result.retCode == UGC_RECORD_RESULT_OK) {// Recording succeeded. Video file is at result.videoPath} else {// Error handling. For error codes, refer to TXUGCRecordResultCode in TXUGCRecordTypeDef.h}}@end
TXUGCRecord
in TXUGCRecord.h
is used to implement video shooting. The first step of shooting videos is using startCameraSimplePreview
to enable preview. Because mic and camera permissions are required for preview, you need to configure pop-up windows to request the permissions.[TXUGCRecord shareInstance].recordDelegate = self; // Set recording callback (refer to TXUGCRecordListener for callback methods)// Configure camera and start previewTXUGCSimpleConfig *param = [[TXUGCSimpleConfig alloc] init];param.videoQuality = TXRecordCommon.VIDEO_QUALITY_HIGH; // 720pparam.frontCamera = YES; // Use front cameraparam.minDuration = 5; // Minimum recording duration: 5sparam.maxDuration = 60; // Maximum recording duration: 60sparam.touchFocus = NO; // NO: autofocus; YES: manual focus// Display camera preview in self.previewView[[TXUGCRecord shareInstance] startCameraSimple:param preview:self.previewView];// Stop camera preview[[TXUGCRecord shareInstance] stopCameraPreview];
// Switch video recording resolution to 540p (540x960)[[TXUGCRecord shareInstance] setVideoResolution: VIDEO_RESOLUTION_540_960];// Switch video bitrate to 6500 Kbps[[TXUGCRecord shareInstance] setVideoBitrate: 6500];// Set zoom level to 3.// Value 1: farthest view (normal lens); Value 5: closest view (zoomed-in lens)[[TXUGCRecord shareInstance] setZoom: 3];// Switch camera: YES for front camera, NO for rear camera[[TXUGCRecord shareInstance] switchCamera: NO];// Toggle flash: YES to turn on, NO to turn off[[TXUGCRecord shareInstance] toggleTorch: YES];// Set custom video processing callback delegate[TXUGCRecord shareInstance].videoProcessDelegate = delegate;
// Take a photo. Before calling this API, you must start the recording preview// by calling either `startCameraSimplePreview` or `startCameraCustomPreview`[[TXUGCRecord shareInstance] snapshot:^(UIImage *image) {// Process the captured image here}];
// Start recording.// This method does not specify the recording file path; the file path will be returned in the recording completion callback.[[TXUGCRecord shareInstance] startRecord];// Start recording with a specified output video file path and cover image path[[TXUGCRecord shareInstance] startRecord:videoFilePath coverPath:coverPath];// Start recording with a specified output video file path, video segments folder path, and cover image path[[TXUGCRecord shareInstance] startRecord:videoFilePath videoPartsFolder:videoPartFolder coverPath:coverPath];// Pause recording[[TXUGCRecord shareInstance] pauseRecord];// Resume recording[[TXUGCRecord shareInstance] resumeRecord];// Stop recording[[TXUGCRecord shareInstance] stopRecord];
TXUGCRecordListener
(defined in TXUGCRecordListener.h
).onRecordProgress
is the shooting progress callback. The millisecond
parameter indicates the recorded duration in milliseconds.@optional(void)onRecordProgress:(NSInteger)milliSecond;
onRecordComplete
is the shooting result callback. The retCode
and descMsg
fields in TXRecordResult
indicate the error code and error message respectively. videoPath
indicates the path of the video, and coverImage
is the first frame of the video, which is used as the thumbnail.@optional(void)onRecordComplete:(TXUGCRecordResult*)result;
onRecordEvent
is the callback reserved for the shooting event and is not used currently.@optional(void)onRecordEvent:(NSDictionary*)evt;
// Set orientation for preview// The valid values for `rotation` are 0, 90, 180, and 270, which indicate the clockwise rotation angle.// You must set the rotation before you call `startRecord` for the setting to take effect.[[TXUGCRecord shareInstance] setRenderRotation:rotation];// Set the aspect ratio// VIDEO_ASPECT_RATIO_9_16: 9:16// VIDEO_ASPECT_RATIO_3_4: 3:4// VIDEO_ASPECT_RATIO_1_1: 1:1// You must set the rotation before you call `startRecord` for the setting to take effect.[[TXUGCRecord shareInstance] setAspectRatio:VIDEO_ASPECT_RATIO_9_16];
// Set the shooting speed// VIDEO_RECORD_SPEED_SLOWEST: Very slow// VIDEO_RECORD_SPEED_SLOW: Slow// VIDEO_RECORD_SPEED_NOMAL: Original// VIDEO_RECORD_SPEED_FAST: Fast// VIDEO_RECORD_SPEED_FASTEST: Very fast[[TXUGCRecord shareInstance] setRecordSpeed:VIDEO_RECORD_SPEED_NOMAL];
// Set the mic volume. This is used to control the volume of the mic when background music is mixed.// Volume. The normal volume is 1. We recommend 0-2, but you can set it to a larger value if you want louder music.[[TXUGCRecord shareInstance] setMicVolume:volume];// Mute/Unmute. The `isMute` parameter specifies whether to mute audio. Audio is unmuted by default.[[TXUGCRecord shareInstance] setMute:isMute];
// Add a global watermark// normalizationFrame: The normalized position of the watermark in relation to the video. The SDK calculates the watermark height based on the aspect ratio.// Suppose the video dimensions are 540 x 960, and `frame` is set to `(0.1,0.1,0.1, 0)`.// The actual coordinates of the watermark would be:// (540*0.1, 960*0.1, 540*0.1, 540*0.1*waterMarkImage.size.height / waterMarkImage.size.width)[[TXUGCRecord shareInstance] setWaterMark:waterMarkImage normalizationFrame:frame)
// Set the filter style// Set the color filter: Romantic, refreshing, elegant, pink, retro, and more// filterImage: The color lookup table, which must be in PNG format.// The color lookup table used in the demo is in `FilterResource.bundle`.[[TXUGCRecord shareInstance] setFilter:filterImage];// Set the strength of filters. Value range: 0-1. Default: 0.5. The greater the value, the stronger the filter.[[TXUGCRecord shareInstance] setSpecialRatio:ratio];// Set a filter combination// mLeftBitmap: The left filter// leftIntensity: The strength of the left filter// mRightBitmap: The right filter// rightIntensity: The strength of the right filter// leftRatio: The ratio of the width of the left picture to the video width// You can use this API to implement "swipe to change filter".[[TXUGCRecord shareInstance] setFilter:leftFilterImgage leftIntensity:leftIntensity rightFilter:rightFilterImgage rightIntensity:rightIntensity leftRatio:leftRatio];
// Access Beauty Configuration InterfaceTXBeautyManager *manager = [[TXUGCRecord shareInstance] getBeautyManager];// Set beauty style: (TXBeautyStyleSmooth: Smooth; TXBeautyStyleNature: Natural; TXBeautyStylePitu: Pitu)[manager setBeautyStyle:TXBeautyStyleSmooth];// Set beauty level (0-9)[manager setBeautyLevel:5];// Set whitening level (0-9)[manager setWhitenessLevel:5];// Set rosy level (0-9)[manager setRuddyLevel:5];