/// <summary>
        /// Writes video frame to output. Make sure to call OpenWrite() before calling this.
        /// </summary>
        /// <param name="frame">Frame containing audio data</param>
        public void WriteFrame(VideoFrame frame)
        {
            if (!OpenedForWriting)
            {
                throw new InvalidOperationException("Media needs to be prepared for writing first!");
            }

            InputDataStreamVideo.Write(frame.RawData.Span);
        }
        /// <summary>
        /// Closes output video.
        /// </summary>
        public void CloseWrite()
        {
            if (!OpenedForWriting)
            {
                throw new InvalidOperationException("File is not opened for writing!");
            }

            try
            {
                InputDataStreamAudio?.Dispose();
                InputDataStreamVideo?.Dispose();

                connected_socket?.Shutdown(SocketShutdown.Both);
                connected_socket?.Close();
                socket?.Close();

                ffmpegp.WaitForExit();
                csc?.Cancel();

                if (!UseFilename)
                {
                    OutputDataStream?.Dispose();
                }

                try
                {
                    if (ffmpegp?.HasExited == false)
                    {
                        ffmpegp.Kill();
                    }
                }
                catch { }
            }
            finally
            {
                OpenedForWriting = false;
            }
        }