title: How can I continue recording a video stream (webm, vp8) to an existing file (using C#)?
body: <p><strong>Encountered the following problem:</strong>
  From the client side using websocket I drive the video bit by bit to the server:</p>
  <pre class="lang-js prettyprint-override"><code>mediaRecorder.ondataavailable = function (e) {
     if (ws &amp;&amp; ws.readyState === WebSocket.OPEN &amp;&amp; e.data &amp;&amp; e.data.size &gt; 0) {
        ws.send(e.data);
     }
     else {
        //...
     }
  }
  mediaRecorder.start(100);
  </code></pre>
  
  <p>On the server in a loop, I get these parts and write them to a file.</p>
  <pre><code>while (true)
  {
     buffer = new ArraySegment&lt;byte&gt;(new byte[500000]);
     result = await socket.ReceiveAsync(buffer, CancellationToken.None);
     if (socket.State == WebSocketState.CloseReceived)
     {
        bw.Close();
        fs.Close();
        break;
     }
     if (Encoding.UTF8.GetString(buffer.Array, 0, result.Count) == &quot;start record&quot;)
     {
        writeStatus = &quot;start record&quot;;
        fullPath = $&quot;{context.Server.MapPath(&quot;~&quot;)}{fileName}.{fileExt}&quot;;
        fs = new FileStream(fullPath, FileMode.Append, FileAccess.Write);
        bw = new BinaryWriter(fs);
        continue;
     }
  
     if (Encoding.UTF8.GetString(buffer.Array, 0, result.Count) == &quot;stop record&quot;)
     {
        bw.Close();
        fs.Close();
        writeStatus = &quot;none&quot;;
        continue;
     }
  
     if (writeStatus == &quot;start record&quot;)
     {
        bw.Write(buffer.Array, 0, result.Count);
        pos += result.Count;
     }
  }
  </code></pre>
  <p>The problem is that I need to keep writing videos to the same file every time the page is reloaded. As I understand it, just adding to the end of the file is not an option, since in this case all the bytes added are not played when playing the recorded video file. Tell me, please, how can I continue recording video in the same file?</p>