Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit c80244e

Browse files
committed
adds chapters in media information object, fixes #196
1 parent 34e924f commit c80244e

File tree

2 files changed

+195
-1
lines changed

2 files changed

+195
-1
lines changed

react-native/src/index.d.ts

+38
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ declare module 'ffmpeg-kit-react-native' {
299299

300300
getStreams(): Array<StreamInformation>;
301301

302+
getChapters(): Array<Chapter>;
303+
302304
getStringProperty(key: string): string;
303305

304306
getNumberProperty(key: string): number;
@@ -535,4 +537,40 @@ declare module 'ffmpeg-kit-react-native' {
535537

536538
}
537539

540+
export class Chapter {
541+
542+
static readonly KEY_ID: string;
543+
static readonly KEY_TIME_BASE: string;
544+
static readonly KEY_START: string;
545+
static readonly KEY_START_TIME: string;
546+
static readonly KEY_END: string;
547+
static readonly KEY_END_TIME: string;
548+
static readonly KEY_TAGS: string;
549+
550+
constructor(properties: Record<string, any>);
551+
552+
getId(): number;
553+
554+
getTimeBase(): string;
555+
556+
getStart(): number;
557+
558+
getStartTime(): string;
559+
560+
getEnd(): number;
561+
562+
getEndTime(): string;
563+
564+
getTags(): Record<string, any>;
565+
566+
getStringProperty(key): string;
567+
568+
getNumberProperty(key): number;
569+
570+
getProperties(key): Record<string, any>;
571+
572+
getAllProperties(): Record<string, any>;
573+
574+
}
575+
538576
}

react-native/src/index.js

+157-1
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ export class FFprobeKit {
18761876
* @return media information session created for this execution
18771877
*/
18781878
static async getMediaInformationAsync(path, executeCallback, logCallback, waitTimeout) {
1879-
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path];
1879+
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
18801880
return FFprobeKit.getMediaInformationFromCommandArgumentsAsync(commandArguments, executeCallback, logCallback, waitTimeout);
18811881
}
18821882

@@ -2221,6 +2221,28 @@ export class MediaInformation {
22212221
return list;
22222222
}
22232223

2224+
/**
2225+
* Returns the chapters found as array.
2226+
*
2227+
* @returns Chapter array
2228+
*/
2229+
getChapters() {
2230+
let list = [];
2231+
let chapterList;
2232+
2233+
if (this.#allProperties !== undefined) {
2234+
chapterList = this.#allProperties.chapters;
2235+
}
2236+
2237+
if (chapterList !== undefined) {
2238+
chapterList.forEach((chapter) => {
2239+
list.push(new Chapter(chapter));
2240+
});
2241+
}
2242+
2243+
return list;
2244+
}
2245+
22242246
/**
22252247
* Returns the media property associated with the key.
22262248
*
@@ -2788,3 +2810,137 @@ export class StreamInformation {
27882810
return this.#allProperties;
27892811
}
27902812
}
2813+
2814+
/**
2815+
* Chapter class.
2816+
*/
2817+
export class Chapter {
2818+
2819+
static KEY_ID = "id";
2820+
static KEY_TIME_BASE = "time_base";
2821+
static KEY_START = "start";
2822+
static KEY_START_TIME = "start_time";
2823+
static KEY_END = "end";
2824+
static KEY_END_TIME = "end_time";
2825+
static KEY_TAGS = "tags";
2826+
2827+
#allProperties;
2828+
2829+
constructor(properties) {
2830+
this.#allProperties = properties;
2831+
}
2832+
2833+
/**
2834+
* Returns id.
2835+
*
2836+
* @return id
2837+
*/
2838+
getId() {
2839+
return this.getNumberProperty(Chapter.KEY_ID);
2840+
}
2841+
2842+
/**
2843+
* Returns time base.
2844+
*
2845+
* @return time base
2846+
*/
2847+
getTimeBase() {
2848+
return this.getStringProperty(Chapter.KEY_TIME_BASE);
2849+
}
2850+
2851+
/**
2852+
* Returns start.
2853+
*
2854+
* @return start
2855+
*/
2856+
getStart() {
2857+
return this.getNumberProperty(Chapter.KEY_START);
2858+
}
2859+
2860+
/**
2861+
* Returns start time.
2862+
*
2863+
* @return start time
2864+
*/
2865+
getStartTime() {
2866+
return this.getStringProperty(Chapter.KEY_START_TIME);
2867+
}
2868+
2869+
/**
2870+
* Returns end.
2871+
*
2872+
* @return end
2873+
*/
2874+
getEnd() {
2875+
return this.getNumberProperty(Chapter.KEY_END);
2876+
}
2877+
2878+
/**
2879+
* Returns end time.
2880+
*
2881+
* @return end time
2882+
*/
2883+
getEndTime() {
2884+
return this.getStringProperty(Chapter.KEY_END_TIME);
2885+
}
2886+
2887+
/**
2888+
* Returns all tags.
2889+
*
2890+
* @return tags object
2891+
*/
2892+
getTags() {
2893+
return this.getProperties(StreamInformation.KEY_TAGS);
2894+
}
2895+
2896+
/**
2897+
* Returns the chapter property associated with the key.
2898+
*
2899+
* @param key property key
2900+
* @return chapter property as string or undefined if the key is not found
2901+
*/
2902+
getStringProperty(key) {
2903+
if (this.#allProperties !== undefined) {
2904+
return this.#allProperties[key];
2905+
} else {
2906+
return undefined;
2907+
}
2908+
}
2909+
2910+
/**
2911+
* Returns the chapter property associated with the key.
2912+
*
2913+
* @param key property key
2914+
* @return chapter property as number or undefined if the key is not found
2915+
*/
2916+
getNumberProperty(key) {
2917+
if (this.#allProperties !== undefined) {
2918+
return this.#allProperties[key];
2919+
} else {
2920+
return undefined;
2921+
}
2922+
}
2923+
2924+
/**
2925+
* Returns the chapter properties associated with the key.
2926+
*
2927+
* @param key properties key
2928+
* @return chapter properties as an object or undefined if the key is not found
2929+
*/
2930+
getProperties(key) {
2931+
if (this.#allProperties !== undefined) {
2932+
return this.#allProperties[key];
2933+
} else {
2934+
return undefined;
2935+
}
2936+
}
2937+
2938+
/**
2939+
* Returns all properties found.
2940+
*
2941+
* @returns an object in which properties can be accessed by property names
2942+
*/
2943+
getAllProperties() {
2944+
return this.#allProperties;
2945+
}
2946+
}

0 commit comments

Comments
 (0)