runEncode static method
Runs an FFmpeg job that encodes video at size: the phone's hardware
encoder first, x264 if that fails. argumentsFor gets the encoder
arguments to place before the output file. Throws RenderException.
Implementation
static Future<void> runEncode({
required List<String> Function(List<String> encoderArgs) argumentsFor,
required Size size,
required Duration duration,
RenderProgressCallback? onProgress,
int fps = 30,
}) async {
final hardware = await hardwareEncoderAvailable();
RenderPlan plan(bool hw) => RenderPlan(
arguments: argumentsFor(videoCodecArgs(
canvas: size,
fps: fps,
quality: ExportQuality.high,
preview: false,
hardware: hw,
)),
duration: duration,
canvas: size,
);
try {
await executePlan(plan(hardware), onProgress: onProgress);
} on RenderException catch (e) {
if (!hardware) rethrow;
debugPrint('Hardware encoder failed, using x264: ${e.message}');
disableHardwareEncoder();
await executePlan(plan(false), onProgress: onProgress);
}
}