I am just interested in raw uncompressed data and not particularly raw bayer data, I assumed a *.yuv format video sequence generated using the simple python code :

import time
from picamera import PiCamera

camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 30
camera.iso = 400
camera.shutter_speed = 3000
ext = 'yuv'
fileName = '/home/pi/video/stream_' + time.strftime('%d-%m-%Y_%H-%M-%S') + "." + ext 
camera.start_recording(fileName, ext)

should have been good enough. But for some reason the generated recording had missing frames and the quality did not really impress me. The missing frame problem seems to be solved for a lower resolution i.e., "320x240" or a lower frame rate i.e., 5 fps at "640x480" resolution. The specifications are as follows :

  • Raspberry Pi 2 model B
  • CPU freq. overclocked to 1 GHz
  • GPU memory 128
  • 32 GB ultra class 3 SD-Card

The problem persists even if I caputure images using the following code:

import io
import time
import picamera
import cv2 

frames = 1800

with picamera.PiCamera() as camera:
   camera.resolustion = (640, 480)
   camera.framerate = 30
   camera.shutter_speed = 2500
   start = time.time()
   camera.capture_sequence(['images%04d.yuv'%i for i in range(frames)], 'yuv' , use_video_port=True)
   finish = time.time()
print('Captured %d frames at %.2ffps' % ( 
frames / (finish - start)))

and convert it to a video stream using FFmpeg as:

ffmpeg -f image2 -r 30 -s 640x480 -pix_fmt yuv420p -vcodec rawvideo -i images%04d.yuv -vcodec ffvhuff video.avi

I can't seem to understand the reason behind the missing frames, I assume it has something to do with the writing speed, the video buffer, memory at most. I would really appreciate if someone can point me in the right direction.

Note : The video recording seems to work fine for .h264 format. Which is awkward since it should be slower compared to raw formats due to the encoding step.

1 Answer 1


You are using a Class3 SD card. They are too slow for the normal operation of a Raspberry Pi, they are even too slow for the normal operation of most digital cameras. Get a Class 10 SD card or faster, they are common and rather inexpensive now.

The reason the compressed video works fine and the raw video does not, is that the compressed video, although needing an extra processing step, has much less data to write to the SD card than the raw video.

  • It's an ultra high speed class 3 SanDisk U3.
    – Ragesam
    Jun 23, 2016 at 17:43
  • 1
    Ah! UHS Class 3. That's not the same as plain old Class 3. Since your compressed video isn't having any trouble, your raw video is probably just too much data to write in real-time for the Pi. Try boosting your GPU memory to 256MB or 512MB, it might help.
    – tlhIngan
    Jun 23, 2016 at 17:54
  • @tlhlngan: thanks for the quick response, Have tried varying GPU memory splits but the problem persists. I fail to localize the problem as to what might be causing this behavior. Bought the UHS class 3 sd-card thinking that class 10 is slower so that might be the reason, as it turns out I was wrong there. any other suggestions ?
    – Ragesam
    Jun 24, 2016 at 8:13
  • BTW, even plain old class 3 would offer you 3MB/s, more than enough for a DVD-quality video. Class 4 already supports Full HD. So the issue can hardly be explained by the SD card. Nov 28, 2016 at 10:40
  • For anyone trying to make sense of this discussion -- there are two "classes" with respect to the speed of an SD card. Speed Classes are generally even numbers and appear inside a letter "C". UHS Speed Classes are generally odd numbers and appear inside a letter "U." While the names are similar, the measurements are totally different. A normal Speed Class of 2 or 4 might be too slow for the raspberry pi to write video to, however a UHS Speed class of 3 should be plenty fast enough. Apr 24, 2021 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.