videoCodecArgs static method
List<String>
videoCodecArgs({
- required Size canvas,
- required int fps,
- required ExportQuality quality,
- required bool preview,
- bool hardware = false,
Encoder arguments for canvas at fps: hardware H.264 on Android when
hardware is set, otherwise x264 (VideoToolbox on Apple platforms).
Implementation
static List<String> videoCodecArgs({
required Size canvas,
required int fps,
required ExportQuality quality,
required bool preview,
bool hardware = false,
}) {
if (hardware && Platform.isAndroid) {
final bitsPerPixel = preview ? 0.06 : quality.bitsPerPixel;
final bitrate = (canvas.width * canvas.height * fps * bitsPerPixel)
.clamp(1000000, 40000000)
.round();
return [
'-c:v', 'h264_mediacodec',
'-b:v', '$bitrate',
'-g', '${fps * 2}',
// Every Android encoder accepts NV12; planar YUV is optional.
'-pix_fmt', 'nv12',
];
}
if (Platform.isIOS || Platform.isMacOS) {
final bitsPerPixel = preview ? 0.05 : quality.bitsPerPixel;
final bitrate = (canvas.width * canvas.height * fps * bitsPerPixel)
.clamp(800000, 60000000)
.round();
return [
'-c:v', 'h264_videotoolbox',
'-b:v', '$bitrate',
if (preview) ...['-realtime', 'true'],
];
}
return preview
? ['-c:v', 'libx264', '-preset', 'ultrafast', '-tune', 'zerolatency', '-crf', '30']
: ['-c:v', 'libx264', '-preset', 'veryfast', '-crf', '${quality.crf}'];
}