title: How to remove frames from a video file recorded with Aforge
body: <p>I have to implement via software a CCTV circuit with AForge.
  I can write a video file with</p>
  <pre><code> private VideoFileWriter FileWriter = new VideoFileWriter();
  </code></pre>
  <p>and write a new frame with</p>
  <pre><code>private void LocalWebCam_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
  {
     try
     {
        Image img = (Bitmap)eventArgs.Frame.Clone();
  
         MemoryStream ms = new MemoryStream();
         img.Save(ms, ImageFormat.Bmp);
         ms.Seek(0, SeekOrigin.Begin);
         bi = new BitmapImage();
         bi.BeginInit();
         bi.StreamSource = ms;
         bi.EndInit();
  
         bi.Freeze();
         Dispatcher.BeginInvoke(new ThreadStart(delegate
         { frameHolder.Source = bi; }));
  
         FileWriter.WriteVideoFrame(BitmapImage2Bitmap(bi));
     }
     catch (Exception ex)
     {}
  }
  </code></pre>
  <p>So the file writing by frame adding is fine.</p>
  <p>So in order not to fill the hd with huge files I decide for example that when the avi file reaches 10MBs it is split to a new file</p>
  <p>1.avi is renamed to 2.avi and a new file is started</p>
  <blockquote>
  <p>1.avi --&gt; 2.avi</p>
  </blockquote>
  <p>then</p>
  <blockquote>
  <p>1.avi --&gt; 2.avi --&gt; 3.avi</p>
  </blockquote>
  <p>and so on. Eventually when I will have 1.avi 2.avi... 10.avi 11.avi I will delete 11.avi
  so to always have 10 file. A rolling system.
  And that works but is not smart all.</p>
  <p>What would be great instead is that of file dividing when reaching a certain size I continue adding the new frames at the end AND I remove the new frames at the beginning so that the whole avi file size does not exceeds a certain size and I ALWAYS have the last minutes of registration</p>
  <p><a href="https://i.stack.imgur.com/fnMR6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fnMR6.png" alt="enter image description here" /></a></p>