title: File size limit in making timelapse video on the fly with OpenCV, Picamera and an IR camera
body: <p>I am creating a raspberry pi timelapse camera encoding video with CV2 videowriter
  Each image captured with picamera is added to the videowriter and once the intended number of images are taken the videowriter closes.</p>
  <p>However - while this works for a few thousand images - it stops at some limit with a filesize of 366Mb which is now frustrating me and I ask you - the internet and hoard of coders to tell me why I am bad a coding and how to fix this - you must be tempted by this..</p>
  <p>Here is my offering of garbage for you to laugh pitifully at</p>
  <pre><code>import os, cv2
  from picamera import PiCamera
  from picamera.array import PiRGBArray
  from datetime import datetime
  from time import sleep
  
  now = datetime.now()
  x = now.strftime(&quot;%Y&quot;)+&quot;-&quot;+now.strftime(&quot;%m&quot;)+&quot;-&quot;+now.strftime(&quot;%d&quot;)+&quot;-&quot;+now.strftime(&quot;%H&quot;)+&quot;-&quot;+now.strftime(&quot;%M&quot;)  #string of dateandtimestart
  print(x)
  def main():
    imagenum = 10000 #how many images
    period = 1 #seconds between images
    os.chdir (&quot;/home/pi/t_lapse&quot;)
    os.mkdir(x)
    os.chdir(x)
    filename = x + &quot;.avi&quot;
  
    camera = PiCamera()
    camera.resolution=(1920,1088)
    camera.vflip = True
    camera.hflip = True
    camera.color_effects = (128,128) #makes a black and white image for IR camera
    sleep(0.1)
    out = cv2.VideoWriter(filename, cv2.cv.CV_FOURCC(*'XVID'), 30, (1920,1088))
    for c in range(imagenum):
        with PiRGBArray(camera, size=(1920,1088)) as output:
            camera.capture(output, 'bgr')
            imagec = output.array
            out.write(imagec)
            output.truncate(0) #trying to get more than 300mb files..
            pass
        sleep(period-0.5)
  
    camera.close()
    out.release()
  if __name__ == '__main__':
    main()
  </code></pre>
  <p>This example is a part of the whole code I've written (<a href="https://github.com/gchennell/RPi-PiLapse" rel="nofollow noreferrer">https://github.com/gchennell/RPi-PiLapse</a>) which has an OLED display and buttons and selection of how many images as I have this all in an enclosure - the number of images seems to be limited to about 3000-4000 and then it just gives up and goes home... I tried adding the output.truncate(0)
  I have also recreated this in python3 before you cry &quot;BUT CV2.CV2.VIDEOWRITER!!!!&quot; and that hasn't changed a thing - I'm missing something here...</p>