Truvideo Video SDK

This plugin integrates TruvideoVideoSdk for handling video files, including browsing, editing, encoding, and merging videos.

Supported Platforms

  • Android
  • iOS

Features

  • Loads and displays videos from a directory
  • Edits videos
  • Generates thumbnails
  • Compares videos
  • Retrieves video information
  • Clears noise from videos
  • Encode videos using EncodeBuilder
  • Merge videos using MergeBuilder
  • Concatenate videos using ConcatBuilder

Requirements

  • TruvideoVideoSdk Plugin

Setup

  1. Add TruvideoVideoSdk Plugin to your project.
  2. Install dependencies:
    flutter pub get
    
  3. Ensure proper permissions in AndroidManifest.xml & Info.plist.
  4. Run the app:
    flutter run
    

Usage

  • Edit a video:
  void editVideo(String videoPath, String outputPath) {
    TruvideoVideoSdk.editVideo(
      inputPath: videoPath,
      outputPath: outputPath,
      onResult: (String? result) {
        print("Video edited successfully: \$result");
      },
      onError: (String? message) {
        print("Video editing failed: \$message");
      },
    );
  }
  • Generate a thumbnail:
  void generateThumbnail(String videoPath, String outputPath) {
    TruvideoVideoSdk.generateThumbnail(
      videoUri: videoPath,
      outputPath: outputPath,
      position: 1000,
      width: 300,
      height: 300,
      precise: true,
      onResult: (String? result) {
        print("Thumbnail generated successfully: \$result");
      },
      onError: (String? message) {
        print("Thumbnail generation failed: \$message");
      },
    );
  }
  • Retrieve video information:
  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");
    },
  );
  }
  • Clear noise from a video:
  void clearNoise(String videoPath, String outputPath) {
  TruvideoVideoSdk.cleanNoise(
    videoUri: videoPath,
    outputPath: outputPath,
    onResult: (String? result) {
      print("Noise cleared successfully: \$result");
    },
    onError: (String? message) {
      print("Noise clearing failed: \$message");
    },
  );
  }
  • Encode a video:
  Future<void> encodeVideo(String videoPath) async {
  final builder = EncodeBuilder(
  filePath: videoPath,
  resultPath: "$directoryPath/encoded.mp4",
  )
    ..setWidth(1280)
    ..setHeight(720)
    ..setFrameRate(TruvideoSdkVideoFrameRate.sixtyFps);
    
    await builder.build();
    final result = await builder.process();
    }
  • Compare multiple videos:
  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");
    },
  );
  }
  • Concatenate multiple videos:
  Future<void> concatVideos(List<String> videoPaths) async {
    final builder = ConcatBuilder(
    filePaths: videoPaths,
    resultPath: "$directoryPath/concat.mp4",
    );
    
    await builder.build();
    final result = await builder.process();
  }
  • Merge multiple videos:
  Future<void> mergeVideos(List<String> videoPaths) async {
    final builder = MergeBuilder(
    filePaths: videoPaths,
    resultPath: "$directoryPath/merged.mp4",
    )
    ..setWidth(480)
    ..setHeight(640)
    ..setFrameRate(TruvideoSdkVideoFrameRate.thirtyFps);
    
    await builder.build();
    final result = await builder.process();
  }
  • Get all video requests:
  void getAllRequests() async {
    try {
      List<VideoRequestDetails>? result = await TruvideoVideoSdk.getAllRequests();

      if (result != null) {
        print(result.length);
      }
    } on PlatformException catch (e) {
      print('Error on getting all requests: ${e.message}');
    }
  }
  • Process Request:
void processRequest(String id) async {
    try {
      final res = await TruvideoVideoSdk.processVideo(id);

      if (res != null) {
        print('Video processed successfully, ID: $id');
      }
    } on PlatformException catch (e) {
      print('Error on process requests: ${e.message}');
    }
  }
  • Cancel Request:
void cancelRequest(String id) async {
  try {
    final res = await TruvideoVideoSdk.cancelVideo(id);

    if (res != null) {
      print('Video canceled successfully, ID: $id');
    }
  } on PlatformException catch (e) {
    print('Error on cancel requests: ${e.message}');
  }
}
  • Delete Request:
void deleteRequest(String id) async {
  try {
    final res = await TruvideoVideoSdk.deleteVideo(id);

    if (res != null) {
      print('Video deleted successfully, ID: $id');
    }
  } on PlatformException catch (e) {
    print('Error on deleting requests: ${e.message}');
  }
}

Documentation

For more details, please refer to the official documentation: Truvideo Swift SDK Guide

License

MIT

Support

If you have any questions or suggestions regarding the SDK, please contact us at [email protected].