Version - 0.0.1
Video Information
This function gives you all the important details about a video, like its resolution, duration, codec, and other useful metadata.
void getVideoInfo(String videoPath) {
TruvideoVideoSdk.getVideoInfo(
videoUri: videoPath,
onResult: (String? result) {
print("Video info: $result");
},
onError: (String? message) {
print("Failed to fetch video info: $message");
},
);
}
Compare Video
This function checks if multiple videos are compatible for concatenation, returning true if they have matching characteristics and false if they need merging.
void compareVideos(List<String> videoPaths) {
TruvideoVideoSdk.compareVideos(
videoUris: videoPaths,
onResult: (bool? result) {
print("Videos comparison result: $result");
},
onError: (String? message) {
print("Video comparison failed: $message");
},
);
}
Edit Video
This function initiates video editing by creating a preset with the input video URL and the desired output URL. It then presents the TruvideoSdkVideoEditorView
with the preset, allowing users to perform editing actions. Upon completion, it provides the result of the edited video.
void editVideo(String videoPath) {
TruvideoVideoSdk.editVideo(
inputPath: videoPath,
outputPath: "${widget.directoryPath}/editVideo_${timestamp}",
onResult: (String? result) {
print("Video edited successfully: $result");
},
onError: (String? message) {
print("Video editing failed: $message");
},
);
}
Thumbnail Generation
This function asynchronously generates a thumbnail for a given video using the TruvideoSdkVideo's thumbnailGenerator. It accepts a TruvideoSdkVideoThumbnailInputVideo
object as input, which encapsulates the necessary information about the video.
void generateThumbnail(String videoPath) {
TruvideoVideoSdk.generateThumbnail(
videoUri: videoPath,
outputPath: "${widget.directoryPath}/thumbnail_${timestamp}",
position: 1000,
width: 300,
height: 300,
precise: true,
onResult: (String? result) {
print("Thumbnail generated successfully: $result");
},
onError: (String? message) {
print("Thumbnail generation failed: $message");
},
);
}
Clean noise
This function asynchronously utilizes TruvideoSdkVideo's engine to clean noise from a specified video file located at the given input URL. The cleaned video is then saved to the provided output URL.
void clearNoise(String videoPath) {
TruvideoVideoSdk.cleanNoise(
videoUri: videoPath,
outputPath: "${widget.directoryPath}/clearNoise_${timestamp}",
onResult: (String? result) {
print("Noise cleared successfully: $result");
},
onError: (String? message) {
print("Noise clearing failed: $message");
},
);
}
Concat Videos
This function concatenates multiple videos into a single video file. First, it checks if the videos can be concatenated by calling the canConcatVideos
function. If the videos are compatible, it proceeds to concatenate them using the ConcatBuilder
. Finally, it prints the output path of the concatenated video.
Note:
1. Concatenation necessitates uniform characteristics across all provided videos, including resolution, audio codec, video codec, and pixel format.
2. Any discrepancies in these characteristics may lead to exceptions during the concatenation process.
3. To verify compatibility, it's advisable to use the compare method mentioned earlier to ensure the videos meet the necessary criteria before concatenation.
Future<void> runConcatBuilder() async {
try {
final builder = ConcatBuilder(
filePaths: selectedVideos,
resultPath: "${widget.directoryPath}/concat_${timestamp}",
);
await builder.build();
final result = await builder.process();
lastBuilderId = result.id;
print("ConcatBuilder Process Success: ${result.toString()}");
} catch (e) {
print("ConcatBuilder Error: $e");
}
}
Merge Videos
The mergeVideos function combines several videos into one file. Unlike just sticking them together, this method reprocesses the videos, which might take longer. The merged video could end up with different qualities to fit all the originals. Unlike a simple join, this method lets you mix videos without any specific limitations, giving you more options.
Note:
1. Any video resolution can be merged without causing errors.
2. Unlike the concatenate method, this process involves reprocessing the videos, which might slow things down, especially on slower devices.
3 The resulting video's resolution is automatically adjusted to make sure it plays properly.
Future<void> runMergeBuilder() async {
if (selectedVideos.length < 2) return;
try {
final builder = MergeBuilder(
filePaths: selectedVideos,
resultPath: "${widget.directoryPath}/merged_${timestamp}",
)
..setHeight(640)
..setWidth(480)
..setFrameRate(TruvideoSdkVideoFrameRate.thirtyFps);
await builder.build();
final result = await builder.process();
lastBuilderId = result.id;
print("MergeBuilder Process Success: ${result.toString()}");
} catch (e) {
print("MergeBuilder Error: $e");
}
}
Encode Video
This function is used to build a TruvideoSdkVideoRequest
that performs an encoding operation. An encoding operation allows to perform changes over a single video by changing one or many of its attributes, such as:
Resolution through the width and height parameters
Video codec (.h264 and .h265)
Audio codec (.aac, .mp3, .ac3)
Frame rate (24fps, 25fps, 30fps, 50fps, 60fps)
Future<void> runEncodeBuilder() async {
try {
final builder = EncodeBuilder(
filePath: selectedVideos.first,
resultPath: "${widget.directoryPath}/encoded_${timestamp}",
)
..setHeight(720)
..setWidth(1280)
..setFrameRate(TruvideoSdkVideoFrameRate.sixtyFps);
await builder.build();
final result = await builder.process();
lastBuilderId = result.id;
print("EncodeBuilder Process Success: ${result.toString()}");
} catch (e) {
print("EncodeBuilder Error: $e");
}
}
Last updated
Was this helpful?