updates chapters in media information object, improves #196

pull/295/head
Taner Sener 4 years ago
parent dcabec5f65
commit aed46e9bd7
  1. 60
      flutter/flutter/lib/chapter.dart
  2. 1
      flutter/flutter/lib/ffprobe_kit.dart
  3. 26
      flutter/flutter/lib/media_information.dart
  4. 2
      flutter/flutter/lib/stream_information.dart

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019-2021 Taner Sener * Copyright (c) 2021 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -17,21 +17,51 @@
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/ */
/// Chapter class.
class Chapter { class Chapter {
int id; static const keyId = "id";
String timeBase; static const keyTimeBase = "time_base";
int start; static const keyStart = "start";
int end; static const keyStartTime = "start_time";
String startTime; static const keyEnd = "end";
String endTime; static const keyEndTime = "end_time";
Tags tags; static const keyTags = "tags";
Chapter(this.id, this.timeBase, this.start, this.end, this.startTime, Map<dynamic, dynamic>? _allProperties;
this.endTime, this.tags);
} /// Creates a new [Chapter] instance
Chapter(this._allProperties);
/// Returns id.
int? getId() => this.getNumberProperty(Chapter.keyId)?.toInt();
/// Returns time base.
String? getTimeBase() => this.getStringProperty(Chapter.keyTimeBase);
/// Returns start.
int? getStart() => this.getNumberProperty(Chapter.keyStart)?.toInt();
/// Returns start time.
String? getStartTime() => this.getStringProperty(Chapter.keyStartTime);
/// Returns end.
int? getEnd() => this.getNumberProperty(Chapter.keyEnd)?.toInt();
/// Returns end time.
String? getEndTime() => this.getStringProperty(Chapter.keyEndTime);
/// Returns all tags.
Map<dynamic, dynamic>? getTags() => this.getProperties(Chapter.keyTags);
/// Returns the chapter property associated with the key.
String? getStringProperty(String key) => this._allProperties?[key];
/// Returns the chapter property associated with the key.
num? getNumberProperty(String key) => this._allProperties?[key];
class Tags { /// Returns the chapter properties associated with the key.
String title; dynamic getProperties(String key) => this._allProperties?[key];
Tags(this.title); /// Returns all properties found.
Map<dynamic, dynamic>? getAllProperties() => this._allProperties;
} }

@ -76,6 +76,7 @@ class FFprobeKit {
"json", "json",
"-show_format", "-show_format",
"-show_streams", "-show_streams",
"-show_chapters",
"-i", "-i",
path path
]; ];

@ -88,25 +88,17 @@ class MediaInformation {
return list; return list;
} }
/// Returns all chapters /// Returns all chapters found as a list.
List<Chapter> getChapters() { List<Chapter> getChapters() {
final List<Chapter> list = List<Chapter>.empty(growable: true); final List<Chapter> list = List<Chapter>.empty(growable: true);
List<Chapter> chapters = List.empty(growable: true);
if (_allProperties?["chapters"] != null) { dynamic createChapter(Map<dynamic, dynamic> chapterProperties) =>
chapters = <Chapter>[]; list.add(new Chapter(chapterProperties));
_allProperties!['chapters'].forEach((dynamic chapter) {
final int id = chapter['id']; this._allProperties?["chapters"]?.forEach((Object? chapter) {
final String timeBase = chapter['time_base']; createChapter(chapter as Map<dynamic, dynamic>);
final int start = chapter['start']; });
final int end = chapter['end'];
final String startTime = chapter['start_time'];
final String endTime = chapter['end_time'];
final Tags tags = Tags(chapter['tags']['title'] ?? "");
chapters.add(
new Chapter(id, timeBase, start, end, startTime, endTime, tags));
});
}
list.addAll(chapters);
return list; return list;
} }

@ -119,6 +119,6 @@ class StreamInformation {
/// Returns the stream properties associated with the key. /// Returns the stream properties associated with the key.
dynamic getProperties(String key) => this._allProperties?[key]; dynamic getProperties(String key) => this._allProperties?[key];
/// Returns all properties found.d /// Returns all properties found.
Map<dynamic, dynamic>? getAllProperties() => this._allProperties; Map<dynamic, dynamic>? getAllProperties() => this._allProperties;
} }

Loading…
Cancel
Save