78.1.1+
TruvideoSdkVideoFile
Represents an existing file in your file system. It is used to indicate to the SDK a file to use.
TruvideoSdkVideoFile.cache(fileName, fileExtension)
Used to point to a file that is inside the "cache" directory of the Android file system assigned to the application.
Example:
TruvideoSdkVideoFile.cache("video", "mp4");
TruvideoSdkVideoFile.cache("dir/subdir/video", "mp4");
TruvideoSdkVideoFile.files(fileName, fileExtension)
Used to point to a file that is inside the "files" directory of the Android file system assigned to the application.
Example:
TruvideoSdkVideoFile.files("video", "mp4");
TruvideoSdkVideoFile.files("dir/subdir/video", "mp4");
TruvideoSdkVideoFile.custom(filePath)
Used to point to a file by passing the file path.
Example:
TruvideoSdkVideoFile.custom("video.mp4");
TruvideoSdkVideoFile.custom("dir/subdir/video.mp4");
TruvideoSdkVideoFile.fromFile(file)
Used to point to a file using the AndroidFile
object.
Example:
TruvideoSdkVideoFile.fromFile(File("dir/subdir/video.mp4"));
TruvideoSdkVideoFileDescriptor
Represents a file that does not exist but is desired to be created by the SDK
for you. The main difference with TruvideoSdkVideoFile
is that when using this object, the file extension is not required (nor should it be sent). It is used to describe where and with what name the file will be created by the TruvideoSdkVideoModule
.
TruvideoSdkVideoFileDescriptor.cache(fileName)
Used to point to a file inside thecache
directory of the Android file system assigned to the application.
Example:
TruvideoSdkVideoFileDescriptor.cache("video_result");
TruvideoSdkVideoFileDescriptor.cache("dir/suybdir/video_result");
TruvideoSdkVideoFileDescriptor.files(fileName)
Used to point to a file inside the
files
directory of the Android file system assigned to the application.
Example:
TruvideoSdkVideoFileDescriptor.files("video");
TruvideoSdkVideoFileDescriptor.files("dir/subdir/video");
TruvideoSdkVideoFileDescriptor.custom(filePath)
Used to point to a file by passing the file path.
Example:
TruvideoSdkVideoFileDescriptor.custom("result");
TruvideoSdkVideoFileDescriptor.custom("dir/subdir/result");
TruvideoSdkVideoFileDescriptor.fromFile(file)
Used to point to a file using the AndroidFile
object.
Example:
TruvideoSdkVideoFileDescriptor.fromFile(File("dir/subdir/video"));
Video Information
getInfo(input)
: this function provides video info such as resolution, duration, codec information, and relevant metadata.
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void getVideoInfo(TruvideoSdkVideoFile input) {
// Get video info as TruvideoSdkVideoInformation
TruvideoSdkVideo.getInstance().getInfo(input, new TruvideoSdkVideoCallback<TruvideoSdkVideoInformation>() {
@Override
public void onComplete(@NonNull TruvideoSdkVideoInformation result) {
// Handle video information
int duration = result.getDurationMillis();
int width = result.getWidth();
int height = result.getHeight();
String videoCodec = result.getVideoCodec();
String audioCodec = result.getAudioCodec();
int rotation = result.getRotation();
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error
}
});
}
Compare Video
compare(input)
: this function compares multiple videos and returns the boolean accordingly as the concat video needs to have the same characteristics i.e. if the boolean is true videos are compatible with concat otherwise not compatible videos need to merge in that case.
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void compare(List<TruvideoSdkVideoFile> input) {
TruvideoSdkVideo.getInstance().compare(input, new TruvideoSdkVideoCallback<Boolean>() {
@Override
public void onComplete(Boolean result) {
// Handle result
// result is true if the videos are compatible to be concatenated, otherwise false
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error
exception.printStackTrace();
}
});
}
Edit Video
Edit consists of 2 steps initialize and the edit will open the screen to edit the video
ActivityResultLauncher<TruvideoSdkVideoEditParams>
: On Android, the SDK needs to be initialized to function properly. To achieve this, you should add the following code snippet inside the onCreate method of the activity that will invoke the video edit, it returns theTruvideoSdkVideoEditScreen
instance.
import com.truvideo.sdk.camera.TruvideoSdkCamera;
public class EditVideoJavaActivity extends ComponentActivity {
private ActivityResultLauncher<TruvideoSdkVideoEditParams> editVideoLauncher;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editVideoLauncher = registerForActivityResult(new TruvideoSdkVideoEditContract(), resultPath -> {
// edited video its on 'resultPath'
});
}
}
launch(input,output)
: After the module is initialized, you can invoke this method for video editing using the following approach.
This will return the path as a result when the file is ready
import com.truvideo.sdk.media.TruvideoSdkVideo;
import com.truvideo.sdk.video.interfaces.TruvideoSdkVideoEditCallback;
private void editVideo(TruvideoSdkVideoFile input, TruvideoSdkVideoFileDescriptor output) {
editVideoLauncher.launch(new TruvideoSdkVideoEditParams(input, output));
}
Thumbnail Generation
Preview of video is crucial, thumbnail generation gives you the preview image from the timeframe you need.
createThumbnail(input,output,position,width,height)
: this method takes the video path, result path, position, width, and height as input and places the image at the resulting path.
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void createThumbnail(TruvideoSdkVideoFile input, TruvideoSdkVideoFileDescriptor output) {
TruvideoSdkVideo.getInstance().createThumbnail(
input,
output,
1000, // position
300, // width, can be null
300, // height, can be null
false, // precise
new TruvideoSdkVideoCallback<String>() {
@Override
public void onComplete(@NonNull String resultPath) {
// Handle result
// the thumbnail is stored at resultPath
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error
exception.printStackTrace();
}
}
);
}
Clean noise
We are utilizing high-level Artificial intelligence for noise cancellation over the input video. It’s useful for video containing background noises.
clearNoise(input,output)
: This function takes the video path, and result path, and places a new video to the resulting path after clearing noise.
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void clearNoise(TruvideoSdkVideoFile input, TruvideoSdkVideoFileDescriptor output) {
// Clean noise from video and save to resultPath
TruvideoSdkVideo.getInstance().clearNoise(
input,
output,
new TruvideoSdkVideoCallback<String>() {
@Override
public void onComplete(String resultVideoPath) {
// Handle result
// Cleaned video is stored in resultVideoPath
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle rror
exception.printStackTrace();
}
}
);
}
Concat Videos
ConcatBuilder(input,output)
: Concatenation uses a specific algorithm to merge multiple videos one after another to make one video efficiently and make a completely new video. This method takes the video URIs list, and result path to place a new video and place the video at the given result path.
Note:
1. There are certain restrictions for concat to work, all the provided videos should be of the same character such as resolution, audio codec, video codec, pixel format, and many more. The difference could raise an exception.
2. To check whether videos are compatible use compare method first given above.
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void concatVideos(List<TruvideoSdkVideoFile> input, TruvideoSdkVideoFileDescriptor output) {
TruvideoSdkVideoConcatBuilder builder = TruvideoSdkVideo.getInstance().ConcatBuilder(input, output);
builder.build(new TruvideoSdkVideoCallback<TruvideoSdkVideoRequest>() {
@Override
public void onComplete(@NonNull TruvideoSdkVideoRequest request) {
// Request ready
// Send to process
request.process(new TruvideoSdkVideoCallback<String>() {
@Override
public void onComplete(String resultPath) {
// Handle result
// the concated video its on 'resultPath'
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error concating videos
exception.printStackTrace();
}
});
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error creating request
exception.printStackTrace();
}
});
}
Merge Videos
MergeBuilder(input,output)
: Merge has the same functionality as concat to merge multiple videos to make one another video but there is an advantage over concat to merge all video does not have to be of same configuration.This method takes video URIs list, and result path to place a new video and place the video at the given result path.
Note:
1 Any type of video resolution can be merged no exception will occur
2 Unlike concat this method involves reencoding the input videos, making it less performant, and processing time may be considerable (depending on the device's processing power).
3 It automatically calculates the resulting video resolution to ensure that all input videos can be displayed correctly
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void mergeVideos(List<TruvideoSdkVideoFile> input, TruvideoSdkVideoFileDescriptor output) {
TruvideoSdkVideoMergeBuilder builder = TruvideoSdkVideo.getInstance().MergeBuilder(input, output);
// Set custom video resolution
// builder.setWidth(1000);
// builder.setHeight(1000);
builder.build(new TruvideoSdkVideoCallback<TruvideoSdkVideoRequest>() {
@Override
public void onComplete(@NonNull TruvideoSdkVideoRequest request) {
// Request ready
// Send to process
request.process(new TruvideoSdkVideoCallback<String>() {
@Override
public void onComplete(String resultPath) {
// Handle result
// the merged video its on 'resultPath'
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error merging the videos
exception.printStackTrace();
}
});
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error creating the request
exception.printStackTrace();
}
});
}
Encode Video
This function constructs a TruvideoSdkVideoRequest
to carry out an encoding operation. This operation enables modifications to a video by altering one or more of its attributes, such as:
Resolution via width and height parameters
Video codec (options: .h264, .h265)
Audio codec (options: .aac, .mp3, .ac3)
Frame rate (options: 24fps, 25fps, 30fps, 50fps, 60fps)
import com.truvideo.sdk.media.TruvideoSdkVideo;
public void encodeVideo(TruvideoSdkVideoFile input, TruvideoSdkVideoFileDescriptor output) {
TruvideoSdkVideoEncodeBuilder builder = TruvideoSdkVideo.getInstance().EncodeBuilder(input, output);
// Set custom video resolution
// builder.setWidth(1000);
// builder.setHeight(1000);
builder.build(new TruvideoSdkVideoCallback<TruvideoSdkVideoRequest>() {
@Override
public void onComplete(@NonNull TruvideoSdkVideoRequest request) {
// Request ready
// Send to process
request.process(new TruvideoSdkVideoCallback<String>() {
@Override
public void onComplete(String resultPath) {
// Handle result
// the merged video its on 'resultPath'
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error merging the videos
exception.printStackTrace();
}
});
}
@Override
public void onError(@NonNull TruvideoSdkException exception) {
// Handle error creating the request
exception.printStackTrace();
}
});
}
Last updated
Was this helpful?