tencent cloud

All product documents
User Generated Short Video SDK
Last updated: 2025-04-01 17:14:08
iOS
Last updated: 2025-04-01 17:14:08
You can implement video shooting features including speed change, beautification, filters, audio effects, and background music.

Overview of Relevant Classes

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

Basic Workflow

1. Configure shooting parameters.
2. Enable preview.
3. Set shooting effects.
4. End shooting.
Basic code example for starting preview/recording(The following snippet demonstrates the core logic; implement the full code as needed):
- (void)viewDidLoad {
// Create a view to display camera preview
_videoRecordView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:_videoRecordView];

// 1. Configure recording parameters
TXUGCSimpleConfig * 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

Preview

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.

1. Start Preview

[TXUGCRecord shareInstance].recordDelegate = self; // Set recording callback (refer to TXUGCRecordListener for callback methods)

// Configure camera and start preview
TXUGCSimpleConfig *param = [[TXUGCSimpleConfig alloc] init];
param.videoQuality = TXRecordCommon.VIDEO_QUALITY_HIGH; // 720p
param.frontCamera = YES; // Use front camera
param.minDuration = 5; // Minimum recording duration: 5s
param.maxDuration = 60; // Maximum recording duration: 60s
param.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];

2. Modify Preview Parameters

To modify preview parameters after the camera is turned on, refer to the code below:
// 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;

Photo Capture

After starting the camera preview, you can use the photo capture functionality.
// 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
}];

Shooting Control

The shoot can be started, paused, and resumed as follows:
// 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];
The shooting progress and result callbacks are implemented by 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;

Shooting Settings

1. Video Image

// 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];

2. Speed

// 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];

3. Audio

// 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];

Effects

You can add various effects to your video during shooting.

1. Watermarks

// 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)

2. Filters

// 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];

3. Beauty

// Access Beauty Configuration Interface
TXBeautyManager *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];

Advanced Features

Drafts
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon