The customizable parameters of short video shooting include frame rate (number of frames per second), GOP length (number of seconds between key I frames), video bitrate (volume of audio/video data generated by the encoder per second), and maximum/minimum shooting duration. We offer 4 shooting resolutions as constants for your choice: 360 × 640, 540 × 960, 720 × 1280, and 1080 × 1920.
The following describes why the shooting resolution is set as a constant instead of a variable:
You can call the startCameraCustomPreview
API of the TXUGCRecord
class to pass in custom shooting parameters, as shown below:
// Custom configuration
TXRecordCommon.TXUGCCustomConfig customConfig = new TXRecordCommon.TXUGCCustomConfig();
customConfig.videoResolution = TXRecordCommon.VIDEO_RESOLUTION_540_960;
customConfig.minDuration = mMinDuration; // Minimum duration
customConfig.maxDuration = mMaxDuration; // Maximum duration
customConfig.videoBitrate = mBiteRate; // Video bitrate
customConfig.videoGop = mGop; // GOP length
customConfig.videoFps = mFps; // Frame rate in fps
customConfig.isFront = mFront; // Whether to use the front camera
mTXCameraRecord.startCameraCustomPreview(customConfig, mVideoView);
onRecordComplete
callback after shooting ends on Android?Before shooting a short video, please call the setVideoRecordListener()
API of the TXUGCRecord
class to set a listener for the shooting callback.
To end shooting, you need to call the stopRecord()
API of the TXUGCRecord
class.
// Before shooting
mTXCameraRecord = TXUGCRecord.getInstance(this.getApplicationContext());
mTXCameraRecord.setVideoRecordListener(this);
...
// End shooting
mTXCameraRecord.stopRecord();
If you call stopRecord
, the video segments shot will be spliced, so after the onRecordComplete
callback is received, the demo will call mTXCameraRecord.getPartsManager().deleteAllParts()
to delete the segment files.
If shooting is interrupted, and you want to resume shooting from where you stopped, do not call mTXCameraRecord.getPartsManager().deleteAllParts()
.
@Override
public void onRecordComplete(TXRecordCommon.TXRecordResult result) {
TXCLog.i(TAG, "onRecordComplete, result retCode = " + result.retCode + ", descMsg = " + result.descMsg + ", videoPath + " + result.videoPath + ", coverPath = " + result.coverPath);
if (mTXRecordResult.retCode < 0) {
Toast.makeText(TCVideoRecordActivity.this.getApplicationContext(), "Shoot failed. Cause: " + mTXRecordResult.descMsg, Toast.LENGTH_SHORT).show();
} else {
mDuration = mTXCameraRecord.getPartsManager().getDuration(); // Total shooting duration
if (mTXCameraRecord != null) {
mTXCameraRecord.getPartsManager().deleteAllParts(); // Delete the video segments already shot
}
startPreview(); // Enter the preview page
}
You must set the background music before calling the shooting API (startRecord
of TXUGCRecord
) so that the settings can take effect. The call sequence in the code is as shown below:
TXRecordCommon.TXUGCSimpleConfig simpleConfig = new TXRecordCommon.TXUGCSimpleConfig();
simpleConfig.videoQuality = TXRecordCommon.VIDEO_QUALITY_MEDIUM;
simpleConfig.minDuration = mMinDuration;
simpleConfig.maxDuration = mMaxDuration;
// 1. Start the preview first
mTXCameraRecord.startCameraSimplePreview(simpleConfig, mVideoView);
// 2. Specify the path of the background music file and play the music
mBGMDuration = mTXCameraRecord.setBGM(mBGMPath);
mTXCameraRecord.playBGMFromTime(0, mBGMDuration);
// 3. Start shooting (`customVideoPath`: The path of the video generated. `customPartFolder`: The folder of the video segments shot. `customCoverPath`: The path of the thumbnail.)
int result = mTXCameraRecord.startRecord(customVideoPath, customPartFolder, customCoverPath);
You can call the snapshot
API of the TXUGCRecord
class to take a photo, which will be returned asynchronously through the TXRecordCommon.ITXSnapshotListener
callback. The sample code is as follows:
private void snapshot() {
if (mTXCameraRecord != null) {
mTXCameraRecord.snapshot(new TXRecordCommon.ITXSnapshotListener() {
@Override
public void onSnapshot(Bitmap bmp) {
// Captured photo
saveBitmap(bmp);
}
});
}
}
You cannot customize speed for shooting.
Definition | Constant in TXRecordCommon | Speed |
---|---|---|
Ultra-slow | RECORD_SPEED_SLOWEST | 0.5x |
Slow | RECORD_SPEED_SLOW | 0.8x |
Standard | RECORD_SPEED_NORMAL | 1x |
Fast | RECORD_SPEED_FAST | 1.25x |
Ultra-fast | RECORD_SPEED_FASTEST | 1.5x |
You can call setRecordSpeed(record)
of TXUGCRecord
to set the speed for shooting.
mTXCameraRecord.setRecordSpeed(TXRecordCommon.RECORD_SPEED_FAST);
Currently, you can import only MP4 video files on Android. There are no limits on the resolution or size of imported files.
Currently, only MP3 and M4A files are supported.
Editing supports custom video bitrate (in SDK 4.5 or later) and audio bitrate (in SDK 4.7 or later). For the resolution, you can choose from five constants: 360 × 640, 480 × 640, 540 × 960, 720 × 1280, and 1080 × 1920.
Resolution | Constant in TXVideoEditConstants |
---|---|
360 × 640 | VIDEO_COMPRESSED_360P |
480 × 640 | VIDEO_COMPRESSED_480P |
540 × 960 | VIDEO_COMPRESSED_540P |
720 × 1280 | VIDEO_COMPRESSED_720P |
1080 × 1920 | VIDEO_COMPRESSED_1080P |
// Set the output video bitrate
mTXVideoEditer.setVideoBitrate(3600);
// Set the output resolution
mTXVideoEditer.generateVideo(TXVideoEditConstants.VIDEO_COMPRESSED_720P, mVideoOutputPath);
Currently, the SDK does not support recording background music and human voice at the same time. Therefore, to change the background music during editing, just set the volume of the original audio to 0. See the code below for detailed directions:
// Set the original audio to 0 to remove the recorded background music
mTXVideoEditer.setVideoVolume(0.0f);
// Specify the local path of the background music to use
String bgmPath = getBGMPath();
mTXVideoEditer.setBGM(bgmPath);
// Set the volume of the background music. Value range: 0.0f-1.0f
mTXVideoEditer.setBGMVolume(1.0f);
Activity
window and the full screen mode to display the preview image?You need to dynamically modify the dimensions of the parent layout for the video preview view passed in to the SDK. The SDK will internally adjust the video dimensions dynamically according to the video width and height and the parent layout dimensions.
The APIs of the SDK need to be called in the following sequence:
Call stopPlay
first, modify the width and height of FrameLayout
passed in to the SDK, call initWithPreview(parm)
, pass in the new FrameLayout
, and call startPlay
again.
// Stop playback
mTXVideoEditer.stopPlay();
if (isFullScreen) {
// If the full screen mode is used, you can use the following code to switch to the window mode
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1500);
mVideoPlayerLayout.setLayoutParams(params);
initPlayerLayout(false);
isFullScreen = false;
} else {
// If the window mode is used, you can use the following code to switch to the full screen mode
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mVideoPlayerLayout.setLayoutParams(params);
initPlayerLayout(false);
isFullScreen = true;
}
// Start playback
mTXVideoEditer.startPlayFromTime(startTime, endTime);
// Set the preview view
private void initPlayerLayout(boolean isFullScreen) {
TXVideoEditConstants.TXPreviewParam param = new TXVideoEditConstants.TXPreviewParam();
param.videoView = mVideoPlayerLayout;
if (isFullScreen) {
param.renderMode = TXVideoEditConstants.PREVIEW_RENDER_MODE_FILL_SCREEN;
} else {
param.renderMode = TXVideoEditConstants.PREVIEW_RENDER_MODE_FILL_EDGE;
}
mTXVideoEditer.initWithPreview(param);
}
You can clip (setCutTimeFrom
) and preprocess (processVideo
) a video first. Then, you can edit the clipped and preprocessed video. After editing, set the clipping duration (setCutTimeFrom
) to the total duration of the edited video, and call generateVideo
to generate the video. This can avoid reduced image quality caused by two compressions.
Note:Before generating the final video, make sure you set the clipping duration to the total duration of the processed and clipped video. Otherwise, the video will be clipped again.
// Clipping page
mTXVideoEditer = new TXVideoEditer(mContext);
mTXVideoEditer.setCutFromTime(mTCVideoEditView.getSegmentFrom(), mTCVideoEditView.getSegmentTo());
mTXVideoEditer.processVideo();
// Set the clipping duration to the entire video duration (`setCutTimeFrom`)
mTXVideoEditer.setCutFromTime(0, mVideoDuration);
// Redirect to the special effects page for generation
mTXVideoEditer.generateVideo(TXVideoEditConstants.VIDEO_COMPRESSED_720P, mVideoOutputPath);
You can use the armeabi and armeabi-v7a architectures.
As shown above, set abiFilters
to armeabi
in build.gradle
in app
.
Because all Tencent Cloud media SDKs use the same underlying modules, the duplicate symbol error occurs if you integrate two or more SDKs into your project.
To avoid the problem, instead of integrating two SDKs, we recommend you use the All-in-One SDK.
Platform | ZIP File | GitHub | 64-bit Support | Size | Downsizing Installation Package |
---|---|---|---|---|---|
iOS | Download | GitHub | Yes | 4.08 MB (arm64) | Document |
Android | Download | GitHub | Yes | jar: 1.5 MB so (armeabi): 6.5 MB so (armv7): 6.1 MB so (arm64): 7.3 MB |
Document |
build.gradle
of app
to the name of the AAR file in /libs
of your project. Then, clean your project and build it again.If you don’t have a license, please buy one first. The UGSV SDK comes in Lite edition and Standard edition.
In UGSV, video playback is based on the UGSV player. You need to write your own code for progress bar. For detailed directions, see Player SDK - Playback progress.
Was this page helpful?