parseArguments and argumentsToString moved under FFmpegKitConfig
This commit is contained in:
parent
68cbf69e80
commit
caa53bedd8
|
@ -191,7 +191,7 @@ public abstract class AbstractSession implements Session {
|
|||
|
||||
@Override
|
||||
public String getCommand() {
|
||||
return FFmpegKit.argumentsToString(arguments);
|
||||
return FFmpegKitConfig.argumentsToString(arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -148,7 +148,7 @@ public class FFmpegKit {
|
|||
* @return FFmpeg session created for this execution
|
||||
*/
|
||||
public static FFmpegSession execute(final String command) {
|
||||
return execute(parseArguments(command));
|
||||
return execute(FFmpegKitConfig.parseArguments(command));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,7 +162,7 @@ public class FFmpegKit {
|
|||
*/
|
||||
public static FFmpegSession executeAsync(final String command,
|
||||
final ExecuteCallback executeCallback) {
|
||||
return executeAsync(parseArguments(command), executeCallback);
|
||||
return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +180,7 @@ public class FFmpegKit {
|
|||
final ExecuteCallback executeCallback,
|
||||
final LogCallback logCallback,
|
||||
final StatisticsCallback statisticsCallback) {
|
||||
return executeAsync(parseArguments(command), executeCallback, logCallback, statisticsCallback);
|
||||
return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,7 +196,7 @@ public class FFmpegKit {
|
|||
public static FFmpegSession executeAsync(final String command,
|
||||
final ExecuteCallback executeCallback,
|
||||
final ExecutorService executorService) {
|
||||
final FFmpegSession session = new FFmpegSession(parseArguments(command), executeCallback);
|
||||
final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), executeCallback);
|
||||
|
||||
FFmpegKitConfig.asyncFFmpegExecute(session, executorService);
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class FFmpegKit {
|
|||
final LogCallback logCallback,
|
||||
final StatisticsCallback statisticsCallback,
|
||||
final ExecutorService executorService) {
|
||||
final FFmpegSession session = new FFmpegSession(parseArguments(command), executeCallback, logCallback, statisticsCallback);
|
||||
final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback);
|
||||
|
||||
FFmpegKitConfig.asyncFFmpegExecute(session, executorService);
|
||||
|
||||
|
@ -262,84 +262,4 @@ public class FFmpegKit {
|
|||
return FFmpegKitConfig.getFFmpegSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Parses the given command into arguments. Uses space character to split the arguments.
|
||||
* Supports single and double quote characters.
|
||||
*
|
||||
* @param command string command
|
||||
* @return array of arguments
|
||||
*/
|
||||
public static String[] parseArguments(final String command) {
|
||||
final List<String> argumentList = new ArrayList<>();
|
||||
StringBuilder currentArgument = new StringBuilder();
|
||||
|
||||
boolean singleQuoteStarted = false;
|
||||
boolean doubleQuoteStarted = false;
|
||||
|
||||
for (int i = 0; i < command.length(); i++) {
|
||||
final Character previousChar;
|
||||
if (i > 0) {
|
||||
previousChar = command.charAt(i - 1);
|
||||
} else {
|
||||
previousChar = null;
|
||||
}
|
||||
final char currentChar = command.charAt(i);
|
||||
|
||||
if (currentChar == ' ') {
|
||||
if (singleQuoteStarted || doubleQuoteStarted) {
|
||||
currentArgument.append(currentChar);
|
||||
} else if (currentArgument.length() > 0) {
|
||||
argumentList.add(currentArgument.toString());
|
||||
currentArgument = new StringBuilder();
|
||||
}
|
||||
} else if (currentChar == '\'' && (previousChar == null || previousChar != '\\')) {
|
||||
if (singleQuoteStarted) {
|
||||
singleQuoteStarted = false;
|
||||
} else if (doubleQuoteStarted) {
|
||||
currentArgument.append(currentChar);
|
||||
} else {
|
||||
singleQuoteStarted = true;
|
||||
}
|
||||
} else if (currentChar == '\"' && (previousChar == null || previousChar != '\\')) {
|
||||
if (doubleQuoteStarted) {
|
||||
doubleQuoteStarted = false;
|
||||
} else if (singleQuoteStarted) {
|
||||
currentArgument.append(currentChar);
|
||||
} else {
|
||||
doubleQuoteStarted = true;
|
||||
}
|
||||
} else {
|
||||
currentArgument.append(currentChar);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentArgument.length() > 0) {
|
||||
argumentList.add(currentArgument.toString());
|
||||
}
|
||||
|
||||
return argumentList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Concatenates arguments into a string adding a space character between two arguments.
|
||||
*
|
||||
* @param arguments arguments
|
||||
* @return concatenated string containing all arguments
|
||||
*/
|
||||
public static String argumentsToString(final String[] arguments) {
|
||||
if (arguments == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (i > 0) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
stringBuilder.append(arguments[i]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -611,7 +611,7 @@ public class FFmpegKitConfig {
|
|||
ffmpegSession.complete(new ReturnCode(returnCode));
|
||||
} catch (final Exception e) {
|
||||
ffmpegSession.fail(e);
|
||||
android.util.Log.w(FFmpegKitConfig.TAG, String.format("FFmpeg execute failed: %s.%s", FFmpegKit.argumentsToString(ffmpegSession.getArguments()), Exceptions.getStackTraceString(e)));
|
||||
android.util.Log.w(FFmpegKitConfig.TAG, String.format("FFmpeg execute failed: %s.%s", FFmpegKitConfig.argumentsToString(ffmpegSession.getArguments()), Exceptions.getStackTraceString(e)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -628,7 +628,7 @@ public class FFmpegKitConfig {
|
|||
ffprobeSession.complete(new ReturnCode(returnCode));
|
||||
} catch (final Exception e) {
|
||||
ffprobeSession.fail(e);
|
||||
android.util.Log.w(FFmpegKitConfig.TAG, String.format("FFprobe execute failed: %s.%s", FFmpegKit.argumentsToString(ffprobeSession.getArguments()), Exceptions.getStackTraceString(e)));
|
||||
android.util.Log.w(FFmpegKitConfig.TAG, String.format("FFprobe execute failed: %s.%s", FFmpegKitConfig.argumentsToString(ffprobeSession.getArguments()), Exceptions.getStackTraceString(e)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -651,7 +651,7 @@ public class FFmpegKitConfig {
|
|||
}
|
||||
} catch (final Exception e) {
|
||||
mediaInformationSession.fail(e);
|
||||
android.util.Log.w(FFmpegKitConfig.TAG, String.format("Get media information execute failed: %s.%s", FFmpegKit.argumentsToString(mediaInformationSession.getArguments()), Exceptions.getStackTraceString(e)));
|
||||
android.util.Log.w(FFmpegKitConfig.TAG, String.format("Get media information execute failed: %s.%s", FFmpegKitConfig.argumentsToString(mediaInformationSession.getArguments()), Exceptions.getStackTraceString(e)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1096,6 +1096,86 @@ public class FFmpegKitConfig {
|
|||
FFmpegKitConfig.globalLogRedirectionStrategy = logRedirectionStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Parses the given command into arguments. Uses space character to split the arguments.
|
||||
* Supports single and double quote characters.
|
||||
*
|
||||
* @param command string command
|
||||
* @return array of arguments
|
||||
*/
|
||||
public static String[] parseArguments(final String command) {
|
||||
final List<String> argumentList = new ArrayList<>();
|
||||
StringBuilder currentArgument = new StringBuilder();
|
||||
|
||||
boolean singleQuoteStarted = false;
|
||||
boolean doubleQuoteStarted = false;
|
||||
|
||||
for (int i = 0; i < command.length(); i++) {
|
||||
final Character previousChar;
|
||||
if (i > 0) {
|
||||
previousChar = command.charAt(i - 1);
|
||||
} else {
|
||||
previousChar = null;
|
||||
}
|
||||
final char currentChar = command.charAt(i);
|
||||
|
||||
if (currentChar == ' ') {
|
||||
if (singleQuoteStarted || doubleQuoteStarted) {
|
||||
currentArgument.append(currentChar);
|
||||
} else if (currentArgument.length() > 0) {
|
||||
argumentList.add(currentArgument.toString());
|
||||
currentArgument = new StringBuilder();
|
||||
}
|
||||
} else if (currentChar == '\'' && (previousChar == null || previousChar != '\\')) {
|
||||
if (singleQuoteStarted) {
|
||||
singleQuoteStarted = false;
|
||||
} else if (doubleQuoteStarted) {
|
||||
currentArgument.append(currentChar);
|
||||
} else {
|
||||
singleQuoteStarted = true;
|
||||
}
|
||||
} else if (currentChar == '\"' && (previousChar == null || previousChar != '\\')) {
|
||||
if (doubleQuoteStarted) {
|
||||
doubleQuoteStarted = false;
|
||||
} else if (singleQuoteStarted) {
|
||||
currentArgument.append(currentChar);
|
||||
} else {
|
||||
doubleQuoteStarted = true;
|
||||
}
|
||||
} else {
|
||||
currentArgument.append(currentChar);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentArgument.length() > 0) {
|
||||
argumentList.add(currentArgument.toString());
|
||||
}
|
||||
|
||||
return argumentList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Concatenates arguments into a string adding a space character between two arguments.
|
||||
*
|
||||
* @param arguments arguments
|
||||
* @return concatenated string containing all arguments
|
||||
*/
|
||||
public static String argumentsToString(final String[] arguments) {
|
||||
if (arguments == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (i > 0) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
stringBuilder.append(arguments[i]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Enables redirection natively.
|
||||
*/
|
||||
|
|
|
@ -199,7 +199,7 @@ public class FFmpegSession extends AbstractSession implements Session {
|
|||
stringBuilder.append(", endTime=");
|
||||
stringBuilder.append(endTime);
|
||||
stringBuilder.append(", arguments=");
|
||||
stringBuilder.append(FFmpegKit.argumentsToString(arguments));
|
||||
stringBuilder.append(FFmpegKitConfig.argumentsToString(arguments));
|
||||
stringBuilder.append(", logs=");
|
||||
stringBuilder.append(getLogsAsString());
|
||||
stringBuilder.append(", state=");
|
||||
|
|
|
@ -147,7 +147,7 @@ public class FFprobeKit {
|
|||
* @return FFprobe session created for this execution
|
||||
*/
|
||||
public static FFprobeSession execute(final String command) {
|
||||
return execute(FFmpegKit.parseArguments(command));
|
||||
return execute(FFmpegKitConfig.parseArguments(command));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +161,7 @@ public class FFprobeKit {
|
|||
*/
|
||||
public static FFprobeSession executeAsync(final String command,
|
||||
final ExecuteCallback executeCallback) {
|
||||
return executeAsync(FFmpegKit.parseArguments(command), executeCallback);
|
||||
return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +177,7 @@ public class FFprobeKit {
|
|||
public static FFprobeSession executeAsync(final String command,
|
||||
final ExecuteCallback executeCallback,
|
||||
final LogCallback logCallback) {
|
||||
return executeAsync(FFmpegKit.parseArguments(command), executeCallback, logCallback);
|
||||
return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,7 +193,7 @@ public class FFprobeKit {
|
|||
public static FFprobeSession executeAsync(final String command,
|
||||
final ExecuteCallback executeCallback,
|
||||
final ExecutorService executorService) {
|
||||
final FFprobeSession session = new FFprobeSession(FFmpegKit.parseArguments(command), executeCallback);
|
||||
final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), executeCallback);
|
||||
|
||||
FFmpegKitConfig.asyncFFprobeExecute(session, executorService);
|
||||
|
||||
|
@ -215,7 +215,7 @@ public class FFprobeKit {
|
|||
final ExecuteCallback executeCallback,
|
||||
final LogCallback logCallback,
|
||||
final ExecutorService executorService) {
|
||||
final FFprobeSession session = new FFprobeSession(FFmpegKit.parseArguments(command), executeCallback, logCallback);
|
||||
final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback);
|
||||
|
||||
FFmpegKitConfig.asyncFFprobeExecute(session, executorService);
|
||||
|
||||
|
@ -335,7 +335,7 @@ public class FFprobeKit {
|
|||
* @return media information session created for this execution
|
||||
*/
|
||||
public static MediaInformationSession getMediaInformationFromCommand(final String command) {
|
||||
final MediaInformationSession session = new MediaInformationSession(FFmpegKit.parseArguments(command));
|
||||
final MediaInformationSession session = new MediaInformationSession(FFmpegKitConfig.parseArguments(command));
|
||||
|
||||
FFmpegKitConfig.asyncGetMediaInformationExecute(session, AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT);
|
||||
|
||||
|
@ -355,7 +355,7 @@ public class FFprobeKit {
|
|||
final ExecuteCallback executeCallback,
|
||||
final LogCallback logCallback,
|
||||
final int waitTimeout) {
|
||||
return getMediaInformationFromCommandArgumentsAsync(FFmpegKit.parseArguments(command), executeCallback, logCallback, waitTimeout);
|
||||
return getMediaInformationFromCommandArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, waitTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -95,7 +95,7 @@ public class FFprobeSession extends AbstractSession implements Session {
|
|||
stringBuilder.append(", endTime=");
|
||||
stringBuilder.append(endTime);
|
||||
stringBuilder.append(", arguments=");
|
||||
stringBuilder.append(FFmpegKit.argumentsToString(arguments));
|
||||
stringBuilder.append(FFmpegKitConfig.argumentsToString(arguments));
|
||||
stringBuilder.append(", logs=");
|
||||
stringBuilder.append(getLogsAsString());
|
||||
stringBuilder.append(", state=");
|
||||
|
|
|
@ -93,7 +93,7 @@ public class MediaInformationSession extends FFprobeSession implements Session {
|
|||
stringBuilder.append(", endTime=");
|
||||
stringBuilder.append(endTime);
|
||||
stringBuilder.append(", arguments=");
|
||||
stringBuilder.append(FFmpegKit.argumentsToString(arguments));
|
||||
stringBuilder.append(FFmpegKitConfig.argumentsToString(arguments));
|
||||
stringBuilder.append(", logs=");
|
||||
stringBuilder.append(getLogsAsString());
|
||||
stringBuilder.append(", state=");
|
||||
|
|
|
@ -199,11 +199,11 @@ public class NativeLoader {
|
|||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
stringBuilder.append(", abis: ");
|
||||
stringBuilder.append(FFmpegKit.argumentsToString(Build.SUPPORTED_ABIS));
|
||||
stringBuilder.append(FFmpegKitConfig.argumentsToString(Build.SUPPORTED_ABIS));
|
||||
stringBuilder.append(", 32bit abis: ");
|
||||
stringBuilder.append(FFmpegKit.argumentsToString(Build.SUPPORTED_32_BIT_ABIS));
|
||||
stringBuilder.append(FFmpegKitConfig.argumentsToString(Build.SUPPORTED_32_BIT_ABIS));
|
||||
stringBuilder.append(", 64bit abis: ");
|
||||
stringBuilder.append(FFmpegKit.argumentsToString(Build.SUPPORTED_64_BIT_ABIS));
|
||||
stringBuilder.append(FFmpegKitConfig.argumentsToString(Build.SUPPORTED_64_BIT_ABIS));
|
||||
} else {
|
||||
stringBuilder.append(", cpu abis: ");
|
||||
stringBuilder.append(Build.CPU_ABI);
|
||||
|
|
|
@ -536,7 +536,7 @@ public class FFmpegKitTest {
|
|||
|
||||
@Test
|
||||
public void parseSimpleCommand() {
|
||||
final String[] argumentArray = FFmpegKit.parseArguments("-hide_banner -loop 1 -i file.jpg -filter_complex [0:v]setpts=PTS-STARTPTS[video] -map [video] -vsync 2 -async 1 video.mp4");
|
||||
final String[] argumentArray = FFmpegKitConfig.parseArguments("-hide_banner -loop 1 -i file.jpg -filter_complex [0:v]setpts=PTS-STARTPTS[video] -map [video] -vsync 2 -async 1 video.mp4");
|
||||
|
||||
Assert.assertNotNull(argumentArray);
|
||||
Assert.assertEquals(14, argumentArray.length);
|
||||
|
@ -559,7 +559,7 @@ public class FFmpegKitTest {
|
|||
|
||||
@Test
|
||||
public void parseSingleQuotesInCommand() {
|
||||
String[] argumentArray = FFmpegKit.parseArguments("-loop 1 'file one.jpg' -filter_complex '[0:v]setpts=PTS-STARTPTS[video]' -map [video] video.mp4 ");
|
||||
String[] argumentArray = FFmpegKitConfig.parseArguments("-loop 1 'file one.jpg' -filter_complex '[0:v]setpts=PTS-STARTPTS[video]' -map [video] video.mp4 ");
|
||||
|
||||
Assert.assertNotNull(argumentArray);
|
||||
Assert.assertEquals(8, argumentArray.length);
|
||||
|
@ -576,7 +576,7 @@ public class FFmpegKitTest {
|
|||
|
||||
@Test
|
||||
public void parseDoubleQuotesInCommand() {
|
||||
String[] argumentArray = FFmpegKit.parseArguments("-loop 1 \"file one.jpg\" -filter_complex \"[0:v]setpts=PTS-STARTPTS[video]\" -map [video] video.mp4 ");
|
||||
String[] argumentArray = FFmpegKitConfig.parseArguments("-loop 1 \"file one.jpg\" -filter_complex \"[0:v]setpts=PTS-STARTPTS[video]\" -map [video] video.mp4 ");
|
||||
|
||||
Assert.assertNotNull(argumentArray);
|
||||
Assert.assertEquals(8, argumentArray.length);
|
||||
|
@ -590,7 +590,7 @@ public class FFmpegKitTest {
|
|||
Assert.assertEquals("[video]", argumentArray[6]);
|
||||
Assert.assertEquals("video.mp4", argumentArray[7]);
|
||||
|
||||
argumentArray = FFmpegKit.parseArguments(" -i file:///tmp/input.mp4 -vcodec libx264 -vf \"scale=1024:1024,pad=width=1024:height=1024:x=0:y=0:color=black\" -acodec copy -q:v 0 -q:a 0 video.mp4");
|
||||
argumentArray = FFmpegKitConfig.parseArguments(" -i file:///tmp/input.mp4 -vcodec libx264 -vf \"scale=1024:1024,pad=width=1024:height=1024:x=0:y=0:color=black\" -acodec copy -q:v 0 -q:a 0 video.mp4");
|
||||
|
||||
Assert.assertNotNull(argumentArray);
|
||||
Assert.assertEquals(13, argumentArray.length);
|
||||
|
@ -612,7 +612,7 @@ public class FFmpegKitTest {
|
|||
|
||||
@Test
|
||||
public void parseDoubleQuotesAndEscapesInCommand() {
|
||||
String[] argumentArray = FFmpegKit.parseArguments(" -i file:///tmp/input.mp4 -vf \"subtitles=file:///tmp/subtitles.srt:force_style=\'FontSize=16,PrimaryColour=&HFFFFFF&\'\" -vcodec libx264 -acodec copy -q:v 0 -q:a 0 video.mp4");
|
||||
String[] argumentArray = FFmpegKitConfig.parseArguments(" -i file:///tmp/input.mp4 -vf \"subtitles=file:///tmp/subtitles.srt:force_style=\'FontSize=16,PrimaryColour=&HFFFFFF&\'\" -vcodec libx264 -acodec copy -q:v 0 -q:a 0 video.mp4");
|
||||
|
||||
Assert.assertNotNull(argumentArray);
|
||||
Assert.assertEquals(13, argumentArray.length);
|
||||
|
@ -631,7 +631,7 @@ public class FFmpegKitTest {
|
|||
Assert.assertEquals("0", argumentArray[11]);
|
||||
Assert.assertEquals("video.mp4", argumentArray[12]);
|
||||
|
||||
argumentArray = FFmpegKit.parseArguments(" -i file:///tmp/input.mp4 -vf \"subtitles=file:///tmp/subtitles.srt:force_style=\\\"FontSize=16,PrimaryColour=&HFFFFFF&\\\"\" -vcodec libx264 -acodec copy -q:v 0 -q:a 0 video.mp4");
|
||||
argumentArray = FFmpegKitConfig.parseArguments(" -i file:///tmp/input.mp4 -vf \"subtitles=file:///tmp/subtitles.srt:force_style=\\\"FontSize=16,PrimaryColour=&HFFFFFF&\\\"\" -vcodec libx264 -acodec copy -q:v 0 -q:a 0 video.mp4");
|
||||
|
||||
Assert.assertNotNull(argumentArray);
|
||||
Assert.assertEquals(13, argumentArray.length);
|
||||
|
@ -658,7 +658,7 @@ public class FFmpegKitTest {
|
|||
}
|
||||
|
||||
public String argumentsToString(final String[] arguments) {
|
||||
return FFmpegKit.argumentsToString(arguments);
|
||||
return FFmpegKitConfig.argumentsToString(arguments);
|
||||
}
|
||||
|
||||
private void assertMediaInput(MediaInformation mediaInformation, String format, String filename) {
|
||||
|
|
|
@ -113,7 +113,7 @@ extern void addSessionToSessionHistory(id<Session> session);
|
|||
}
|
||||
|
||||
- (NSString*)getCommand {
|
||||
return [FFmpegKit argumentsToString:_arguments];
|
||||
return [FFmpegKitConfig argumentsToString:_arguments];
|
||||
}
|
||||
|
||||
- (void)waitForAsynchronousMessagesInTransmit:(int)timeout {
|
||||
|
|
|
@ -176,23 +176,6 @@
|
|||
*/
|
||||
+ (NSArray*)listSessions;
|
||||
|
||||
/**
|
||||
* <p>Parses the given command into arguments. Uses space character to split the arguments.
|
||||
* Supports single and double quote characters.
|
||||
*
|
||||
* @param command string command
|
||||
* @return array of arguments
|
||||
*/
|
||||
+ (NSArray*)parseArguments:(NSString*)command;
|
||||
|
||||
/**
|
||||
* <p>Concatenates arguments into a string adding a space character between two arguments.
|
||||
*
|
||||
* @param arguments arguments
|
||||
* @return concatenated string containing all arguments
|
||||
*/
|
||||
+ (NSString*)argumentsToString:(NSArray*)arguments;
|
||||
|
||||
@end
|
||||
|
||||
#endif // FFMPEG_KIT_H
|
||||
|
|
|
@ -65,31 +65,31 @@
|
|||
}
|
||||
|
||||
+ (FFmpegSession*)execute:(NSString*)command {
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKit parseArguments:command]];
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command]];
|
||||
[FFmpegKitConfig ffmpegExecute:session];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback {
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback];
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
|
||||
[FFmpegKitConfig asyncFFmpegExecute:session];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
|
||||
[FFmpegKitConfig asyncFFmpegExecute:session];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback];
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
|
||||
[FFmpegKitConfig asyncFFmpegExecute:session onDispatchQueue:queue];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue {
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
|
||||
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
|
||||
[FFmpegKitConfig asyncFFmpegExecute:session onDispatchQueue:queue];
|
||||
return session;
|
||||
}
|
||||
|
@ -111,72 +111,4 @@
|
|||
return [FFmpegKitConfig getFFmpegSessions];
|
||||
}
|
||||
|
||||
+ (NSArray*)parseArguments:(NSString*)command {
|
||||
NSMutableArray *argumentArray = [[NSMutableArray alloc] init];
|
||||
NSMutableString *currentArgument = [[NSMutableString alloc] init];
|
||||
|
||||
bool singleQuoteStarted = false;
|
||||
bool doubleQuoteStarted = false;
|
||||
|
||||
for (int i = 0; i < command.length; i++) {
|
||||
unichar previousChar;
|
||||
if (i > 0) {
|
||||
previousChar = [command characterAtIndex:(i - 1)];
|
||||
} else {
|
||||
previousChar = 0;
|
||||
}
|
||||
unichar currentChar = [command characterAtIndex:i];
|
||||
|
||||
if (currentChar == ' ') {
|
||||
if (singleQuoteStarted || doubleQuoteStarted) {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
} else if ([currentArgument length] > 0) {
|
||||
[argumentArray addObject: currentArgument];
|
||||
currentArgument = [[NSMutableString alloc] init];
|
||||
}
|
||||
} else if (currentChar == '\'' && (previousChar == 0 || previousChar != '\\')) {
|
||||
if (singleQuoteStarted) {
|
||||
singleQuoteStarted = false;
|
||||
} else if (doubleQuoteStarted) {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
} else {
|
||||
singleQuoteStarted = true;
|
||||
}
|
||||
} else if (currentChar == '\"' && (previousChar == 0 || previousChar != '\\')) {
|
||||
if (doubleQuoteStarted) {
|
||||
doubleQuoteStarted = false;
|
||||
} else if (singleQuoteStarted) {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
} else {
|
||||
doubleQuoteStarted = true;
|
||||
}
|
||||
} else {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
}
|
||||
}
|
||||
|
||||
if ([currentArgument length] > 0) {
|
||||
[argumentArray addObject: currentArgument];
|
||||
}
|
||||
|
||||
return argumentArray;
|
||||
}
|
||||
|
||||
+ (NSString*)argumentsToString:(NSArray*)arguments {
|
||||
if (arguments == nil) {
|
||||
return @"nil";
|
||||
}
|
||||
|
||||
NSMutableString *string = [NSMutableString stringWithString:@""];
|
||||
for (int i=0; i < [arguments count]; i++) {
|
||||
NSString *argument = [arguments objectAtIndex:i];
|
||||
if (i > 0) {
|
||||
[string appendString:@" "];
|
||||
}
|
||||
[string appendString:argument];
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -381,6 +381,23 @@ typedef NS_ENUM(NSUInteger, Signal) {
|
|||
*/
|
||||
+ (NSString*)sessionStateToString:(SessionState)state;
|
||||
|
||||
/**
|
||||
* <p>Parses the given command into arguments. Uses space character to split the arguments.
|
||||
* Supports single and double quote characters.
|
||||
*
|
||||
* @param command string command
|
||||
* @return array of arguments
|
||||
*/
|
||||
+ (NSArray*)parseArguments:(NSString*)command;
|
||||
|
||||
/**
|
||||
* <p>Concatenates arguments into a string adding a space character between two arguments.
|
||||
*
|
||||
* @param arguments arguments
|
||||
* @return concatenated string containing all arguments
|
||||
*/
|
||||
+ (NSString*)argumentsToString:(NSArray*)arguments;
|
||||
|
||||
@end
|
||||
|
||||
#endif // FFMPEG_KIT_CONFIG_H
|
||||
|
|
|
@ -878,7 +878,7 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
[ffmpegSession complete:[[ReturnCode alloc] init:returnCode]];
|
||||
} @catch (NSException *exception) {
|
||||
[ffmpegSession fail:exception];
|
||||
NSLog(@"FFmpeg execute failed: %@.%@", [FFmpegKit argumentsToString:[ffmpegSession getArguments]], [NSString stringWithFormat:@"%@", [exception callStackSymbols]]);
|
||||
NSLog(@"FFmpeg execute failed: %@.%@", [FFmpegKitConfig argumentsToString:[ffmpegSession getArguments]], [NSString stringWithFormat:@"%@", [exception callStackSymbols]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -890,7 +890,7 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
[ffprobeSession complete:[[ReturnCode alloc] init:returnCode]];
|
||||
} @catch (NSException *exception) {
|
||||
[ffprobeSession fail:exception];
|
||||
NSLog(@"FFprobe execute failed: %@.%@", [FFmpegKit argumentsToString:[ffprobeSession getArguments]], [NSString stringWithFormat:@"%@", [exception callStackSymbols]]);
|
||||
NSLog(@"FFprobe execute failed: %@.%@", [FFmpegKitConfig argumentsToString:[ffprobeSession getArguments]], [NSString stringWithFormat:@"%@", [exception callStackSymbols]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -907,7 +907,7 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
} @catch (NSException *exception) {
|
||||
[mediaInformationSession fail:exception];
|
||||
NSLog(@"Get media information execute failed: %@.%@", [FFmpegKit argumentsToString:[mediaInformationSession getArguments]], [NSString stringWithFormat:@"%@", [exception callStackSymbols]]);
|
||||
NSLog(@"Get media information execute failed: %@.%@", [FFmpegKitConfig argumentsToString:[mediaInformationSession getArguments]], [NSString stringWithFormat:@"%@", [exception callStackSymbols]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1145,4 +1145,72 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
}
|
||||
|
||||
+ (NSArray*)parseArguments:(NSString*)command {
|
||||
NSMutableArray *argumentArray = [[NSMutableArray alloc] init];
|
||||
NSMutableString *currentArgument = [[NSMutableString alloc] init];
|
||||
|
||||
bool singleQuoteStarted = false;
|
||||
bool doubleQuoteStarted = false;
|
||||
|
||||
for (int i = 0; i < command.length; i++) {
|
||||
unichar previousChar;
|
||||
if (i > 0) {
|
||||
previousChar = [command characterAtIndex:(i - 1)];
|
||||
} else {
|
||||
previousChar = 0;
|
||||
}
|
||||
unichar currentChar = [command characterAtIndex:i];
|
||||
|
||||
if (currentChar == ' ') {
|
||||
if (singleQuoteStarted || doubleQuoteStarted) {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
} else if ([currentArgument length] > 0) {
|
||||
[argumentArray addObject: currentArgument];
|
||||
currentArgument = [[NSMutableString alloc] init];
|
||||
}
|
||||
} else if (currentChar == '\'' && (previousChar == 0 || previousChar != '\\')) {
|
||||
if (singleQuoteStarted) {
|
||||
singleQuoteStarted = false;
|
||||
} else if (doubleQuoteStarted) {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
} else {
|
||||
singleQuoteStarted = true;
|
||||
}
|
||||
} else if (currentChar == '\"' && (previousChar == 0 || previousChar != '\\')) {
|
||||
if (doubleQuoteStarted) {
|
||||
doubleQuoteStarted = false;
|
||||
} else if (singleQuoteStarted) {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
} else {
|
||||
doubleQuoteStarted = true;
|
||||
}
|
||||
} else {
|
||||
[currentArgument appendFormat: @"%C", currentChar];
|
||||
}
|
||||
}
|
||||
|
||||
if ([currentArgument length] > 0) {
|
||||
[argumentArray addObject: currentArgument];
|
||||
}
|
||||
|
||||
return argumentArray;
|
||||
}
|
||||
|
||||
+ (NSString*)argumentsToString:(NSArray*)arguments {
|
||||
if (arguments == nil) {
|
||||
return @"nil";
|
||||
}
|
||||
|
||||
NSMutableString *string = [NSMutableString stringWithString:@""];
|
||||
for (int i=0; i < [arguments count]; i++) {
|
||||
NSString *argument = [arguments objectAtIndex:i];
|
||||
if (i > 0) {
|
||||
[string appendString:@" "];
|
||||
}
|
||||
[string appendString:argument];
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -59,31 +59,31 @@
|
|||
}
|
||||
|
||||
+ (FFprobeSession*)execute:(NSString*)command {
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKit parseArguments:command]];
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command]];
|
||||
[FFmpegKitConfig ffprobeExecute:session];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback {
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback];
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
|
||||
[FFmpegKitConfig asyncFFprobeExecute:session];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback {
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
|
||||
[FFmpegKitConfig asyncFFprobeExecute:session];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback];
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
|
||||
[FFmpegKitConfig asyncFFprobeExecute:session onDispatchQueue:queue];
|
||||
return session;
|
||||
}
|
||||
|
||||
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue {
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKit parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
|
||||
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
|
||||
[FFmpegKitConfig asyncFFprobeExecute:session onDispatchQueue:queue];
|
||||
return session;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@
|
|||
}
|
||||
|
||||
+ (MediaInformationSession*)getMediaInformationFromCommand:(NSString*)command {
|
||||
MediaInformationSession* session = [[MediaInformationSession alloc] init:[FFmpegKit parseArguments:command]];
|
||||
MediaInformationSession* session = [[MediaInformationSession alloc] init:[FFmpegKitConfig parseArguments:command]];
|
||||
[FFmpegKitConfig getMediaInformationExecute:session withTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit];
|
||||
return session;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user