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,130 @@
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../workspace/media_binding.dart';
|
||||
import '../../workspace/projects.dart';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart'
|
||||
show ProviderListenableSelect;
|
||||
part 'media_thumbnails.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
MediaThumbnails mediaThumbnails(Ref ref) {
|
||||
final projectId = ref.watch(
|
||||
projectsProvider.select((s) => s.asData?.value.activeProject?.id),
|
||||
);
|
||||
return MediaThumbnails(
|
||||
loadMedia: <T>(asset, action) => ref
|
||||
.read(projectsProvider.notifier)
|
||||
.withAssetMedia(projectId, asset, action),
|
||||
);
|
||||
}
|
||||
|
||||
/// Small runtime-generated browser covers, kept outside the project document.
|
||||
class MediaThumbnails {
|
||||
MediaThumbnails({required this.loadMedia});
|
||||
final AssetMediaLoader loadMedia;
|
||||
final _runtime = CutdexRuntime();
|
||||
final _cache = <(String, int?, int), Future<Uint8List?>>{};
|
||||
final _durations = <(String, int?), Future<double?>>{};
|
||||
Future<void> _tail = Future.value();
|
||||
|
||||
Future<double?> duration(AssetDocument asset) {
|
||||
final key = (asset.location, asset.byteLength);
|
||||
if (_durations.containsKey(key)) return _durations[key]!;
|
||||
if (_durations.length >= 64) _durations.remove(_durations.keys.first);
|
||||
return _durations[key] = () async {
|
||||
try {
|
||||
final info = await loadMedia(asset, _runtime.probe);
|
||||
final seconds = info.duration.numerator / info.duration.denominator;
|
||||
return seconds.isFinite && seconds > 0 ? seconds : null;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
Future<Uint8List?> load(AssetDocument asset, {int timeMilliseconds = 0}) {
|
||||
final key = (asset.location, asset.byteLength, timeMilliseconds);
|
||||
final cached = _cache.remove(key);
|
||||
if (cached != null) {
|
||||
_cache[key] = cached;
|
||||
return cached;
|
||||
}
|
||||
// Bound encoded cover retention and concurrent native generation.
|
||||
if (_cache.length >= 64) _cache.remove(_cache.keys.first);
|
||||
final future = _tail.then((_) async {
|
||||
if (asset.metadata['kind'] == 'image') {
|
||||
final image = await _imagePreview(asset);
|
||||
if (image != null) return image;
|
||||
}
|
||||
try {
|
||||
final thumbnail = await loadMedia(
|
||||
asset,
|
||||
(media) => _runtime.thumbnail(
|
||||
ThumbnailRequest(
|
||||
media: media,
|
||||
time: MediaTime(timeMilliseconds, 1000),
|
||||
),
|
||||
),
|
||||
);
|
||||
return thumbnail.data;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
_cache[key] = future;
|
||||
_tail = future.then((_) {});
|
||||
return future;
|
||||
}
|
||||
|
||||
Future<Uint8List?> _imagePreview(AssetDocument asset) async {
|
||||
if (kIsWeb) return null;
|
||||
try {
|
||||
return await loadMedia(asset, (media) async {
|
||||
if (media.uri.scheme != 'file') return null;
|
||||
final file = File.fromUri(media.uri);
|
||||
if (!file.existsSync()) return null;
|
||||
final bytes = await file.readAsBytes();
|
||||
final buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
|
||||
try {
|
||||
final descriptor = await ui.ImageDescriptor.encoded(buffer);
|
||||
try {
|
||||
final longestSide = descriptor.width > descriptor.height
|
||||
? descriptor.width
|
||||
: descriptor.height;
|
||||
final scale = longestSide > 320 ? 320 / longestSide : 1.0;
|
||||
final codec = await descriptor.instantiateCodec(
|
||||
targetWidth: (descriptor.width * scale).round(),
|
||||
targetHeight: (descriptor.height * scale).round(),
|
||||
);
|
||||
try {
|
||||
final frame = await codec.getNextFrame();
|
||||
try {
|
||||
return (await frame.image.toByteData(
|
||||
format: ui.ImageByteFormat.png,
|
||||
))?.buffer.asUint8List();
|
||||
} finally {
|
||||
frame.image.dispose();
|
||||
}
|
||||
} finally {
|
||||
codec.dispose();
|
||||
}
|
||||
} finally {
|
||||
descriptor.dispose();
|
||||
}
|
||||
} finally {
|
||||
buffer.dispose();
|
||||
}
|
||||
});
|
||||
} catch (_) {
|
||||
// Formats not handled by Flutter can still use the native thumbnailer.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user