Skip to content

Commit

Permalink
docs: Add dartdoc for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed Oct 11, 2023
1 parent a6de7d0 commit 2c50a9b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1

- Add dartdoc for classes.

## 1.1.0

- Feat: Support MP.jpg format.
Expand Down
45 changes: 42 additions & 3 deletions lib/mvimg.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
/// Support for doing something awesome.
/// A library for support MVIMG or Motion Photo.
/// It is a dart library, not a flutter plugin.
///
/// More dartdocs go here.
/// Just like this:
/// - `MVIMG_XXXX.jpg`
/// - `XXXX.MP.jpg`
///
/// Example:
///
/// ```dart
/// import 'dart:io';
///
/// import 'package:buff/buff_io.dart';
/// import 'package:mvimg/mvimg.dart';
///
/// void main() {
/// final mvimg = Mvimg(FileBufferInput.fromPath('assets/test.jpg'));
/// mvimg.decode();
/// try {
/// if (!mvimg.isMvimg()) {
/// print('not mvimg');
/// return;
/// }
///
/// final img = mvimg.getImageBytes();
/// final video = mvimg.getVideoBytes();
///
/// final videoOutputPath = 'assets/split/output.mp4';
/// final imgOutputPath = 'assets/split/output.jpg';
///
/// final videoFile = File(videoOutputPath);
/// final imgFile = File(imgOutputPath);
///
/// videoFile.createSync(recursive: true);
/// imgFile.createSync(recursive: true);
///
/// videoFile.writeAsBytesSync(video);
/// imgFile.writeAsBytesSync(img);
/// } finally {
/// mvimg.dispose();
/// }
/// }
/// ```
library mvimg;

export 'src/mvimg_base.dart';

22 changes: 21 additions & 1 deletion lib/src/mvimg_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ class _Range {
_Range(this.start, this.end);
}

/// Just support jpeg + mp4
/// A class for decoding mvimg files, which are composed of a jpeg image and an mp4 video.
/// Support like this:
/// - `MVIMG_XXXX.jpg`
/// - `XXXX.MP.jpg`
class Mvimg {
/// The input buffer.
///
/// See also:
/// [BufferInput] of `buff` package.
final BufferInput input;

/// Creates a [Mvimg] from a [BufferInput].
Mvimg(this.input);

bool _isMvImg = false;

_Range? _videoRange;

/// Decodes the mvimg file.
///
/// Just call this method after, the [isMvimg], [getImageBytes] or [getVideoBytes] is valid.
void decode() {
try {
_readContent();
Expand Down Expand Up @@ -126,21 +137,30 @@ class Mvimg {
throw Exception('Can not find video range');
}

/// Closes the input buffer.
///
/// Must call this method after use.
void dispose() {
input.close();
}

/// Returns true if the file is a mvimg or motion photo file.
bool isMvimg() {
return _isMvImg;
}

/// Returns the offset of the start of the video in the file.
int get videoStartOffset => _videoRange?.start ?? 0;

/// Returns the offset of the end of the video in the file.
int get videoEndOffset => _videoRange?.end ?? input.length;

/// Returns the bytes of the jpeg image in the file.
List<int> getImageBytes() {
return input.getBytes(0, videoStartOffset);
}

/// Returns the bytes of the mp4 video in the file.
List<int> getVideoBytes() {
if (_isMvImg) {
return input.getBytes(videoStartOffset, videoEndOffset);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mvimg
description: A library to split mvimg(android motion video) file.
version: 1.1.0
version: 1.1.1
repository: https://github.com/caijinglong/mvimg

environment:
Expand Down

0 comments on commit 2c50a9b

Please sign in to comment.