Video
Import the following dependency in your file, here you will use these function.
import {
getVideoInfo,
MergeBuilder,
getResultPath,
editVideo,
compareVideos,
ConcatBuilder,
EncodeBuilder,
generateThumbnail,
cleanNoise,
FrameRate
} from 'truvideo-react-video-sdk';
Video Information
The
TruVideoVideoSdk
has agetVideoInfo
function provides video info such as resolution, duration, codec information and relevant metadata.
try {
// call video info function
const videoInfo : MediaInfo = await getVideoInfo(filePath);
console.log('Video info:', videoInfo);
} catch (error) {
console.error('Error fetching video info:', error);
}
MediaInfo Type
interface MediaInfo {
path : string;
size : number;
durationMillis : number;
format : string;
videoTracks : VideoTrack[];
audioTracks : AudioTrack[];
}
interface VideoTrack {
index : string;
width : string;
height : string;
rotatedWidth : string;
rotatedHeight : string;
codec : string;
codecTag : string;
pixelFormat : string;
bitrate : string;
frameRate : string;
rotation : string;
durationMillis : string;
}
interface AudioTrack {
index: string;
bitrate: string;
sampleRate: string;
channels: string;
codec: string;
codecTag: string;
durationMillis: string;
channelLayout: string;
sampleFormat: string;
}
Compare Video
The
TruVideoVideoSdk
has acompareVideos
function compare multiple videos and returns the boolean accordingly as the concat video needs to have the same characteristics i.e it return true videos are compatible with concat not.
try {
// call compare function
const result : Boolean = await compareVideos(filePaths);
// handle result
console.log('Comparison result:', result);
return result;
} catch (error) {
// handle error
console.error('Error comparing videos:', error);
return false;
}
Edit Video
The TruVideoVideoSdk
has a editVideo
function that takes a filePath & resulthPath
try {
// get result path to where to save
const resultPath : string = await getResultPath(`${Date.now()}-editVideo`);
// handle result
// return result is path where video is saved
const result = await editVideo(filePath, resultPath);
console.log('Video edited successfully:', result);
} catch (error) {
// handle error
console.error('Error editing video:', error);
}
Thumbnail Generation
Preview of video is crucial, thumbnail generation gives you the preview image from the timeframe you need.
The TruVideoVideoSdk has a generateThumbnail function this method takes the videoPath, resultPath, position, width, height as input and places the image at the resulting path.
try {
// get result path to where to save
const resultPath = await getResultPath(`${Date.now()}-thumbnail`);
// handle result of generate Thumbnail
// return result is path where image is saved
const result = await generateThumbnail(selectedItems[0], resultPath, '1000', '640', '480');
console.log('Thumbnail generated successfully:', result);
} catch (error) {
// handle error
console.error('Error generating thumbnail:', error);
}
Clean noise
We are utilizing high-level Artificial intelligence for noise cancellation over the input video. It’s useful for video containing background noises.
This function takes video path, result path, and callback and places a new video to the resulting path after clearing noise
try {
// get result path to where to save
const resultPath = await getResultPath(`${Date.now()}-cleanNoise`);
// handle result of generate Thumbnail
const result = await cleanNoise(selectedItems[0], resultPath);
// return result is path where video is saved
console.log('Noise cleaned successfully:', result);
} catch (error) {
// handle error
console.error('Error cleaning noise:', error);
}
Concat Videos
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 list, and result path to place a new video and 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.
try {
// get result path to where to save
const resultPath = await getResultPath(`${Date.now()}-concatVideo`);
// build concat class
const request = new ConcatBuilder(selectedItems, resultPath);
const builder = await request.build();
// process the result
const video : BuilderResponse = await request.process();
console.log('Video concatenated successfully:', video);
} catch (error) {
console.error('Error concatenating videos:', error);
}
Merge Videos
The TruVideoVideoSdk has a mergeVideos function have same functionality as concat to merge multiple videos to make one another video but there is an advantage over contact 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
try {
// get result path to where to save
const resultPath = await getResultPath(`${Date.now()}-mergedVideo`);
const request = new MergeBuilder(selectedItems, resultPath);
request.setHeight(640);
request.setWigth(480);
request.setFrameRate(FrameRate.fiftyFps);
const result = await request.build();
// process the result
const video : BuilderResponse = await request.process(); // process the video
console.log('Videos merged successfully:', video);
} catch (error) {
console.error('Error merging videos:', error);
}
Encode Video
The TruVideoVideoSdk has a encodeVideo function constructs to carry out a an encoding operation. This operation enables modification to a video by altering one or more of its attribute, such as:-
Resolution via width and height parameters
try {
// get result path to where to save
const resultPath = await getResultPath(`${Date.now()}-encodedVideo`);
const request = new EncodeBuilder(selectedItems[0], resultPath);
request.setHeight(640);
request.setWidth(480);
request.setFrameRate(FrameRate.fiftyFps);
const result = await request.build();
// process the result
const video : BuilderResponse = await request.process(); // process the video
console.log('Video encoded successfully:', video);
} catch (error) {
console.error('Error encoding video:', error);
}
BuilderResponse
export interface BuilderResponse {
id: string;
createdAt: string;
status: VideoStatus;
type: BuilderType;
updatedAt: string;
}
export enum BuilderType {
merge = 'merge',
concat = 'concat',
encode = 'encode',
}
export enum VideoStatus {
processing = 'processing',
completed = 'complete',
idle = 'idle',
cancel = 'cancelled',
error = 'error',
}
GetAllRequest
This function will provide all the requests created for Encode, Concat and Merge Builder
Input Params
var videoStatus : VideoStatus | undefined = undefined // for all status
// for specific status
enum VideoStatus {
processing = 'processing',
completed = 'complete',
idle = 'idle',
cancel = 'cancelled',
error = 'error',
}
Function Utilisation
const requests : BuilderResponse[] = await getAllRequest(videoStatus);
GetRequestById
This function will return exact request associated with the id
const request : BuilderResponse = getRequestById(id : string);
Last updated
Was this helpful?