Merge pull request #182 from Suman085/add-get-chapters-api

implement get chapters api in media information
This commit is contained in:
Taner Şener 2021-10-20 23:36:09 +01:00 committed by GitHub
commit afa1a19859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2019-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
class Chapter {
int id;
String timeBase;
int start;
int end;
String startTime;
String endTime;
Tags tags;
Chapter(this.id, this.timeBase, this.start, this.end, this.startTime,
this.endTime, this.tags);
}
class Tags {
String title;
Tags(this.title);
}

View File

@ -17,6 +17,7 @@
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/ */
import 'chapter.dart';
import 'stream_information.dart'; import 'stream_information.dart';
/// Media information class. /// Media information class.
@ -87,6 +88,28 @@ class MediaInformation {
return list; return list;
} }
/// Returns all chapters
List<Chapter> getChapters() {
final List<Chapter> list = List<Chapter>.empty(growable: true);
List<Chapter> chapters = List.empty(growable: true);
if (_allProperties?["chapters"] != null) {
chapters = <Chapter>[];
_allProperties!['chapters'].forEach((dynamic chapter) {
final int id = chapter['id'];
final String timeBase = chapter['time_base'];
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;
}
/// Returns all media properties. /// Returns all media properties.
Map<dynamic, dynamic>? getMediaProperties() => Map<dynamic, dynamic>? getMediaProperties() =>
this._allProperties?[keyMediaProperties]; this._allProperties?[keyMediaProperties];