I am looking some tip or idea in order to process an stream of jpg files created by a fFMPEG command.
There is a way to split the outpuStream to capture each jpg file?
Here is the command ffmpeg -i rtsp://somertsp:554 -an -f image2pipe -vf fps=fps=5 -
I execute that command using a C# application.
Here is a example code
class Program
{
private static BackgroundWorker worker;
private static MemoryStream buffer = new MemoryStream();
private static BinaryWriter bufferWriter = new BinaryWriter(buffer);
static void Main(string[] args)
{
string file = @"C:\ffmpeg\bin\ffmpeg.exe";
string arguments = @"-i rtsp://xxx:yyy@v5demo.wavestore.com:554/rtsp/00004 -an -f image2pipe -vf fps=fps=5 -qscale 0 -";
var processStartInfo = new ProcessStartInfo(file, arguments);
processStartInfo.CreateNoWindow = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.WorkerReportsProgress = true;
worker.ProgressChanged += worker_ProgressChanged;
var process = new Process();
process.StartInfo = processStartInfo;
process.Start();
worker.RunWorkerAsync(process);
process.WaitForExit();
}
static void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// save the image
}
static void worker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
var internalWorker = sender as BackgroundWorker;
Process p = e.Argument as Process;
buffer = new MemoryStream();
bufferWriter = new BinaryWriter(buffer);
using (var reader = new BinaryReader(p.StandardOutput.BaseStream))
{
while (true)
{
//get the jpg image
}
}
}
catch (Exception ex)
{
// Log the error, continue processing the live stream
}
}
}