Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caijinglong/bmff
The package provides a library for reading ISO Base Media File Format (BMFF) files.
https://github.com/caijinglong/bmff
bmff dart heic isobmff mp4
Last synced: 2 months ago
JSON representation
The package provides a library for reading ISO Base Media File Format (BMFF) files.
- Host: GitHub
- URL: https://github.com/caijinglong/bmff
- Owner: CaiJingLong
- License: bsd-3-clause
- Created: 2022-04-12T09:42:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-08T02:41:09.000Z (almost 2 years ago)
- Last Synced: 2024-10-02T13:41:25.334Z (3 months ago)
- Topics: bmff, dart, heic, isobmff, mp4
- Language: Dart
- Homepage:
- Size: 136 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bmff of dart
The package provides a library for reading ISO Base Media File Format (BMFF) files.
## Usage
```yaml
dependencies:
bmff: any
``````dart
import 'package:bmff/bmff.dart';
```## Example
### Simple example
Click to show codes
```dart
import 'package:bmff/bmff.dart';void main() {
final assetPath = 'assets/compare_still_1.heic';
final bmff =
Bmff.file(assetPath); // The path is file path, not flutter asset path.final boxes = bmff.childBoxes;
for (final box in boxes) {
print(box);
}showFtyp(bmff);
}void useByteListSource(List bytes) {
final bmff = Bmff.memory(bytes);
final boxes = bmff.childBoxes;
for (final box in boxes) {
print(box);
}
}void showFtyp(Bmff bmff) {
final typeBox = bmff.typeBox;
final type = typeBox.type;final majorBrand = typeBox.majorBrand;
final minorVersion = typeBox.minorVersion;
final compatibleBrands = typeBox.compatibleBrands;print('type: $type');
print('majorBrand: $majorBrand');
print('minorVersion: $minorVersion');
print('compatibleBrands: $compatibleBrands');
}```
```log
ftyp (len = 24, start = 0, end = 24)
meta (len = 315, start = 24, end = 339)
mdat (len = 37933, start = 339, end = 38272)
type: ftyp
majorBrand: mif1
minorVersion:
compatibleBrands: [mif1, heic]
```### Async context example
Click to show codes
```dart
import 'package:bmff/bmff.dart';
import 'package:http/http.dart' as http;Future main(List args) async {
// final uri = Uri.parse('https://www.w3school.com.cn/i/movie.mp4');
final uri = Uri.parse(
'http://vfx.mtime.cn/Video/2019/03/18/mp4/190318231014076505.mp4');
final bmff = await Bmff.asyncContext(AsyncBmffContextHttp(uri));
for (final box in bmff.childBoxes) {
showBoxInfo(0, box);
}
}void showBoxInfo(int level, AsyncBmffBox box) {
final levelPrefix = ' ' * level;
print('$levelPrefix${box.type} ${box.realSize}');for (final child in box.childBoxes) {
showBoxInfo(level + 1, child);
}
}// part download http context
class AsyncBmffContextHttp extends AsyncBmffContext {
final Uri uri;const AsyncBmffContextHttp(this.uri);
@override
Future> getRangeData(int start, int end) async {
final response = await http.get(uri, headers: {
'Range': 'bytes=$start-${end - 1}',
});
if (response.statusCode != 206) {
throw Exception(
'Current http status code is ${response.statusCode},' +
' not 206, not support range download');
}
final bytes = response.bodyBytes;
return bytes;
}@override
Future lengthAsync() async {
final response = await http.head(uri);
final contentLength = response.headers['content-length'];
if (contentLength != null) {
return int.parse(contentLength);
} else {
throw Exception('content-length not found');
}
}
}```
```log
ftyp 32
moov 44331
mvhd 108
trak 20456
trak 23640
udta 119
free 8
mdat 7538059
```### All examples
See [example](https://github.com/CaiJingLong/bmff/blob/main/example).
## Other resources
[ISO Base Media File Format (BMFF)][isobmff]
[The project wiki][wiki]## LICENSE
[BSD 3-Clause License](https://github.com/CaiJingLong/bmff/blob/main/LICENSE)
[isobmff]: https://mpeg.chiariglione.org/standards/mpeg-4/iso-base-media-file-format
[wiki]: https://github.com/CaiJingLong/bmff/wiki