Skip to content

Commit

Permalink
adds chapters in media information object, fixes #196
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed Dec 19, 2021
1 parent 34e924f commit c80244e
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 1 deletion.
38 changes: 38 additions & 0 deletions react-native/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ declare module 'ffmpeg-kit-react-native' {

getStreams(): Array<StreamInformation>;

getChapters(): Array<Chapter>;

getStringProperty(key: string): string;

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

}

export class Chapter {

static readonly KEY_ID: string;
static readonly KEY_TIME_BASE: string;
static readonly KEY_START: string;
static readonly KEY_START_TIME: string;
static readonly KEY_END: string;
static readonly KEY_END_TIME: string;
static readonly KEY_TAGS: string;

constructor(properties: Record<string, any>);

getId(): number;

getTimeBase(): string;

getStart(): number;

getStartTime(): string;

getEnd(): number;

getEndTime(): string;

getTags(): Record<string, any>;

getStringProperty(key): string;

getNumberProperty(key): number;

getProperties(key): Record<string, any>;

getAllProperties(): Record<string, any>;

}

}
158 changes: 157 additions & 1 deletion react-native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ export class FFprobeKit {
* @return media information session created for this execution
*/
static async getMediaInformationAsync(path, executeCallback, logCallback, waitTimeout) {
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path];
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
return FFprobeKit.getMediaInformationFromCommandArgumentsAsync(commandArguments, executeCallback, logCallback, waitTimeout);
}

Expand Down Expand Up @@ -2221,6 +2221,28 @@ export class MediaInformation {
return list;
}

/**
* Returns the chapters found as array.
*
* @returns Chapter array
*/
getChapters() {
let list = [];
let chapterList;

if (this.#allProperties !== undefined) {
chapterList = this.#allProperties.chapters;
}

if (chapterList !== undefined) {
chapterList.forEach((chapter) => {
list.push(new Chapter(chapter));
});
}

return list;
}

/**
* Returns the media property associated with the key.
*
Expand Down Expand Up @@ -2788,3 +2810,137 @@ export class StreamInformation {
return this.#allProperties;
}
}

/**
* Chapter class.
*/
export class Chapter {

static KEY_ID = "id";
static KEY_TIME_BASE = "time_base";
static KEY_START = "start";
static KEY_START_TIME = "start_time";
static KEY_END = "end";
static KEY_END_TIME = "end_time";
static KEY_TAGS = "tags";

#allProperties;

constructor(properties) {
this.#allProperties = properties;
}

/**
* Returns id.
*
* @return id
*/
getId() {
return this.getNumberProperty(Chapter.KEY_ID);
}

/**
* Returns time base.
*
* @return time base
*/
getTimeBase() {
return this.getStringProperty(Chapter.KEY_TIME_BASE);
}

/**
* Returns start.
*
* @return start
*/
getStart() {
return this.getNumberProperty(Chapter.KEY_START);
}

/**
* Returns start time.
*
* @return start time
*/
getStartTime() {
return this.getStringProperty(Chapter.KEY_START_TIME);
}

/**
* Returns end.
*
* @return end
*/
getEnd() {
return this.getNumberProperty(Chapter.KEY_END);
}

/**
* Returns end time.
*
* @return end time
*/
getEndTime() {
return this.getStringProperty(Chapter.KEY_END_TIME);
}

/**
* Returns all tags.
*
* @return tags object
*/
getTags() {
return this.getProperties(StreamInformation.KEY_TAGS);
}

/**
* Returns the chapter property associated with the key.
*
* @param key property key
* @return chapter property as string or undefined if the key is not found
*/
getStringProperty(key) {
if (this.#allProperties !== undefined) {
return this.#allProperties[key];
} else {
return undefined;
}
}

/**
* Returns the chapter property associated with the key.
*
* @param key property key
* @return chapter property as number or undefined if the key is not found
*/
getNumberProperty(key) {
if (this.#allProperties !== undefined) {
return this.#allProperties[key];
} else {
return undefined;
}
}

/**
* Returns the chapter properties associated with the key.
*
* @param key properties key
* @return chapter properties as an object or undefined if the key is not found
*/
getProperties(key) {
if (this.#allProperties !== undefined) {
return this.#allProperties[key];
} else {
return undefined;
}
}

/**
* Returns all properties found.
*
* @returns an object in which properties can be accessed by property names
*/
getAllProperties() {
return this.#allProperties;
}
}

0 comments on commit c80244e

Please sign in to comment.