raspi-shaun
Posts: 5
Joined: Mon Sep 15, 2014 12:52 am

Can't change frame rate

Mon Sep 15, 2014 5:18 pm

Hi everyone,

I'm using raspivid to capture video with the Raspberry Pi Camera Board. I can change the image height and width just fine, but no matter what value I specify for the frame rate, the captured stream is always 25fps.

[email protected] ~ $ raspivid -t 10000 -w 640 -h 480 -fps 10 -o test640x480x10.h264
[email protected] ~ $ MP4Box -add test640x480x10.h264 test640x480x10.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 91 samples - Slices: 2 I 89 P 0 B - 0 SEI - 2 IDR
Saving to test640x480x10.mp4: 0.500 secs Interleaving
[email protected] ~ $

Thoughts?

ethanol100
Posts: 619
Joined: Wed Oct 02, 2013 12:28 pm

Re: Can't change frame rate

Mon Sep 15, 2014 5:32 pm

The raw h264 stream has no information on its frame rate. MP4Box assumes a default of 25 fps if not specified. You need to specify the correct one with i.e.

Code: Select all

MP4Box -add video.h264 -fps 10 video.mp4
Your example shows that you try to capture 10s with 10 fps. That should create ~100 frames. You get 91, because of the startup time. raspivid creates the right framerate.

raspi-shaun
Posts: 5
Joined: Mon Sep 15, 2014 12:52 am

Re: Can't change frame rate

Mon Sep 15, 2014 10:45 pm

Thanks ethanol100 - that makes sense. Following your reasoning I next created a series of 10-second videos ranging from 5fps to 90fps in 5fps steps:

