fix execute() methods

This commit is contained in:
Taner Sener 2022-01-01 22:52:13 +00:00
parent 8448f29c02
commit eaa0b91758
4 changed files with 74 additions and 38 deletions

View File

@ -946,6 +946,32 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
promise.resolve(toSessionArray(FFprobeKit.listMediaInformationSessions()));
}
// MediaInformationSession
@ReactMethod
public void getMediaInformation(final Double sessionId, final Promise promise) {
if (sessionId != null) {
final Session session = FFmpegKitConfig.getSession(sessionId.longValue());
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session.isMediaInformation()) {
final MediaInformationSession mediaInformationSession = (MediaInformationSession) session;
final MediaInformation mediaInformation = mediaInformationSession.getMediaInformation();
if (mediaInformation != null) {
promise.resolve(toMap(mediaInformation));
} else {
promise.resolve(null);
}
} else {
promise.reject("NOT_MEDIA_INFORMATION_SESSION", "A session is found but it does not have the correct type.");
}
}
} else {
promise.reject("INVALID_SESSION", "Invalid session id.");
}
}
// Packages
@ReactMethod

View File

@ -669,6 +669,22 @@ RCT_EXPORT_METHOD(getMediaInformationSessions:(RCTPromiseResolveBlock)resolve re
resolve([FFmpegKitReactNativeModule toSessionArray:[FFprobeKit listMediaInformationSessions]]);
}
// MediaInformationSession
RCT_EXPORT_METHOD(getMediaInformation:(int)sessionId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
AbstractSession* session = (AbstractSession*)[FFmpegKitConfig getSession:sessionId];
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMediaInformation]) {
MediaInformationSession *mediaInformationSession = (MediaInformationSession*)session;
resolve([FFmpegKitReactNativeModule toMediaInformationDictionary:[mediaInformationSession getMediaInformation]]);
} else {
reject(@"NOT_MEDIA_INFORMATION_SESSION", @"A session is found but it does not have the correct type.", nil);
}
}
}
// Packages
RCT_EXPORT_METHOD(getPackageName:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {

View File

@ -74,9 +74,9 @@ declare module 'ffmpeg-kit-react-native' {
export class FFmpegKit {
static execute(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static execute(command: string): Promise<FFmpegSession>;
static executeWithArguments(commandArguments: string[], completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeWithArguments(commandArguments: string[]): Promise<FFmpegSession>;
static executeAsync(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
@ -236,19 +236,19 @@ declare module 'ffmpeg-kit-react-native' {
export class FFprobeKit {
static execute(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static execute(command: string): Promise<FFprobeSession>;
static executeWithArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArguments(commandArguments: string[]): Promise<FFprobeSession>;
static executeAsync(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArgumentsAsync(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static getMediaInformation(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformation(path: string, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommand(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommand(command: string, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArguments(commandArguments: string[], waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationAsync(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;

View File

@ -709,26 +709,20 @@ export class FFmpegKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async execute(command, completeCallback, logCallback, statisticsCallback) {
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
static async execute(command) {
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command));
}
/**
* <p>Synchronously executes FFmpeg with arguments provided.
*
* @param commandArguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async executeWithArguments(commandArguments, completeCallback, logCallback, statisticsCallback) {
let session = await FFmpegSession.create(commandArguments, completeCallback, logCallback, statisticsCallback);
static async executeWithArguments(commandArguments) {
let session = await FFmpegSession.create(commandArguments, undefined, undefined, undefined);
await FFmpegKitConfig.ffmpegExecute(session);
@ -1614,7 +1608,7 @@ class FFmpegKitFactory {
}
static getVersion() {
return "4.5";
return "4.5.1";
}
static getLogRedirectionStrategy(sessionId) {
@ -2055,24 +2049,20 @@ export class FFprobeKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async execute(command, completeCallback, logCallback) {
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
static async execute(command) {
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command));
}
/**
* <p>Synchronously executes FFprobe with arguments provided.
*
* @param commandArguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async executeWithArguments(commandArguments, completeCallback, logCallback) {
let session = await FFprobeSession.create(commandArguments, completeCallback, logCallback);
static async executeWithArguments(commandArguments) {
let session = await FFprobeSession.create(commandArguments, undefined, undefined);
await FFmpegKitConfig.ffprobeExecute(session);
@ -2118,14 +2108,12 @@ export class FFprobeKit {
* <p>Extracts media information for the file specified with path.
*
* @param path path or uri of a media file
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformation(path, completeCallback, logCallback, waitTimeout) {
static async getMediaInformation(path, waitTimeout) {
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout);
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, waitTimeout);
}
/**
@ -2133,13 +2121,11 @@ export class FFprobeKit {
* this method must generate the output in JSON format in order to successfully extract media information from it.
*
* @param command FFprobe command that prints media information for a file in JSON format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommand(command, completeCallback, logCallback, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, waitTimeout);
static async getMediaInformationFromCommand(command, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), waitTimeout);
}
/**
@ -2148,16 +2134,19 @@ export class FFprobeKit {
* from it.
*
* @param commandArguments FFprobe command arguments that prints media information for a file in JSON format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, completeCallback, logCallback);
static async getMediaInformationFromCommandArguments(commandArguments, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, undefined, undefined);
await FFmpegKitConfig.getMediaInformationExecute(session, waitTimeout);
const mediaInformation = await FFmpegKitReactNativeModule.getMediaInformation(session.getSessionId());
if (mediaInformation !== undefined && mediaInformation !== null) {
session.setMediaInformation(new MediaInformation(mediaInformation));
}
return session;
}
@ -2214,6 +2203,11 @@ export class FFprobeKit {
await FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);
const mediaInformation = await FFmpegKitReactNativeModule.getMediaInformation(session.getSessionId());
if (mediaInformation !== undefined && mediaInformation !== null) {
session.setMediaInformation(new MediaInformation(mediaInformation));
}
return session;
}