Explaining Pi Camera

Part 4.5 of the series

Pi Camera NoIR

In my last post, I discussed about setting up a surveillance system using Pi camera, which can e-mail the video files as well.

Before jumping onto the topic that I mentioned last time, let’s have a look at a few points that I was not able to discuss in last post.

PiCamera readthedocs have a great explanation for working of camera’s hardware. Right now I am focusing on the following topics.

Resolution —
According to the documentation, there is a set of modes available to create a video. The lowest mode suggests resolution of 640*480. And the docs also suggests that if I select a resolution, the camera algorithm either upscale or downscale the res to nearest available values w.r.t to the modes. Though the algorithm will prefer to downscale only.

Now I used 320*240 resolution to create a video. According to what I stated from the docs, the algorithm cannot downscale the res, so it should upscale it.

To test this, I created 2 videos which have the same background in it’s frame. The 320*240 one was 3.5MB in size, but the 640*480 was 16.3MB in size. Why was there this much difference in size? The resolution justifies the difference in size but the algorithm should had upscale the res to 640*480. What happened here?

Some digging in on the subject and I was able to find only 1 link that is stating minimum resolution as 64*64.

To test this I set the resolution to 64*64 in my code, and it worked, though the video was very pixelated. I lowered the resolution further to 32*32, and that worked as well. 16*16 did not worked, so as other lower resolutions. I got the following error. I tried 31*31 and got the same error. So 32*32 is the minimum resolution.

mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1f9b380 (EINVAL)

Encoders —
Pi Camera supports 2 video encoders, that are, h264 and mjpeg
As I mentioned in my last post, when I tried creating mp4 file directly, the code gave my an error, so I created a h264 file and converted that to mp4 file afterwards.

Later on I also tried creating mjpeg file. This format takes a lot more space than h264. A 3 min 640*480 resolution h264 file size is around 16–20 MB. While a mjpeg file is 180 MB.

Also you cannot run the mjpeg video in VLC Player. It takes the video as a jpeg file and display only one frame. I had to use MPlayer to run the video.

sudo apt-get install mplayer
mplayer
mplayer /path/to/mjpeg/video/file
Mplayer running in terminal

Also MP4Box is unable to convert mjpeg to mp4. It gave this error —

Trying to convert mjpeg using MP4Box

So mjpeg format is not the right option for my current use case.

That’s all for this post. Stay Tuned!

Hacking the Physical World | Senior Embedded Systems Engineer @ PiRhoAlpha Research (ActiveBuildings) | I write posts about AVR and Raspberry Pi.