[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 5 -o test640x480x5.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 10 -o test640x480x10.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 15 -o test640x480x15.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 20 -o test640x480x20.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 25 -o test640x480x25.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 30 -o test640x480x30.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 35 -o test640x480x35.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 40 -o test640x480x40.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 45 -o test640x480x45.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 50 -o test640x480x50.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 55 -o test640x480x55.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 60 -o test640x480x60.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 65 -o test640x480x65.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 70 -o test640x480x70.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 75 -o test640x480x75.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 80 -o test640x480x80.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 85 -o test640x480x85.h264
[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 90 -o test640x480x90.h264

Based on the results from my initial test at 10fps, it seems there was roughly 0.9 seconds of setup time followed by 9.1 seconds of video resulting in 91 captured frames. I assume the setup time would be fairly constant across frame rates so the number of frames would scale linearly as the framerate increased. As you can see below, the numbers worked out pretty well up to 25fps (9.1 sec @ 25fps = 228 frames and I captured 229). After that, it all fell apart! At 30fps I only captured 183 frames (why did it go down?) and by 90fps I captured only 329 frames.

Does this mean the camera module can only handle frame rates up to 25 fps? My understanding is that other people are getting 90fps at this resolution. Thoughts?

[email protected] ~/camera $ MP4Box -add test640x480x5.h264 test640x480x5.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 45 samples - Slices: 1 I 44 P 0 B - 0 SEI - 1 IDR
Saving to test640x480x5.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x10.h264 test640x480x10.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 91 samples - Slices: 2 I 89 P 0 B - 0 SEI - 2 IDR
Saving to test640x480x10.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x15.h264 test640x480x15.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 137 samples - Slices: 3 I 134 P 0 B - 0 SEI - 3 IDR
Saving to test640x480x15.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x20.h264 test640x480x20.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 183 samples - Slices: 4 I 179 P 0 B - 0 SEI - 4 IDR
Saving to test640x480x20.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x25.h264 test640x480x25.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 229 samples - Slices: 4 I 225 P 0 B - 0 SEI - 4 IDR
Saving to test640x480x25.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x30.h264 test640x480x30.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 183 samples - Slices: 4 I 179 P 0 B - 0 SEI - 4 IDR
Saving to test640x480x30.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x35.h264 test640x480x35.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 213 samples - Slices: 4 I 209 P 0 B - 0 SEI - 4 IDR
Saving to test640x480x35.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x40.h264 test640x480x40.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 244 samples - Slices: 5 I 239 P 0 B - 0 SEI - 5 IDR
Saving to test640x480x40.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x45.h264 test640x480x45.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 274 samples - Slices: 5 I 269 P 0 B - 0 SEI - 5 IDR
Saving to test640x480x45.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x50.h264 test640x480x50.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 304 samples - Slices: 6 I 298 P 0 B - 0 SEI - 6 IDR
Saving to test640x480x50.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x55.h264 test640x480x55.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 333 samples - Slices: 6 I 327 P 0 B - 0 SEI - 6 IDR
Saving to test640x480x55.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x60.h264 test640x480x60.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 273 samples - Slices: 5 I 268 P 0 B - 0 SEI - 5 IDR
Saving to test640x480x60.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x65.h264 test640x480x65.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 297 samples - Slices: 5 I 292 P 0 B - 0 SEI - 5 IDR
Saving to test640x480x65.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x70.h264 test640x480x70.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 320 samples - Slices: 6 I 314 P 0 B - 0 SEI - 6 IDR
Saving to test640x480x70.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x75.h264 test640x480x75.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 343 samples - Slices: 6 I 337 P 0 B - 0 SEI - 6 IDR
Saving to test640x480x75.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x80.h264 test640x480x80.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 365 samples - Slices: 7 I 358 P 0 B - 0 SEI - 7 IDR
Saving to test640x480x80.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x85.h264 test640x480x85.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 370 samples - Slices: 7 I 363 P 0 B - 0 SEI - 7 IDR
Saving to test640x480x85.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x90.h264 test640x480x90.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 329 samples - Slices: 6 I 323 P 0 B - 0 SEI - 6 IDR
Saving to test640x480x90.mp4: 0.500 secs Interleaving

[email protected] ~/camera $ MP4Box -add test640x480x90.h264 test640x480x90.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 329 samples - Slices: 6 I 323 P 0 B - 0 SEI - 6 IDR
Saving test640x480x90.mp4: 0.500 secs Interleaving

ethanol100
Posts: 619
Joined: Wed Oct 02, 2013 12:28 pm

Re: Can't change frame rate

Tue Sep 16, 2014 9:54 am

Hmm, I get ~820 frames if I use your command to capture 640x480 at 90fps, which is again reasonable. Do you have a slow SD card? Can you test a recording of one video in the directory /run/shm? This is a temporary file system which lives only in RAM and if you get the requested framerate, I would assume that your SD card is too slow. You could then try to lower the bitrate(-b switch) and to increase the interval of I-frames(-g switch).

raspi-shaun
Posts: 5
Joined: Mon Sep 15, 2014 12:52 am

Re: Can't change frame rate

Wed Sep 17, 2014 4:32 am

It's a SanDisk 32G card. I used the following commands to test read/write speed:

[email protected] ~/camera $ sudo hdparm -t /dev/root

/dev/root:
Timing buffered disk reads: 54 MB in 3.02 seconds = 17.90 MB/sec

[email protected] ~/camera $ dd count=50k bs=1k if=/dev/zero of=/home/pi/test.img
51200+0 records in
51200+0 records out
52428800 bytes (52 MB) copied, 8.89446 s, 5.9 MB/s

I believe the card speed looks good. Next, I switched to /run/shm to try your suggestion:

[email protected] ~/camera $ cd /run/shm
[email protected] /run/shm $ raspivid -t 10000 -w 640 -h 480 -fps 90 -o test640x480x90.h264
[email protected] /run/shm $ MP4Box -add test640x480x90.h264 test640x480x90.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 329 samples - Slices: 6 I 323 P 0 B - 0 SEI - 6 IDR
Saving to test640x480x90.mp4: 0.500 secs Interleaving

[email protected] /run/shm $ df -h .
Filesystem Size Used Avail Use% Mounted on
tmpfs 75M 12M 64M 16% /run/shm

No sign of improvement.

ethanol100
Posts: 619
Joined: Wed Oct 02, 2013 12:28 pm

Re: Can't change frame rate

Wed Sep 17, 2014 8:06 am

Are you using an old firmware version?

You could try to update your system with:

Code: Select all

apt-get update
apt-get upgrade
rpi-update

lagurus
Posts: 48
Joined: Wed Aug 07, 2013 8:02 am

Re: Can't change frame rate

Wed Sep 17, 2014 1:22 pm

If you use last firmware, try to use older, e.g. firmware from Aug 12, 2014

Code: Select all

rpi-update  3d99bfb69460105c91e688a6031971e641bff354
and check again the results.

raspi-shaun
Posts: 5
Joined: Mon Sep 15, 2014 12:52 am

Re: Can't change frame rate

Wed Sep 17, 2014 6:24 pm

I'm in disbelief! I know for a FACT that I ran rpi-update multiple times before:

[email protected] ~ $ history | grep rpi-update
661 which rpi-update
662 man rpi-update
761 sudo rpi-update
841 sudo rpi-update
1207 sudo rpi-update <--- this time it solved my problem!
1208 man rpi-update
1209 rpi-update --help
1210 sudo rpi-update --help
1211 sudo man rpi-update
1250 history | grep rpi-update

but I tried it again per your suggestions and this time... it SOLVED my problem!!!

[email protected] ~/camera $ raspivid -t 10000 -w 640 -h 480 -fps 90 -o test640x480x90.h264
[email protected] ~/camera $ MP4Box -add test640x480x90.h264 test640x480x90.mp4
AVC-H264 import - frame size 640 x 480 at 25.000 FPS
AVC Import results: 894 samples - Slices: 15 I 879 P 0 B - 0 SEI - 15 IDR
Saving to test640x480x90.mp4: 0.500 secs Interleaving

I'm blown away! Thank you so much for your support!

On a side note: I've ordered another SD card so I can reinstall from scratch and dig deeper into the question of why it didn't work after the first rpi-update. If I find the answer, I'll tack onto this post for posterity.

Another side note: Looking at the git repository (https://github.com/Hexxeh/rpi-firmware/commits/master) I notice there was a commit yesterday titled "Add missing files from last update" lol. Not sure if he's referring to the Sept 10 update or the one earlier that same day. If the former, then perhaps that explains it. :-)

Thanks again guys!

Return to “Camera board”