/*
* Copyright (c) 2020-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
Main class for FFprobe operations. *
Supports running FFprobe commands using {@link #execute(String...)} method. *
* FFprobeSession session = FFprobe.execute("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4"); * Log.i(FFmpegKitConfig.TAG, String.format("Command execution %s.", (session.getReturnCode() == 0?"completed successfully":"failed with rc=" + session.getReturnCode())); **
It can also extract media information for a file or a url, using {@link #getMediaInformation(String)} method. *
* MediaInformationSession session = FFprobe.getMediaInformation("file1.mp4"); * Log.i(FFmpegKitConfig.TAG, String.format("Media information %s.", (session.getReturnCode() == 0?"extracted successfully":"was not extracted due to rc=" + session.getReturnCode())); **/ public class FFprobeKit { static { AbiDetect.class.getName(); FFmpegKitConfig.class.getName(); } /** * Default constructor hidden. */ private FFprobeKit() { } /** *
Synchronously executes FFprobe with arguments provided. * * @param arguments FFprobe command options/arguments as string array * @return ffprobe session created for this execution */ public static FFprobeSession execute(final String[] arguments) { final FFprobeSession session = new FFprobeSession(arguments, null, null, null); FFmpegKitConfig.ffprobeExecute(session); return session; } /** *
Synchronously executes FFprobe command provided. Space character is used to split command * into arguments. You can use single and double quote characters to specify arguments inside * your command. * * @param command FFprobe command * @return ffprobe session created for this execution */ public static FFprobeSession execute(final String command) { return execute(FFmpegKit.parseArguments(command)); } /** *
Asynchronously executes FFprobe command provided. Space character is used to split command * into arguments. You can use single and double quote characters to specify arguments inside * your command. * * @param command FFprobe command * @param executeCallback callback that will be notified when the execution is completed * @return ffprobe session created for this execution */ public static FFprobeSession executeAsync(final String command, final ExecuteCallback executeCallback) { return executeAsync(FFmpegKit.parseArguments(command), executeCallback); } /** *
Asynchronously executes FFprobe with arguments provided. * * @param arguments FFprobe command options/arguments as string array * @param executeCallback callback that will be notified when the execution is completed * @return ffprobe session created for this execution */ public static FFprobeSession executeAsync(final String[] arguments, final ExecuteCallback executeCallback) { final FFprobeSession session = new FFprobeSession(arguments, executeCallback, null, null); FFmpegKitConfig.asyncFFprobeExecute(session); return session; } /** *
Asynchronously executes FFprobe command provided. Space character is used to split command * into arguments. You can use single and double quote characters to specify arguments inside * your command. * * @param command FFprobe command * @param executeCallback callback that will be notified when execution is completed * @param logCallback callback that will receive log entries * @param statisticsCallback callback that will receive statistics * @return ffprobe session created for this execution */ public static FFprobeSession executeAsync(final String command, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback) { return executeAsync(FFmpegKit.parseArguments(command), executeCallback, logCallback, statisticsCallback); } /** *
Asynchronously executes FFprobe with arguments provided. * * @param arguments FFprobe command options/arguments as string array * @param executeCallback callback that will be notified when execution is completed * @param logCallback callback that will receive log entries * @param statisticsCallback callback that will receive statistics * @return ffprobe session created for this execution */ public static FFprobeSession executeAsync(final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback) { final FFprobeSession session = new FFprobeSession(arguments, executeCallback, logCallback, statisticsCallback); FFmpegKitConfig.asyncFFprobeExecute(session); return session; } /** *
Asynchronously executes FFprobe with arguments provided. * * @param arguments FFprobe command options/arguments as string array * @param executeCallback callback that will be notified when the execution is completed * @param executor executor that will be used to run this asynchronous operation * @return ffprobe session created for this execution */ public static FFprobeSession executeAsync(final String[] arguments, final ExecuteCallback executeCallback, final Executor executor) { final FFprobeSession session = new FFprobeSession(arguments, executeCallback, null, null); AsyncFFprobeExecuteTask asyncFFprobeExecuteTask = new AsyncFFprobeExecuteTask(session); executor.execute(asyncFFprobeExecuteTask); return session; } /** *
Asynchronously executes FFprobe with arguments provided. * * @param arguments FFprobe command options/arguments as string array * @param executeCallback callback that will be notified when execution is completed * @param logCallback callback that will receive log entries * @param statisticsCallback callback that will receive statistics * @param executor executor that will be used to run this asynchronous operation * @return ffprobe session created for this execution */ public static FFprobeSession executeAsync(final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback, final Executor executor) { final FFprobeSession session = new FFprobeSession(arguments, executeCallback, logCallback, statisticsCallback); AsyncFFprobeExecuteTask asyncFFprobeExecuteTask = new AsyncFFprobeExecuteTask(session); executor.execute(asyncFFprobeExecuteTask); return session; } /** *
Lists all FFprobe sessions in the session history
*
* @return all FFprobe sessions in the session history
*/
public static List Returns media information for the given path.
*
* @param path path or uri of a media file
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformation(final String path) {
return getMediaInformationFromCommandArguments(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, null, null, null, AbstractSession.DEFAULT_TIMEOUT_FOR_CALLBACK_MESSAGES_IN_TRANSMIT);
}
/**
* Returns media information for the given path.
*
* @param path path or uri of a media file
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformation(final String path, final Integer waitTimeout) {
return getMediaInformationFromCommandArguments(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, null, null, null, waitTimeout);
}
/**
* Returns media information for the given path asynchronously.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when the execution is completed
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback) {
final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, null, null);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, AbstractSession.DEFAULT_TIMEOUT_FOR_CALLBACK_MESSAGES_IN_TRANSMIT);
return session;
}
/**
* Returns media information for the given path asynchronously.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive log entries
* @param statisticsCallback callback that will receive statistics
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final Integer waitTimeout) {
final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, logCallback, statisticsCallback);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);
return session;
}
/**
* Returns media information for the given path asynchronously.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when the execution is completed
* @param executor executor that will be used to run this asynchronous operation
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback,
final Executor executor) {
final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, null, null);
AsyncGetMediaInformationTask asyncGetMediaInformationTask = new AsyncGetMediaInformationTask(session);
executor.execute(asyncGetMediaInformationTask);
return session;
}
/**
* Returns media information for the given path asynchronously.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive log entries
* @param statisticsCallback callback that will receive statistics
* @param executor executor that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final Executor executor,
final Integer waitTimeout) {
final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, logCallback, statisticsCallback);
AsyncGetMediaInformationTask asyncGetMediaInformationTask = new AsyncGetMediaInformationTask(session, waitTimeout);
executor.execute(asyncGetMediaInformationTask);
return session;
}
/**
* Returns media information for the given command.
*
* @param command command to execute
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationFromCommand(final String command) {
return getMediaInformationFromCommandArguments(FFmpegKit.parseArguments(command), null, null, null, AbstractSession.DEFAULT_TIMEOUT_FOR_CALLBACK_MESSAGES_IN_TRANSMIT);
}
/**
* Returns media information for the given command.
*
* @param command command to execute
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive log entries
* @param statisticsCallback callback that will receive statistics
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationFromCommand(final String command,
final ExecuteCallback executeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final Integer waitTimeout) {
return getMediaInformationFromCommandArguments(FFmpegKit.parseArguments(command), executeCallback, logCallback, statisticsCallback, waitTimeout);
}
private static MediaInformationSession getMediaInformationFromCommandArguments(final String[] arguments,
final ExecuteCallback executeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final Integer waitTimeout) {
final MediaInformationSession session = new MediaInformationSession(arguments, executeCallback, logCallback, statisticsCallback);
FFmpegKitConfig.getMediaInformationExecute(session, waitTimeout);
return session;
}
}