Пример #1
0
        private string GetFFMpegArguments(EncoderSettings settings)
        {
            String args = "";

            args += " -y ";
            args += " -f rawvideo ";
            args += " -pixel_format bgr24 ";
            args += String.Format(" -video_size {0}x{1} ", width, height);
            args += " -framerate " + settings.framerate;
            args += " -i - ";
            args += String.Format(" -vb {0}K ", settings.videoRate);
            args += " -c:v " + settings.codec;
            args += "  -tune zerolatency ";
            args += String.Format(" -video_size {0}x{1} ", width, height);
            args += " -f mpegts ";
            args += " -bufsize 2M -g 300 -ps 4096 ";
            args += " - ";

            return args;
        }
Пример #2
0
        public void StartEncoding(EncoderSettings settings)
        {
            if (IsEncoding)
            {
                return;
            }

            lock (this)
            {
                started = true;
            }

            totalBytes = 0;
            frameBuffers.Clear();

            // Create new buffer pools in case threads are still doing things
            frameBuffers = new BufferPool();
            encodedBuffers = new BufferPool();

            process = new Process();
            process.StartInfo.Arguments = GetFFMpegArguments(settings);
            process.StartInfo.FileName = ffmpeg.Path;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.Start();

            readThread = new VideoEncoderReadThread(this, process, encodedBuffers);
            writeThread = new VideoEncoderWriteThread(this, process, frameBuffers);
            errorThread = new VideoEncoderErrorThread(this, process);

            errorThread.Start();
            readThread.Start();
            writeThread.Start();
        }