Ejemplo n.º 1
0
        //録画開始
        static Task StartRecording(HttpListenerContext context)
        {
            WriteLog($"StartRecording");

            var request  = context.Request;
            var response = context.Response;

            lock (syncOutput)
            {
                if (videoOutputStream != null)
                {
                    throw new ApplicationException("Already recording");
                }

                var videoName     = GetTimestampString() + videoExtension;
                var videoFilePath = Path.Combine(videoDir, videoName);
                WriteLog($"    {videoName}");
                Directory.CreateDirectory(Path.GetDirectoryName(videoFilePath));
                var frame = _lastOriginalFrame != null
                    ? lastOriginalFrame
                    : videoInputStream.Read();

                var frameSize = frame.Size();
                WriteLog($"    {frameSize.Width}x{frameSize.Height}");
                videoOutputStream = new VideoOutputStream(videoFilePath, FourCC.XVID, 15, GetOutputSize(frameSize));
                videoOutputStream.Start();
            }

            response.StatusCode = (int)HttpStatusCode.NoContent;
            response.Close();

            return(Task.CompletedTask);
        }