I tried the FFmpeg library but the code seems not working.
public void MergeVideos(string[] videoPaths, string outputFilePath)
{
// Combine video paths into FFmpeg command
string command = "ffmpeg -i concat:" + string.Join("|", videoPaths[0]) + " -c copy " + outputFilePath;
// Execute FFmpeg command
ExecuteFFmpegCommand(command);
}
private void ExecuteFFmpegCommand(string command)
{
try
{
// Start the FFmpeg process
Process ffmpegProcess = new Process
{
StartInfo =
{
FileName = "ffmpeg.exe", // Assuming ffmpeg.exe is in the PATH environment variable
Arguments = command,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = false
}
};
// Subscribe to process output data events
ffmpegProcess.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
ffmpegProcess.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
// Start process and redirect output
ffmpegProcess.Start();
ffmpegProcess.BeginOutputReadLine();
ffmpegProcess.BeginErrorReadLine();
// Wait for process to exit
ffmpegProcess.WaitForExit();
}
Are there bugs in the above code? Or Is there some other easier way to do it?
Thanks.

Tuhin PaulPosted Mar 10, 2024, 3:00 AM
To correctly concatenate all video paths in the array, we should use
string.Joinon the entirevideoPathsarray, not justvideoPaths[0].In this improvement:
I added a check to ensure that the
videoPathsarray is not null or empty before attempting to concatenate the paths. If the array is empty or null, anArgumentExceptionis thrown to indicate the error.I updated
string.Jointo concatenate all video paths in thevideoPathsarray, ensuring that the correct FFmpeg command is generated with all video paths included in the concatenation.With this improvement, the
MergeVideosmethod will correctly concatenate all video paths provided in thevideoPathsarray when generating the FFmpeg command.Kasun LeePosted Mar 5, 2024, 1:27 PM
>> I think when joining the video paths into a single command, you are using string.Join on videoPaths[0], which would only concatenate the first video path. You should concatenate all video paths in the array.
Yes, my bad, fixed it, but still it's not working. ffmpeg.exe is being executed, but the video merging does not happen...
Amit MohantyPosted Mar 5, 2024, 7:20 AM
I think when joining the video paths into a single command, you are using string.Join on videoPaths[0], which would only concatenate the first video path. You should concatenate all video paths in the array.