如何从ffmpeg管道输出

时间:2015-02-27 18:02:11

标签: c# ffmpeg pipe

我有一个c#桌面应用。

我想将RTSP源从我的相机流式传输到我的应用程序,并在我的应用程序中保存jpegs。

我使用mpdecimate来限制更改前一帧的帧。

如果我打开DOS窗口并输入:

ffmpeg -i rtsp://admin:admin@192.168.0.17:554/video_0 -vf mpdecimate -r 10 output.avi 2>log.txt 

它有效。

如果我把它放到C#app中,日志文件会报告:

   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

所以,我用我认为可以使它工作的东西调整它但仍然有同样的错误。

这是我最后一次尝试:

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
}

任何建议我都会试试......

0 个答案:

没有答案