diff --git a/react-native/android/src/main/java/com/arthenica/ffmpegkit/reactnative/FFmpegKitReactNativeModule.java b/react-native/android/src/main/java/com/arthenica/ffmpegkit/reactnative/FFmpegKitReactNativeModule.java index 17f3ee4..7f9ce9d 100644 --- a/react-native/android/src/main/java/com/arthenica/ffmpegkit/reactnative/FFmpegKitReactNativeModule.java +++ b/react-native/android/src/main/java/com/arthenica/ffmpegkit/reactnative/FFmpegKitReactNativeModule.java @@ -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 diff --git a/react-native/ios/FFmpegKitReactNativeModule.m b/react-native/ios/FFmpegKitReactNativeModule.m index d566474..9babaa4 100644 --- a/react-native/ios/FFmpegKitReactNativeModule.m +++ b/react-native/ios/FFmpegKitReactNativeModule.m @@ -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) { diff --git a/react-native/src/index.d.ts b/react-native/src/index.d.ts index 839fc62..5836754 100644 --- a/react-native/src/index.d.ts +++ b/react-native/src/index.d.ts @@ -74,9 +74,9 @@ declare module 'ffmpeg-kit-react-native' { export class FFmpegKit { - static execute(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise; + static execute(command: string): Promise; - static executeWithArguments(commandArguments: string[], completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise; + static executeWithArguments(commandArguments: string[]): Promise; static executeAsync(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise; @@ -236,19 +236,19 @@ declare module 'ffmpeg-kit-react-native' { export class FFprobeKit { - static execute(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise; + static execute(command: string): Promise; - static executeWithArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise; + static executeWithArguments(commandArguments: string[]): Promise; static executeAsync(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise; static executeWithArgumentsAsync(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise; - static getMediaInformation(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise; + static getMediaInformation(path: string, waitTimeout?: number): Promise; - static getMediaInformationFromCommand(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise; + static getMediaInformationFromCommand(command: string, waitTimeout?: number): Promise; - static getMediaInformationFromCommandArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise; + static getMediaInformationFromCommandArguments(commandArguments: string[], waitTimeout?: number): Promise; static getMediaInformationAsync(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise; diff --git a/react-native/src/index.js b/react-native/src/index.js index 298cd72..4b28ff5 100644 --- a/react-native/src/index.js +++ b/react-native/src/index.js @@ -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)); } /** *

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)); } /** *

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 { *

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; }