-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmvimg_example.dart
79 lines (65 loc) · 2.02 KB
/
mvimg_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import 'dart:io';
import 'package:buff/buff_io.dart';
import 'package:mvimg/mvimg.dart';
class ExampleMvImgCallbackAdapter extends MvImgCallbackAdapter {
@override
void onDecodeStart(Mvimg mvimg) {
print('onDecodeStart');
}
@override
void onDecodeEnd(Mvimg mvimg) {
print('onDecodeEnd');
}
@override
void onError(Mvimg mvimg, dynamic e, StackTrace? stackTrace) {
print('onError: $e');
print('stackTrace: $stackTrace');
}
@override
void onDispose(Mvimg mvimg) {
print('onDispose');
}
}
void main() {
final assetList = [
'assets/test.jpg',
'assets/test2.jpg',
'assets/test.MP.jpg',
];
for (final asset in assetList) {
final fileName = asset.split('/').last;
final mvimg = Mvimg(FileBufferInput.fromPath(asset));
mvimg.setCallback(ExampleMvImgCallbackAdapter());
mvimg.decode();
try {
if (!mvimg.isMvimg()) {
print('not mvimg');
return;
}
final img = mvimg.getImageBytes();
final video = mvimg.getVideoBytes();
final imgOffsetStart = 0;
final imgOffsetEnd = mvimg.videoStartOffset;
final videoOffsetStart = mvimg.videoStartOffset;
final videoOffsetEnd = mvimg.videoEndOffset;
print('imgOffsetStart: $imgOffsetStart');
print('imgOffsetEnd: $imgOffsetEnd');
print('videoOffsetStart: $videoOffsetStart');
print('videoOffsetEnd: $videoOffsetEnd');
final videoOutputPath = 'assets/split/$fileName/output.mp4';
final imgOutputPath = 'assets/split/$fileName/output.jpg';
final xapOutputPath = 'assets/split/$fileName/output.xml';
final videoFile = File(videoOutputPath);
final imgFile = File(imgOutputPath);
final xapFile = File(xapOutputPath);
videoFile.createSync(recursive: true);
imgFile.createSync(recursive: true);
xapFile.createSync(recursive: true);
videoFile.writeAsBytesSync(video);
imgFile.writeAsBytesSync(img);
xapFile.writeAsBytesSync(mvimg.getXapBytes());
} finally {
mvimg.dispose();
}
}
}