Skip to content

Instantly share code, notes, and snippets.

@lucasnegrao
Created September 27, 2024 23:45
Show Gist options
  • Select an option

  • Save lucasnegrao/ec614bb2073469534f00f5c0e5722709 to your computer and use it in GitHub Desktop.

Select an option

Save lucasnegrao/ec614bb2073469534f00f5c0e5722709 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
// Calculate the required buffer size
size_t command_size = strlen("ffmpeg.exe") + 1;
for (int i = 1; i < argc; i++) {
command_size += strlen(argv[i]) + 3; // For space, quotes, and null terminator
}
char *command = malloc(command_size);
if (!command) {
perror("Failed to allocate memory");
return 1;
}
// Build the FFmpeg command from the provided arguments
strcpy(command, "ffmpeg.exe");
// Append each argument to the command
for (int i = 1; i < argc; i++) {
strcat(command, " \"");
strcat(command, argv[i]);
strcat(command, "\"");
}
int result = 0;
int retries = 0;
int max_retries = 5;
do {
result = system(command);
if (result != 0) {
printf("FFmpeg stopped unexpectedly, restarting...\n");
retries++;
}
} while (result != 0 && retries < max_retries);
if (result == 0) {
printf("FFmpeg finished successfully.\n");
} else {
fprintf(stderr, "FFmpeg failed after %d retries.\n", retries);
}
free(command);
return result == 0 ? 0 : 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment