I have a c# desktop app.
I want to stream an RTSP feed from my camera to my app, and in my app save jpegs as they come through.
I use mpdecimate to restrict frames that are changes to the previous frame.
If I open a DOS windows and type in:
ffmpeg -i rtsp://admin:admin@192.168.0.17:554/video_0 -vf mpdecimate -r 10 output.avi 2>log.txt
it works.
if I put this into a C# app the log file reports:
ffmpeg version N-69779-g2a72b16 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
libavutil 54. 18.100 / 54. 18.100
libavcodec 56. 22.100 / 56. 22.100
libavformat 56. 21.100 / 56. 21.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.100 / 5. 11.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, rtsp, from 'rtsp://admin:admin@192.168.0.17:554/video_0':
Metadata:
title : YOKO Live Streaming
comment : video_0
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 352x288 [SAR 1:1 DAR 11:9], 90k tbr, 90k tbn, 90k tbc
[NULL @ 04d6a1e0] Unable to find a suitable output format for 'mpdecimate'
mpdecimate: Invalid argument
So, I tweaked it with things I thought would make it work but still teh same error.
This is my last attempt at this:
Process process = new Process();
{
FileStream baseStream = null;
string arguments = "-i rtsp://admin:admin@192.168.0.17:554/video_0 -vf image2pipe mpdecimate -r 10 - 0";
string file = @"C:\bin\ffmpeg.exe";
process.StartInfo.FileName = file;
process.StartInfo.Arguments = arguments;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
Task.Run(() =>
{
try
{
process.Start();
byte[] buffer = new byte[200000];
var error = process.StandardError.ReadToEnd();
baseStream = process.StandardOutput.BaseStream as FileStream;
bool gotHeader = false;
bool imgFound = false;
int counter = 0;
while (true)
{
byte bit1 = (byte)baseStream.ReadByte();
buffer[counter] = bit1;
if (bit1 == 217 && gotHeader)
{
if (buffer[counter - 1] == 255)
{
byte[] jpeg = new byte[counter];
Buffer.BlockCopy(buffer, 0, jpeg, 0, counter);
using (MemoryStream ms = new MemoryStream(jpeg))
{
pictureBox1.Image = Image.FromStream(ms);
ms.Close();
}
imgFound = true;
}
}
else if (bit1 == 216)
{
if (buffer[counter - 1] == 255)
{
gotHeader = true;
}
}
if (imgFound)
{
counter = 0;
buffer = new byte[200000];
imgFound = false;
gotHeader = false;
}
else
{
counter++;
}
}
}
catch (Exception ex2)
{
//log error here
}
});
}
catch (Exception ex)
{
//log error here
}
any suggestion I will glady try out...