Video Editing
The Video Module SDK delivers a suite of robust video editing tools. These tools facilitate the seamless integration of comprehensive video editing functionalities into your applications, including:
Video Editing: Modify and enhance video content with precision.
Concatenation: Easily join multiple video files.
Merging: Combine video files into a single output.
Encoding: Convert video files to different formats efficiently.
Noise Cancellation: Enhance audio quality by removing unwanted background noise.
These features empower developers to create versatile video applications tailored to diverse needs.
Prerequisites
Ensure you have integrated the TruVideo Core SDK into your project and completed with the authentication process
Camera module will provide MediaItem or simply provide filepath to upload (optional)
Edit a video
To edit a video, follow these steps:
Step 1 : Import Classes
#if IOS
using TruvideoVideoiOS;
using Foundation;
using UIKit;
#endif
#if ANDROID
using Application = Android.App.Application;
using TruVideoVideoAndroidBinding;
using TruVideoVideoLib = TruVideoVideoAndroid.DotnetTruvideoVideo;
#endif
Step 2 : Init Async Callback Wrapper
#if ANDROID
private Task<T> ExecuteVideoCallbackAsync<T>(Action<VideoCallback> action) {
var tcs = new TaskCompletionSource<T>();
action.Invoke(new VideoCallback(
success => MainThread.BeginInvokeOnMainThread(() =>
tcs.TrySetResult((T)Convert.ChangeType(success, typeof(T)))),
failure => MainThread.BeginInvokeOnMainThread(() => tcs.TrySetException(new Exception(failure)))
));
return tcs.Task;
}
#endif
Step 3 : Call Edit Function
// iOS implementation
#if IOS
var inputUrl = NSUrl.FromFilename(_filePath);
var outputUrl = NSUrl.FromFilename(_outputPath);
var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
TruvideoVideoSdk.Shared.EditVideo(inputUrl, outputUrl, viewController, (resultUrl, error) =>
{
if (error != null)
{
LogTextEditor.Text = $"Error editing video: {error.LocalizedDescription}";
return;
}
LogTextEditor.Text = $"Video edited successfully: {resultUrl}";
});
#endif
// Android implementation
#if ANDROID
string _resultPath = await ExecuteVideoCallbackAsync<string>(cb => TruVideoVideoLib.EditVideo(Application.Context, _inputPath,_outputPath, cb));
LogTextEditor.Text = $"Edit Video: {_resultPath}";
#endif
}
Finalize :
After completing this steps the function should look like
#if IOS
using TruvideoVideoiOS;
using Foundation;
using UIKit;
#endif
#if ANDROID
using Application = Android.App.Application;
using TruVideoVideoAndroidBinding;
using TruVideoVideoLib = TruVideoVideoAndroid.DotnetTruvideoVideo;
#endif
#if ANDROID
private Task<T> ExecuteVideoCallbackAsync<T>(Action<VideoCallback> action) {
var tcs = new TaskCompletionSource<T>();
action.Invoke(new VideoCallback(
success => MainThread.BeginInvokeOnMainThread(() =>
tcs.TrySetResult((T)Convert.ChangeType(success, typeof(T)))),
failure => MainThread.BeginInvokeOnMainThread(() => tcs.TrySetException(new Exception(failure)))
));
return tcs.Task;
}
#endif
private async void Editvideo_OnClicked(object? sender, EventArgs e)
{
// iOS implementation
#if IOS
var inputUrl = NSUrl.FromFilename(_filePath);
var outputUrl = NSUrl.FromFilename(_outputPath);
var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
TruvideoVideoSdk.Shared.EditVideo(inputUrl, outputUrl, viewController, (resultUrl, error) =>
{
if (error != null)
{
LogTextEditor.Text = $"Error editing video: {error.LocalizedDescription}";
return;
}
LogTextEditor.Text = $"Video edited successfully: {resultUrl}";
});
#endif
// Android implementation
#if ANDROID
string _resultPath = await ExecuteVideoCallbackAsync<string>(cb => TruVideoVideoLib.EditVideo(Application.Context, _inputPath,_outputPath, cb));
LogTextEditor.Text = $"Edit Video: {_resultPath}";
#endif
}
For a detailed overview of the features available, please visit the video module.
Last updated
Was this helpful?