render static method

Future<String> render({
  1. required List<VideoEditorClip> clips,
  2. required List<VideoEditorAudioTrack> audioTracks,
  3. required List<VideoEffectOverlay> effectOverlays,
  4. required VideoAspectRatio aspectRatio,
  5. required PreviewSegmentCache cache,
  6. RenderProgressCallback? onProgress,
  7. bool isStale()?,
})

Renders the preview and returns the path of a preview_*.mp4 file.

onProgress reports 0..1 over all the work still to do. isStale is checked between steps; when it returns true the render stops with RenderCancelledException (finished segments stay cached).

Implementation

static Future<String> render({
  required List<VideoEditorClip> clips,
  required List<VideoEditorAudioTrack> audioTracks,
  required List<VideoEffectOverlay> effectOverlays,
  required VideoAspectRatio aspectRatio,
  required PreviewSegmentCache cache,
  RenderProgressCallback? onProgress,
  bool Function()? isStale,
}) async {
  if (clips.isEmpty) return '';
  final hardware = await VideoRenderService.hardwareEncoderAvailable();
  try {
    return await _render(
      clips: clips,
      audioTracks: audioTracks,
      effectOverlays: effectOverlays,
      aspectRatio: aspectRatio,
      cache: cache,
      hardware: hardware,
      onProgress: onProgress,
      isStale: isStale,
    );
  } on RenderException catch (e) {
    if (!hardware) rethrow;
    // Segments from two encoders must not be joined: start over with x264.
    debugPrint('Hardware preview failed, using x264: ${e.message}');
    VideoRenderService.disableHardwareEncoder();
    cache.clear();
    return _render(
      clips: clips,
      audioTracks: audioTracks,
      effectOverlays: effectOverlays,
      aspectRatio: aspectRatio,
      cache: cache,
      hardware: false,
      onProgress: onProgress,
      isStale: isStale,
    );
  }
}