Skip to content

Instantly share code, notes, and snippets.

@Jet-C
Created June 5, 2021 06:31
Show Gist options
  • Save Jet-C/3c8d822eb19c4ac9024c0376287e0fb4 to your computer and use it in GitHub Desktop.
Save Jet-C/3c8d822eb19c4ac9024c0376287e0fb4 to your computer and use it in GitHub Desktop.
Method for concatenating .ts video pieces using FFmpeg concat command
private void executeFFMPEG(String outputFilePath, String ffmpegInputFileNames) {
System.out.println("\nExecuting ffmpeg with output path = " + outputFilePath + "\n");
System.out.println("Input ffmpegInputFileNames character length >> " + ffmpegInputFileNames.length());
// Build ffmpeg tool command and execute
// ffmpeg will concat all our *.ts files and produce a single output video file
ProcessBuilder processBuilder = new ProcessBuilder();
String commandStr = "ffmpeg -i \"concat:" + ffmpegInputFileNames + "\" -c copy " + outputFilePath;
// Run this on Windows, cmd, /c = terminate after this run
processBuilder.command("cmd.exe", "/c", commandStr);
processBuilder.redirectErrorStream(true);
try {
System.out.println("Executing command - " + commandStr);
Process process = processBuilder.start();
// Let's read and print the ffmpeg's output
BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment