racer993
Posts: 60
Joined: Mon Feb 18, 2013 7:27 pm

Re: still capture rate (still FPS)

Wed May 06, 2015 7:31 pm

After reading this thread, I still can't get my head around on how to shoot full frame still at 15 fps.

I've got a Raspberry Pi 2 and mounted a ramdisk in order to avoid the SD card bottleneck.

My objective is to take just 2 pictures as quickly as possible.

When I use the following command:

raspistill -bm -t 100 -tl 0 -o /ramdrive/scan-%01d.jpg -sh 0 -ISO 800 -ss 1000 -n

I get two pictures roughly 0.25s apart or 4 FPS.

Any suggestions on how to get close to 15 fps?

User avatar
jbeale
Posts: 3494
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: still capture rate (still FPS)

Wed May 06, 2015 8:24 pm

I think raspistill is not the right tool for that job.

This post has commands that do 15 fps capture: viewtopic.php?f=43&t=82691#p585569
but note the output is sent to /dev/null, because AFAIK there is no USB/Ethernet/SD card/whatever output on the R-Pi fast enough to sustain that bitrate. If you only need two frames though, I expect the ramdisk ought to be OK.

racer993
Posts: 60
Joined: Mon Feb 18, 2013 7:27 pm

Re: still capture rate (still FPS)

Thu May 07, 2015 6:33 am

Thx for the quick response! I'll give it a shot and let you know.

gordon77
Posts: 4178
Joined: Sun Aug 05, 2012 3:12 pm

Re: still capture rate (still FPS)

Thu May 07, 2015 10:13 am

This is the fastest I've tried, the timings do vary a bit between 70mS and 170mS between frames.
I find the same as you regards raspistill even if I use -bm option, pygame with v4l2 gives similar, and opencv with v4l2 only seems to go upto 960 x720 but manages about 60mS

Code: Select all

import time
import picamera

frames = 10

def filenames():
    frame = 0
    while frame < frames:
        yield 'image%02d.jpg' % frame
        frame += 1

with picamera.PiCamera() as camera:
    camera.resolution = (2592,1944)
    camera.framerate = 30
    camera.start_preview()
    # Give the camera some warm-up time
    time.sleep(2)
    start = time.time()
    camera.capture_sequence(filenames(), use_video_port=True)
    finish = time.time()
print('Captured %d frames at %.2ffps' % (
    frames,
    frames / (finish - start)))

racer993
Posts: 60
Joined: Mon Feb 18, 2013 7:27 pm

Re: still capture rate (still FPS)

Fri May 08, 2015 10:34 am

Hi tried to code, but it seems like that the 2 jpg's end up in a single file. When I open the file with a viewer, I see just one jpg. Maybe it is possible to cut up the file in 2 jpgs, on the other hand from what I've been reading another solution might be streaming to motion, but I have no clue how to do that.

Can someone post an example of either how to cut up a file that contains multiple jpgs or show how I can direct a stream from v4l2 to motion?

I've used the following code:
sudo modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944
v4l2-ctl -p 15
v4l2-ctl -v width=2592,height=1944,pixelformat=3
v4l2-ctl --stream-mmap=3 --stream-count=2 --stream-to=test%1d.jpg

tfv
Posts: 5
Joined: Wed May 06, 2015 2:54 pm

Re: still capture rate (still FPS)

Sun May 10, 2015 4:07 pm

racer993 wrote:After reading this thread, I still can't get my head around on how to shoot full frame still at 15 fps.

I've got a Raspberry Pi 2 and mounted a ramdisk in order to avoid the SD card bottleneck.

My objective is to take just 2 pictures as quickly as possible.

When I use the following command:

raspistill -bm -t 100 -tl 0 -o /ramdrive/scan-%01d.jpg -sh 0 -ISO 800 -ss 1000 -n

I get two pictures roughly 0.25s apart or 4 FPS.

Any suggestions on how to get close to 15 fps?
Have you seen that approach?
http://babaawesam.com/2014/03/24/shooti ... pi-camera/

I know this is not full resolution, but you might end up being quicker trying a video capture.

User avatar
waveform80
Posts: 303
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: still capture rate (still FPS)

Sat May 16, 2015 10:46 pm

racer993 wrote:After reading this thread, I still can't get my head around on how to shoot full frame still at 15 fps.

I've got a Raspberry Pi 2 and mounted a ramdisk in order to avoid the SD card bottleneck.

My objective is to take just 2 pictures as quickly as possible.

When I use the following command:

raspistill -bm -t 100 -tl 0 -o /ramdrive/scan-%01d.jpg -sh 0 -ISO 800 -ss 1000 -n

I get two pictures roughly 0.25s apart or 4 FPS.

Any suggestions on how to get close to 15 fps?

raspistill shoots pictures in the "still mode" of the camera. In this mode, a *lot* of work goes into producing the image including mode switching to the highest resolution, an aggressive denoise algorithm, etc. You're unlikely to get beyond 1fps with this. Shooting video at 15fps (and actually a lot higher) is indeed possible. Here's a little gist I whipped up a while ago which fires up video recording with MJPEG output, then extracts each JPEG from the output as it goes:

https://gist.github.com/waveform80/263b9c8bdcb1e9b79749

On my Pi2 I can *easily* produce 15fps from this (until the disk cache runs out of space and the SD card's IO limitations kick in). Now, as to "full frame", do you just mean "full field of view" (which the above will accomplish happily by 2x2 binning of the input), or do you mean "full resolution" (which the above probably won't manage due to various limitations).

Dave.

User avatar
jbeale
Posts: 3494
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: still capture rate (still FPS)

Sun May 17, 2015 9:06 pm

[quote="waveform80"Here's a little gist I whipped up a while ago which fires up video recording with MJPEG output, then extracts each JPEG from the output as it goes:
https://gist.github.com/waveform80/263b9c8bdcb1e9b79749
.[/quote]
I'm curious about this. I modified your code slightly to wait 2 seconds first for autoexposure, and also raised the resolution to 1920x1080. I pointed it at a basically static scene, but I notice the size of the JPEG files produced go up steadily so the last image is 4x larger than the first. Any idea why that might be the case?

Code: Select all

[email protected] ~/test $ ll
total 5708
-rw-r--r-- 1 pi pi   107652 May 17 13:59 0001.jpg
-rw-r--r-- 1 pi pi   127267 May 17 13:59 0002.jpg
-rw-r--r-- 1 pi pi   151452 May 17 13:59 0003.jpg
-rw-r--r-- 1 pi pi   173122 May 17 13:59 0004.jpg
-rw-r--r-- 1 pi pi   197847 May 17 13:59 0005.jpg
-rw-r--r-- 1 pi pi   225804 May 17 13:59 0006.jpg
-rw-r--r-- 1 pi pi   252406 May 17 13:59 0007.jpg
-rw-r--r-- 1 pi pi   273288 May 17 13:59 0008.jpg
-rw-r--r-- 1 pi pi   300695 May 17 13:59 0009.jpg
-rw-r--r-- 1 pi pi   322719 May 17 13:59 0010.jpg
-rw-r--r-- 1 pi pi   351953 May 17 13:59 0011.jpg
-rw-r--r-- 1 pi pi   375884 May 17 13:59 0012.jpg
-rw-r--r-- 1 pi pi   403292 May 17 13:59 0013.jpg
-rw-r--r-- 1 pi pi   423795 May 17 13:59 0014.jpg
-rw-r--r-- 1 pi pi   423795 May 17 13:59 0015.jpg
-rw-r--r-- 1 pi pi   425328 May 17 13:59 0016.jpg
-rw-r--r-- 1 pi pi   419704 May 17 13:59 0017.jpg
-rw-r--r-- 1 pi pi   423737 May 17 13:59 0018.jpg
-rw-r--r-- 1 pi pi   423003 May 17 13:59 0019.jpg
Here is the code I used:

Code: Select all

#!/usr/bin/python

import io
import picamera
import time

class MyOutput(object):
    def __init__(self):
        self.file_num = 0
        self.output = None

    def write(self, buf):
        if buf.startswith(b'\xff\xd8'):
            if self.output:
                self.output.close()
            self.file_num += 1
            self.output = io.open('%04d.jpg' % self.file_num, 'wb')
        self.output.write(buf)

with picamera.PiCamera() as camera:
    camera.resolution = (1920, 1080)  # 1080p resolution
    camera.start_preview()
    time.sleep(2)
    camera.start_recording(MyOutput(), format='mjpeg')
    camera.wait_recording(1)
    camera.stop_recording()

User avatar
jbeale
Posts: 3494
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: still capture rate (still FPS)

Sun May 17, 2015 9:10 pm

I think it is something about a MJPEG stream bitrate adjustment algorithm; if I run for 2 seconds instead of just one, the JPEG image size stabilizes at the larger value (around 430 kB).

racer993
Posts: 60
Joined: Mon Feb 18, 2013 7:27 pm

Re: still capture rate (still FPS)

Thu Jun 25, 2015 9:57 am

6by9 wrote:Just to quash the rumour, there is no frame averaging on stills captures. There is a more intensive denoise applied to captures which slows it down, but actually most of the delay is due to having to change the sensor mode, which means:
  • Waiting for the end of frame
  • stopping the sensor
  • reprogramming it
  • restarting it
  • waiting most of an exposure time for the first frame, but then dropping it as it is normally corrupted
  • reading out the desired frame
This typically all adds up to at least 90ms, and potentially much much more if you're on more than a 30ms exposure.
There is a way around this, but not currently in the released apps.

I've just played with V4L2 using the commands:
  • sudo modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944
  • v4l2-ctl -p 15
  • v4l2-ctl -v width=2592,height=1944,pixelformat=I420
  • v4l2-ctl --stream-mmap=3 --stream-to=/dev/null --streamcount=1000
and that is reading out at a claimed 15 or 16fps. :D
I have checked and that is genuinely reading the full 5MPix off the sensor and processing it to produce the output frames.
Share and enjoy.
I have tested the code below and can confirm that I get 15 FPS. I am desperately trying to get 2-5 images from the stream converted to single images/files on a ramdisk, but I just can't figure out how to do it.

Is there someone that can point me in the right direction or maybe even does have an example?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23708
Joined: Sat Jul 30, 2011 7:41 pm

Re: still capture rate (still FPS)

Thu Jun 25, 2015 12:32 pm

You could stream the raw YUV420 output from the camera module direct to Ramdisk. Use the raspistilyuv program - that's what it does - and specify a files on ramdisk as the output file. You would need to mod the code to do multiple captures, maybe use timelapse mode or similar?

Note that gives you raw YUV420 files, which you would need to convert to something else to actually use, but there are things like imagemagik to do that.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: still capture rate (still FPS)

Thu Jun 25, 2015 12:47 pm

jamesh wrote:You could stream the raw YUV420 output from the camera module direct to Ramdisk. Use the raspistilyuv program - that's what it does - and specify a files on ramdisk as the output file. You would need to mod the code to do multiple captures, maybe use timelapse mode or similar?

Note that gives you raw YUV420 files, which you would need to convert to something else to actually use, but there are things like imagemagik to do that.
I think you mean raspividyuv. raspistillyuv will still use the stills port and start and stop the sensor.

What format you need the data in depends on use case and what you want to do with it.
NB If you can't process the data at the full rate then do adjust the framerate the camera is producing, otherwise you'll just fill the FIFO with early frames (which it will deliver, just late) before it will then stabilise to producing frames at more regular intervals.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23708
Joined: Sat Jul 30, 2011 7:41 pm

Re: still capture rate (still FPS)

Thu Jun 25, 2015 2:55 pm

6by9 wrote:
jamesh wrote:You could stream the raw YUV420 output from the camera module direct to Ramdisk. Use the raspistilyuv program - that's what it does - and specify a files on ramdisk as the output file. You would need to mod the code to do multiple captures, maybe use timelapse mode or similar?

Note that gives you raw YUV420 files, which you would need to convert to something else to actually use, but there are things like imagemagik to do that.
I think you mean raspividyuv. raspistillyuv will still use the stills port and start and stop the sensor.
Even with the mode specifically set which is what I was thinking? (Has that been implemented in stillyuv? )
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23708
Joined: Sat Jul 30, 2011 7:41 pm

Re: still capture rate (still FPS)

Thu Jun 25, 2015 2:55 pm

6by9 wrote:
jamesh wrote:You could stream the raw YUV420 output from the camera module direct to Ramdisk. Use the raspistilyuv program - that's what it does - and specify a files on ramdisk as the output file. You would need to mod the code to do multiple captures, maybe use timelapse mode or similar?

Note that gives you raw YUV420 files, which you would need to convert to something else to actually use, but there are things like imagemagik to do that.
I think you mean raspividyuv. raspistillyuv will still use the stills port and start and stop the sensor.
Even with the mode specifically set which is what I was thinking? (Has that been implemented in stillyuv? )
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: still capture rate (still FPS)

Thu Jun 25, 2015 3:13 pm

jamesh wrote:Even with the mode specifically set which is what I was thinking? (Has that been implemented in stillyuv? )
-md is implemented in RaspiYUVVid, but not Still.
The answer depends on the preview resolution as that will determine the size of the input pools. Even so, memory says stills colour denoise was limited at about 50MPix/s, so 5MP10, hence having to go for video mode. You'll also be doing a snapshot pass, so you're halving the ISP useful throughput, but that is just within reach (approx 180MPix/s overall, so 6MP30 would be possible, just don't add in a stats pass too).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

ricberw
Posts: 15
Joined: Mon Jul 06, 2015 10:16 pm

Re: still capture rate (still FPS)

Wed Jul 15, 2015 4:59 pm

Has MJPEG support been broken? I'm running 3.18.7+ (very old) and it seems that when setting pixelformat to 5 (or MJPG), it just hangs when trying to stream with v4l2.

Any ideas?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: still capture rate (still FPS)

Wed Jul 15, 2015 5:23 pm

ricberw wrote:Has MJPEG support been broken? I'm running 3.18.7+ (very old) and it seems that when setting pixelformat to 5 (or MJPG), it just hangs when trying to stream with v4l2.

Any ideas?
AFAIK MJPEG support is still working, though there has been a bug recently fixed affecting a couple of the 4.0.7/8 releases where V4L2 will crash and burn quite badly. Now all fixed.

What application/commands are you using?
There was a significant bug in several apps that had returned the buffer to V4L2 before they had consumed the data - IIRC mjpgstreamer was one app effected. The V4L2 framework changed somewhere between 3.12 and 3.18 to zero the bytesused field as soon as the buffer was returned, so the app then looked at the buffer and found it was empty. https://github.com/raspberrypi/firmware/issues/347 seems to have been the relevant thread for discussing that issue.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

ricberw
Posts: 15
Joined: Mon Jul 06, 2015 10:16 pm

Re: still capture rate (still FPS)

Wed Jul 15, 2015 5:28 pm

v4l2-ctl is it.

Commands after boot:

modprobe bcm2835-v4l2
v4l2-ctl -c auto_exposure=1
v4l2-ctl -c exposure_time_absolute=200
v4l2-ctl -v width=2592,height=1944,pixelformat=MJPG
v4l2-ctl -p 15
v4l2-ctl --stream-mmap=3 --stream-count=5 --stream-to=test.mjpg


Here's the --all output:

Driver Info (not using libv4l2):
Driver name : bm2835 mmal
Card type : mmal service 16.1
Bus info : platform:bcm2835-v4l2
Driver version: 3.18.11
Capabilities : 0x85200005
Video Capture
Video Overlay
Read/Write
Streaming
Device Capabilities
Device Caps : 0x05200005
Video Capture
Video Overlay
Read/Write
Streaming
Priority: 2
Video input : 0 (Camera 0: ok)
Format Video Capture:
Width/Height : 2592/1944
Pixel Format : 'MJPG'
Field : None
Bytes per Line: 2592
Size Image : 5059584
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Custom Info : feedcafe
Format Video Overlay:
Left/Top : 150/50
Width/Height: 1024/768
Field : None
Chroma Key : 0x00000000
Global Alpha: 0x00
Clip Count : 0
Clip Bitmap : No
Framebuffer Format:
Capability :
Flags : Overlay Matches Capture/Output Size
Width : 2592
Height : 1952
Pixel Format : 'YU12'
Bytes per Line: 3888
Size image : 7589376
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 15.000 (15000/1000)
Read buffers : 1

User Controls

brightness (int) : min=0 max=100 step=1 default=50 value =50 flags=slider
contrast (int) : min=-100 max=100 step=1 default=0 val ue=0 flags=slider
saturation (int) : min=-100 max=100 step=1 default=0 val ue=0 flags=slider
red_balance (int) : min=1 max=7999 step=1 default=1000 va lue=1000 flags=slider
blue_balance (int) : min=1 max=7999 step=1 default=1000 va lue=1000 flags=slider
horizontal_flip (bool) : default=0 value=0
vertical_flip (bool) : default=0 value=0
power_line_frequency (menu) : min=0 max=3 default=1 value=1
sharpness (int) : min=-100 max=100 step=1 default=0 val ue=0 flags=slider
color_effects (menu) : min=0 max=15 default=0 value=0
rotate (int) : min=0 max=360 step=90 default=0 value =0
color_effects_cbcr (int) : min=0 max=65535 step=1 default=32896 value=32896

Codec Controls

video_bitrate_mode (menu) : min=0 max=1 default=0 value=0 flags=u pdate
video_bitrate (int) : min=25000 max=25000000 step=25000 def ault=10000000 value=10000000
repeat_sequence_header (bool) : default=0 value=0
h264_i_frame_period (int) : min=0 max=2147483647 step=1 default=6 0 value=60
h264_level (menu) : min=0 max=11 default=11 value=11
h264_profile (menu) : min=0 max=4 default=4 value=4

Camera Controls

auto_exposure (menu) : min=0 max=3 default=0 value=1
exposure_time_absolute (int) : min=1 max=10000 step=1 default=1000 v alue=200
exposure_dynamic_framerate (bool) : default=0 value=0
auto_exposure_bias (intmenu): min=0 max=24 default=12 value=12
white_balance_auto_preset (menu) : min=0 max=9 default=1 value=1
image_stabilization (bool) : default=0 value=0
iso_sensitivity (intmenu): min=0 max=4 default=0 value=0
exposure_metering_mode (menu) : min=0 max=2 default=0 value=0
scene_mode (menu) : min=0 max=13 default=0 value=0

JPEG Compression Controls

compression_quality (int) : min=1 max=100 step=1 default=30 value =30

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: still capture rate (still FPS)

Wed Jul 15, 2015 5:41 pm

ricberw wrote:v4l2-ctl is it.

Commands after boot:

modprobe bcm2835-v4l2
v4l2-ctl -c auto_exposure=1
v4l2-ctl -c exposure_time_absolute=200
v4l2-ctl -v width=2592,height=1944,pixelformat=MJPG
v4l2-ctl -p 15
v4l2-ctl --stream-mmap=3 --stream-count=5 --stream-to=test.mjpg
Should work, although the internal buffer allocation may be slightly suboptimal. I haven't heard shouting from other places about it, and various apps use it, so it may just be something weird. I'll try to find 5 mins to give it a go.
Is there a reason you're stuck on an old release?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: still capture rate (still FPS)

Wed Jul 15, 2015 9:58 pm

6by9 wrote:
ricberw wrote:v4l2-ctl is it.

Commands after boot:

modprobe bcm2835-v4l2
v4l2-ctl -c auto_exposure=1
v4l2-ctl -c exposure_time_absolute=200
v4l2-ctl -v width=2592,height=1944,pixelformat=MJPG
v4l2-ctl -p 15
v4l2-ctl --stream-mmap=3 --stream-count=5 --stream-to=test.mjpg
Should work, although the internal buffer allocation may be slightly suboptimal. I haven't heard shouting from other places about it, and various apps use it, so it may just be something weird. I'll try to find 5 mins to give it a go.
Is there a reason you're stuck on an old release?
It is the buffering that is the issue. Load the driver with:

Code: Select all

sudo modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944
and I can stream MJPEG happily at 5MPix. Even without that I can stream MJPEG at 720P without issue.
The default mode is 1280x720, so it is only allocating 3 internal buffers for that. 5MPix is bigger than 3x720P, so it fails to allocate the needed buffers. Not elegant, but a restriction I couldn't think of a sensible way around when I wrote it.
I've tested against the absolute latest release having done an rpi-update. I doubt there will be any difference with the older release.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

ricberw
Posts: 15
Joined: Mon Jul 06, 2015 10:16 pm

Re: still capture rate (still FPS)

Wed Jul 15, 2015 10:24 pm

Awesome - will test this in a moment and will let you know the result.

EDIT: Works perfectly - should have noticed those parameters in one of the other threads and tried that first.

Thank you!

ricberw
Posts: 15
Joined: Mon Jul 06, 2015 10:16 pm

Re: still capture rate (still FPS)

Wed Jul 15, 2015 11:02 pm

Hmm... Probably the wrong thread for this, but now realizing that I have little to no control over the quality of the frames in the MJPG itself.

Any ideas? I played with video_bitrate_mode and compression_quality to no avail.

EDIT: Got some control by playing around with the driver itself. Looking forward to more playing around :) Thanks again!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: still capture rate (still FPS)

Thu Jul 16, 2015 6:59 am

ricberw wrote:Hmm... Probably the wrong thread for this, but now realizing that I have little to no control over the quality of the frames in the MJPG itself.

Any ideas? I played with video_bitrate_mode and compression_quality to no avail.

EDIT: Got some control by playing around with the driver itself. Looking forward to more playing around :) Thanks again!
video_bitrate_mode will do nothing for MJPEG (as you've found). compression_quality is only applicable when capturing pure JPEGs, not MJPEG.
video_bitrate should give you some control, although there have been a couple of longstanding reports that the MJPEG rate control isn't the best.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

racer993
Posts: 60
Joined: Mon Feb 18, 2013 7:27 pm

Re: still capture rate (still FPS)

Thu Jul 23, 2015 2:44 pm

6by9 wrote:
6by9 wrote:
ricberw wrote:v4l2-ctl is it.

Commands after boot:

modprobe bcm2835-v4l2
v4l2-ctl -c auto_exposure=1
v4l2-ctl -c exposure_time_absolute=200
v4l2-ctl -v width=2592,height=1944,pixelformat=MJPG
v4l2-ctl -p 15
v4l2-ctl --stream-mmap=3 --stream-count=5 --stream-to=test.mjpg
Should work, although the internal buffer allocation may be slightly suboptimal. I haven't heard shouting from other places about it, and various apps use it, so it may just be something weird. I'll try to find 5 mins to give it a go.
Is there a reason you're stuck on an old release?
It is the buffering that is the issue. Load the driver with:

Code: Select all

sudo modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944
and I can stream MJPEG happily at 5MPix. Even without that I can stream MJPEG at 720P without issue.
The default mode is 1280x720, so it is only allocating 3 internal buffers for that. 5MPix is bigger than 3x720P, so it fails to allocate the needed buffers. Not elegant, but a restriction I couldn't think of a sensible way around when I wrote it.
I've tested against the absolute latest release having done an rpi-update. I doubt there will be any difference with the older release.

This works for me :)

