feat: initial Cutdex application
Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,156 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Future<void> pumpUntil(
|
||||
WidgetTester tester,
|
||||
bool Function() ready,
|
||||
String label, {
|
||||
int seconds = 60,
|
||||
}) async {
|
||||
final deadline = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!ready()) {
|
||||
if (DateTime.now().isAfter(deadline)) throw TimeoutException(label);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await Future<void>.delayed(const Duration(milliseconds: 10));
|
||||
}
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> measureAndroidFullLengthPreview({
|
||||
required WidgetTester tester,
|
||||
required CutdexRuntime runtime,
|
||||
required MediaReference media,
|
||||
required MediaInfo info,
|
||||
required ({int width, int height, int observationSeconds}) configuration,
|
||||
required Map<String, Object?> result,
|
||||
required void Function() save,
|
||||
}) async {
|
||||
final full = await runtime.createSession();
|
||||
try {
|
||||
final duration = MediaTime(
|
||||
(math.min(
|
||||
info.duration.seconds,
|
||||
info.audioTracks.first.duration.seconds,
|
||||
) *
|
||||
1000)
|
||||
.floor() -
|
||||
100,
|
||||
1000,
|
||||
);
|
||||
final range = MediaRange(start: MediaTime(0, 1), duration: duration);
|
||||
await full.load(
|
||||
ExecutionPlan(
|
||||
duration: duration,
|
||||
renderSize: RenderSize(
|
||||
configuration.width.toDouble(),
|
||||
configuration.height.toDouble(),
|
||||
),
|
||||
frameDuration: MediaTime(1, 30),
|
||||
media: [media],
|
||||
visualLayers: [
|
||||
VisualLayer(
|
||||
id: 'full-video',
|
||||
mediaId: media.id,
|
||||
sourceRange: range,
|
||||
timelineRange: range,
|
||||
inputColorSpace:
|
||||
info.videoColorSpaces[0] ?? RenderColorSpace.rec709,
|
||||
),
|
||||
],
|
||||
audioLayers: [
|
||||
AudioLayer(
|
||||
id: 'full-audio',
|
||||
mediaId: media.id,
|
||||
sourceRange: range,
|
||||
timelineRange: range,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Center(
|
||||
child: SizedBox(
|
||||
width: configuration.width.toDouble(),
|
||||
height: configuration.height.toDouble(),
|
||||
child: RuntimePreview(session: full),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await pumpUntil(
|
||||
tester,
|
||||
() => (full.snapshot?.presentedVideoFrameCount ?? 0) > 0,
|
||||
'full-length first frame',
|
||||
seconds: 90,
|
||||
);
|
||||
final observations = <Map<String, Object?>>[];
|
||||
result['fullLengthPlayback'] = observations;
|
||||
for (final seconds in [
|
||||
60.0,
|
||||
duration.seconds / 2,
|
||||
duration.seconds - math.max(5, configuration.observationSeconds + 2),
|
||||
]) {
|
||||
final seekWatch = Stopwatch()..start();
|
||||
await full.seek(MediaTime((seconds * 1000).round(), 1000));
|
||||
final before = await full.refresh();
|
||||
final seekLatency = seekWatch.elapsedMilliseconds;
|
||||
final startWatch = Stopwatch()..start();
|
||||
await full.play();
|
||||
final startLatency = startWatch.elapsedMilliseconds;
|
||||
await Future<void>.delayed(
|
||||
Duration(seconds: configuration.observationSeconds),
|
||||
);
|
||||
await tester.pump();
|
||||
var after = await full.refresh();
|
||||
while (after.message == null &&
|
||||
(after.position.seconds <= seconds + .5 ||
|
||||
(after.presentedVideoFrameCount ?? 0) <=
|
||||
(before.presentedVideoFrameCount ?? 0)) &&
|
||||
startWatch.elapsedMilliseconds <
|
||||
startLatency +
|
||||
math.max(10000, configuration.observationSeconds * 1000)) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
await tester.pump();
|
||||
after = await full.refresh();
|
||||
}
|
||||
expect(after.message, isNull);
|
||||
expect(after.position.seconds, greaterThan(seconds + .5));
|
||||
expect(
|
||||
after.presentedVideoFrameCount,
|
||||
greaterThan(before.presentedVideoFrameCount ?? 0),
|
||||
);
|
||||
observations.add({
|
||||
'at': seconds,
|
||||
'position': after.position.seconds,
|
||||
'seekMilliseconds': seekLatency,
|
||||
'playStartupMilliseconds': startLatency,
|
||||
'observationMilliseconds': startWatch.elapsedMilliseconds,
|
||||
'slowPlayback':
|
||||
startWatch.elapsedMilliseconds - startLatency >
|
||||
configuration.observationSeconds * 1000 + 1000,
|
||||
'presentedFramesPerSecond':
|
||||
((after.presentedVideoFrameCount ?? 0) -
|
||||
(before.presentedVideoFrameCount ?? 0)) *
|
||||
1000 /
|
||||
(startWatch.elapsedMilliseconds - startLatency),
|
||||
'timelineAdvanceSeconds':
|
||||
after.position.seconds - before.position.seconds,
|
||||
'frames':
|
||||
(after.presentedVideoFrameCount ?? 0) -
|
||||
(before.presentedVideoFrameCount ?? 0),
|
||||
'maximumFrameGapMs': after.maximumVideoFrameGapMs,
|
||||
'maximumFrameGapScope': 'session cumulative',
|
||||
});
|
||||
await full.pause();
|
||||
save();
|
||||
}
|
||||
} finally {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await full.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
const _source = String.fromEnvironment('CUTDEX_TEST_SOURCE');
|
||||
const _encodedSource = String.fromEnvironment('CUTDEX_TEST_SOURCE_BASE64');
|
||||
const _document = String.fromEnvironment('CUTDEX_TEST_SOURCE_DOCUMENT');
|
||||
|
||||
const hasNativeMediaFixture =
|
||||
_source != '' || _encodedSource != '' || _document != '';
|
||||
|
||||
/// Uses a host file, a sandbox document, or embedded media written to a temporary file.
|
||||
Future<File> nativeMediaFixture() async {
|
||||
if (_encodedSource.isEmpty) {
|
||||
if (_document.isEmpty) return File(_source).absolute;
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
return File('${directory.path}/$_document');
|
||||
}
|
||||
final directory = await Directory.systemTemp.createTemp('cutdex-media-');
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
return File('${directory.path}/source.mp4')
|
||||
.writeAsBytes(base64Decode(_encodedSource));
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Future<double> verifyEditedExport(
|
||||
CutdexRuntime runtime, {
|
||||
required Uri edited,
|
||||
required Uri baseline,
|
||||
}) async {
|
||||
final editedMedia = MediaReference(id: 'edited', uri: edited);
|
||||
final editedInfo = await runtime.probe(editedMedia);
|
||||
expect(editedInfo.duration.seconds, closeTo(4, .1));
|
||||
expect(editedInfo.audioTrackCount, 1);
|
||||
final thumbnail = await runtime.thumbnail(
|
||||
ThumbnailRequest(
|
||||
media: editedMedia,
|
||||
time: MediaTime(1, 1),
|
||||
maximumWidth: 320,
|
||||
maximumHeight: 180,
|
||||
),
|
||||
);
|
||||
final image = await decodeImageFromList(thumbnail.data);
|
||||
try {
|
||||
final pixels = (await image.toByteData(
|
||||
format: ui.ImageByteFormat.rawRgba,
|
||||
))!;
|
||||
// The authored half-size mask must leave the canvas corners black.
|
||||
for (final at in [
|
||||
0,
|
||||
(image.width - 1) * 4,
|
||||
(image.height - 1) * image.width * 4,
|
||||
]) {
|
||||
expect(
|
||||
pixels.getUint8(at) + pixels.getUint8(at + 1) + pixels.getUint8(at + 2),
|
||||
lessThan(35),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
image.dispose();
|
||||
}
|
||||
final originalWave = await runtime.waveform(
|
||||
WaveformRequest(
|
||||
media: MediaReference(id: 'baseline', uri: baseline),
|
||||
baseBucketCount: 64,
|
||||
levelCount: 1,
|
||||
),
|
||||
);
|
||||
final editedWave = await runtime.waveform(
|
||||
WaveformRequest(media: editedMedia, baseBucketCount: 64, levelCount: 1),
|
||||
);
|
||||
double rms(MediaWaveform wave) {
|
||||
final values = [
|
||||
for (final channel in wave.levels.first.channels)
|
||||
for (var i = 2; i < channel.length; i += 3) channel[i],
|
||||
];
|
||||
return math.sqrt(
|
||||
values.fold<double>(0, (sum, value) => sum + value * value) /
|
||||
values.length,
|
||||
);
|
||||
}
|
||||
|
||||
final baseRms = rms(originalWave);
|
||||
expect(baseRms, greaterThan(0));
|
||||
final ratio = rms(editedWave) / baseRms;
|
||||
expect(ratio, closeTo(math.pow(10, -6 / 20).toDouble(), .08));
|
||||
return ratio;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
final class RealMediaReport {
|
||||
RealMediaReport(this.file, {required Map<String, Object?> metadata})
|
||||
: metadata = Map.unmodifiable(metadata);
|
||||
|
||||
final File file;
|
||||
final Map<String, Object?> metadata;
|
||||
final files = <Map<String, Object?>>[];
|
||||
|
||||
void save() {
|
||||
final temporary = File('${file.path}.part');
|
||||
temporary.writeAsStringSync(
|
||||
const JsonEncoder.withIndent(' ').convert({...metadata, 'files': files}),
|
||||
);
|
||||
temporary.renameSync(file.path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class SavedEditValidation {
|
||||
final _edits = <String, Map<String, Map<String, Object?>>>{};
|
||||
|
||||
Future<Map<String, Object?>> capture(
|
||||
String projectPath,
|
||||
String timelineId,
|
||||
EditorSession session,
|
||||
SequenceId sequence,
|
||||
) async {
|
||||
final edits = await _editingState(session, sequence);
|
||||
_edits.putIfAbsent(projectPath, () => {})[timelineId] = edits;
|
||||
return edits;
|
||||
}
|
||||
|
||||
Future<void> verify({
|
||||
required Future<void> Function(Duration) wait,
|
||||
required void Function(
|
||||
String projectPath,
|
||||
String timelineId,
|
||||
Map<String, Object?> edits,
|
||||
)
|
||||
onVerified,
|
||||
}) async {
|
||||
for (final project in _edits.entries) {
|
||||
ProjectFile? reopened;
|
||||
final deadline = DateTime.now().add(const Duration(seconds: 40));
|
||||
while (reopened == null) {
|
||||
try {
|
||||
reopened = await ProjectFile.open(Directory(project.key));
|
||||
} on ProjectFileException catch (error) {
|
||||
if (error.code != ProjectFileError.conflict ||
|
||||
DateTime.now().isAfter(deadline)) {
|
||||
rethrow;
|
||||
}
|
||||
await wait(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (final entry in project.value.entries) {
|
||||
final session = EditorSession(
|
||||
document: await reopened.loadTimeline(entry.key),
|
||||
persistence: await reopened.openTimelineSaveSession(entry.key),
|
||||
);
|
||||
late Map<String, Object?> actual;
|
||||
try {
|
||||
actual = await _editingState(
|
||||
session,
|
||||
SequenceId(entry.value['sequenceId'] as String),
|
||||
);
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
expect(
|
||||
actual,
|
||||
entry.value,
|
||||
reason: 'Edited timeline changed after close/reopen',
|
||||
);
|
||||
onVerified(project.key, entry.key, actual);
|
||||
}
|
||||
} finally {
|
||||
await reopened.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, Object?>> _editingState(
|
||||
EditorSession session,
|
||||
SequenceId sequence,
|
||||
) async {
|
||||
final result = await session.executeCommand(
|
||||
sequence,
|
||||
const QueryTimeline(),
|
||||
);
|
||||
// History availability and save status describe the current session.
|
||||
return Map<String, Object?>.of(result.data)
|
||||
..remove('canUndo')
|
||||
..remove('canRedo')
|
||||
..remove('saveState');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user