tencent cloud


Last updated: 2022-05-24 15:45:26

    Video shoot includes features such as adjustable-speed shoot, beauty filters, filters, sound effects, and background music configuration.

    Overview of Relevant Classes

    Class Feature
    TXUGCRecord Video shoot implementation
    TXUGCPartsManager Video segment management class, which is used to shoot multiple video segments and delete existing segments
    ITXVideoRecordListener Shoot callback
    TXRecordCommon Basic parameter definition, including video shoot callback and release callback APIs

    Use Instructions

    The following is the basic usage process of video shoot:

    1. Configure the shoot parameters.
    2. Start video image preview.
    3. Set the shoot effects.
    4. Complete shoot.

    Code Example

    // Create `TXCloudVideoView` for camera preview
    mVideoView = (TXCloudVideoView) findViewById(R.id.video_view);
    // 1. Configure the shoot parameters. The recommended configuration of `TXUGCSimpleConfig` is used here as an example
    TXRecordCommon.TXUGCSimpleConfig param = new TXRecordCommon.TXUGCSimpleConfig();
    param.videoQuality = TXRecordCommon.VIDEO_QUALITY_MEDIUM;
    // 2. Start video image preview
    mTXCameraRecord.startCameraSimplePreview(param, mVideoView);
    // 3. Set the shoot effects. Watermarking is used here as an example
    TXVideoEditConstants.TXRect rect = new TXVideoEditConstants.TXRect();
    rect.x = 0.5f;
    rect.y = 0.5f;
    rect.width = 0.5f;
    mTXCameraRecord.setWatermark(BitmapFactory.decodeResource(getResources(), R.drawable.watermark), rect);
    // 4. Start shoot
    int result = mTXCameraRecord.startRecord();
    if (result != TXRecordCommon.START_RECORD_OK) {
               if (result == -4) {The video image has not been displayed yet} 
               else if (result == -3) {// The version is too low}
        else if (result == -5) {// License verification failed] }
    else{// Started successfully}
    // End shoot
    // Callback for shoot completion
    public void onRecordComplete(TXRecordCommon.TXRecordResult result) {
    if (result.retCode >= 0 ) {
        // The shoot is successful, and the video file is in `result.videoPath`
        // Process the error. For the error code definition, please see "Definition of error codes for shoot result callback" in `TXRecordCommon`.

    Previewing Video Image

    TXUGCRecord (in TXUGCRecord.java) is used for short video shoot. The preview feature needs to be implemented first, where the startCameraSimplePreview function is used to start preview. As camera and mic need to be enabled before the preview can be started, prompt windows for permission application may pop up at this point.

    1. Start preview

    TXUGCRecord mTXCameraRecord = TXUGCRecord.getInstance(this.getApplicationContext());
    mTXCameraRecord.setVideoRecordListener(this);                    // Set shoot callback
    mVideoView = (TXCloudVideoView) findViewById(R.id.video_view);    // Prepare a view for camera image preview
    TXRecordCommon.TXUGCSimpleConfig param = new TXRecordCommon.TXUGCSimpleConfig();
    //param.videoQuality = TXRecordCommon.VIDEO_QUALITY_LOW;        // 360p
    //param.videoQuality = TXRecordCommon.VIDEO_QUALITY_MEDIUM;        // 540p
    param.videoQuality = TXRecordCommon.VIDEO_QUALITY_HIGH;        // 720p
    param.isFront = true;           // Whether to use the front camera
    param.minDuration = 5000;    // Minimum video shoot duration in milliseconds
    param.maxDuration = 60000;    // Maximum video shoot duration in milliseconds
    param.touchFocus = false; // false: autofocus; true: manual focus
    // End video image preview

    2. Adjust preview parameters

    After starting the camera, you can adjust the preview parameters as follows:

    // Switch the video shoot resolution to 540p
    // Switch the video shoot bitrate to 6,500 Kbps
    // Get the maximum focal length supported by the camera
    // Set the focal length to 3. 1 indicates the furthest view (normal lens), and 5 indicates the nearest view (enlarging lens)
    // Switch to the rear camera. true: switches to front camera; false: switches to rear camera
    // Enable the flash. true: enables; false: disables
    // If `param.touchFocus` is `true`, manual focus will be used. You can use the following API to set the focus position
    mTXCameraRecord.setFocusPosition(eventX, eventY);
    // Set the callback for custom image processing


    After enabling the camera preview, you can use the photo capturing feature.

    // Photo capturing, which will take effect if called after `startCameraSimplePreview` or `startCameraCustomPreview`
    mTXCameraRecord.snapshot(new TXRecordCommon.ITXSnapshotListener() {
                  public void onSnapshot(Bitmap bmp) {
                      // Save or display the photo

    Controlling Shoot Process

    The shoot can be started, paused, and resumed as follows:

    // Start shoot
    // Start shoot. You can specify the addresses for the output video file and cover
    mTXCameraRecord.startRecord(videoFilePath, coverPath);
    // Start shoot. You can specify the addresses for the output video file, video segment storage, and cover
    mTXCameraRecord.startRecord(videoFilePath, videoPartFolder, coverPath);
    // Pause shoot
    // Resume shoot
    // End shoot

    The shoot process and result will be returned through the TXRecordCommon.ITXVideoRecordListener API (defined in TXRecordCommon.java):

    • onRecordProgress returns the shoot progress, and the millisecond parameter indicates the shoot duration in milliseconds.
      void onRecordProgress(long milliSecond);
    • onRecordComplete returns the shoot result, the retCode and descMsg fields of TXRecordResult indicate the error code and error message, respectively, videoPath indicates the path of the shot short video file, and coverImage indicates the short video's first-frame image that is automatically captured and will be used in video release.
      void onRecordComplete(TXRecordResult result);
    • onRecordEvent is the shoot event callback, which contains the event ID and event-related parameters in the format of (key,value).
      void onRecordEvent(final int event, final Bundle param);

    Setting Shoot Attributes

    Set the video image

    // Set the landscape or portrait mode for shoot
    // Set the video preview direction
    // TXLiveConstants.RENDER_ROTATION_0 (normal portrait) 
    // TXLiveConstants.RENDER_ROTATION_90 (rotated 90 degrees leftwards) 
    // TXLiveConstants.RENDER_ROTATION_180 (rotated 180 degrees leftwards) 
    // TXLiveConstants.RENDER_ROTATION_270 (rotated 270 degrees leftwards) 
    // Note: it needs to be set before `startRecord` and will not take effect if set during shoot
    // Set the aspect ratio for shoot
    // TXRecordCommon.VIDEO_ASPECT_RATIO_9_16   The aspect ratio is 9:16
    // TXRecordCommon.VIDEO_ASPECT_RATIO_3_4   The aspect ratio is 3:4
    // TXRecordCommon.VIDEO_ASPECT_RATIO_1_1   The aspect ratio is 1:1
    // Note: it needs to be set before `startRecord` and will not take effect if set during shoot

    Set the speed

    // Set the video shoot speed
    // TXRecordCommon.RECORD_SPEED_SLOWEST (ultra-slow) 
    // TXRecordCommon.RECORD_SPEED_SLOW (slow) 
    // TXRecordCommon.RECORD_SPEED_NORMAL (standard) 
    // TXRecordCommon.RECORD_SPEED_FAST (fast) 
    // TXRecordCommon.RECORD_SPEED_FASTEST (ultra-fast) 

    Set the audio

    // Set the mic volume level. It is used to adjust the mic volume level when background music is played back
    // Volume level. 1 indicates the normal volume level. The recommended value range is 02. If you want to increase the volume level, you can set a higher value
    // Set whether the shoot is muted in the `isMute` parameter. The shoot is unmuted by default

    Setting Effects

    During video shoot, you can set various special effects for the shot video.


    // Set a global watermark
    // TXRect: normalized value of watermark relative to video image. The SDK will automatically calculate the `height` according to the watermark aspect ratio
    // Suppose the video image dimensions are (540, 960), and three parameters in `TXRect` are all set to 0.1
    // Then, the actual pixel coordinates of the watermark are (540 * 0.1, 960 * 0.1, 540 * 0.1)
    // 540 * 0.1 * watermarkBitmap.height / watermarkBitmap.width)
    mTXCameraRecord.setWatermark(watermarkBitmap, txRect)


    // Set the color filter to Romantic, Fresh, Aesthetic, Rosy, Vintage, etc.
    // filterBitmap: color lookup table used for filter. Note: it must be in .png format
    // The filter color lookup table used by the demo is in the `RTMPAndroidDemo/app/src/main/res/drawable-xxhdpi/` directory
    // Set the filter mix effect
    // mLeftBitmap   Filter on the left
    // leftIntensity   Level of the filter on the left
    // mRightBitmap   Filter on the right
    // rightIntensity   Level of the filter on the right
    // leftRadio   Ratio of the dimensions of the image on the left
    // You can use this API to implement the effect of switching filters by swipe. For more information, please see the demo
    mTXCameraRecord.setFilter(mLeftBitmap, leftIntensity, mRightBitmap, rightIntensity, leftRatio);
    // It is used to set the filter effect level. Value range: 0–1. The greater the value, the more obvious the effect. Default value: 0.5

    Beauty filter

    // Set the beauty filter type
    // Set the eye enlarging effect level. Recommended value range: 0–9. If you want a more obvious effect, you can set a greater value
    // Set the face slimming effect level. Recommended value range: 0–9. If you want a more obvious effect, you can set a greater value
    // Set the chin slimming effect level. Recommended value range: 0–9. If you want a more obvious effect, you can set a greater value
    // Set the chin lengthening/shortening effect level. Recommended value range: 0–9. If you want a more obvious effect, you can set a greater value
    // Set the face shortening effect level. Recommended value range: 0–9. If you want a more obvious effect, you can set a greater value
    // Set the nose narrowing effect level. Recommended value range: 0–9. If you want a more obvious effect, you can set a greater value
    // Set the green screen keying file. It can be in formats supported by Android, such as .jpg and .png for images and .mp4 and .3gp for videos, and can be looped
    mTXCameraRecord.setGreenScreenFile(path, isLoop);
    // Set `motionTmplPath`, which is the path of the animated effect file of the animated sticker. An empty string ("") indicates to cancel the animated effect
    // Set whether to mute the animated sticker. true: mutes; false: unmutes

    Getting License Information

    UGSV license verification is added in the new version of the SDK. If the verification fails, you can use the following API to query the specific information in the license:

    TXUGCBase.getInstance().getLicenceInfo(Context context);

    Advanced Features

    Multi-segment shoot
    Shoot drafts
    Adding background music
    Voice changing and reverb
    Customizing video data

    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 avaliable.

    7x24 Phone Support