I was wondering whether it is possible to "arm" the camera by using the v4l2 driver and start taking pictures as soon as the driver receives a signal, thereby minimizing the lag between the signal and the moment that the first picture is taken. Somewhat similar to the -k (keypress) or -s (signal) function of raspistill.

I have read something about:

--wait-for-event=<event>
wait for an event [VIDIOC_DQEVENT]
<event> is the event number or one of:
eos, vsync, ctrl=<id>, frame_sync
where <id> is the name of the control
--poll-for-event=<event>
poll for an event [VIDIOC_DQEVENT]
see --wait-for-event for possible events

Does someone have an example?

Vertigo72
Posts: 23
Joined: Wed May 29, 2013 6:41 am

Re: still capture rate (still FPS)

Tue Sep 22, 2015 8:51 am

waveform80 wrote:raspistill shoots pictures in the "still mode" of the camera. In this mode, a *lot* of work goes into producing the image including mode switching to the highest resolution, an aggressive denoise algorithm, etc. You're unlikely to get beyond 1fps with this. Shooting video at 15fps (and actually a lot higher) is indeed possible. Here's a little gist I whipped up a while ago which fires up video recording with MJPEG output, then extracts each JPEG from the output as it goes:

https://gist.github.com/waveform80/263b9c8bdcb1e9b79749

On my Pi2 I can *easily* produce 15fps from this (until the disk cache runs out of space and the SD card's IO limitations kick in). Now, as to "full frame", do you just mean "full field of view" (which the above will accomplish happily by 2x2 binning of the input), or do you mean "full resolution" (which the above probably won't manage due to various limitations).
Would a Pi 2 be any help in still mode? Im flying a RPI (1A+) on an autonomous RC plane for aerial mapping, and I need around 1-1.5 FPS at the full 5MP. I can however compromise a bit on jpeg quality to keep the sd card from being a bottleneck. Right now Im falling just short of that 1-1.5 FPS, and missing frames in flight. I dont think I can use the mjpeg trick because the captures are triggered externally at exact moments. So Im considering a raspberry 2, but I have no idea if it will any difference?

On a side note; I really wish someone would make a better raspberry camera module. The current one is decent enough for the price and a lot of applications, but Im sure many like me could use a ~15MP camera with better optics. The step from a 3gr $25 module to a 100+gr $200+ point and shoot camera is a bit steep.

Return to “Camera board”