metalmajor
Posts: 36
Joined: Fri Oct 20, 2017 9:40 pm

FPS influence possible by writing to sd-card?

Mon Dec 02, 2019 6:43 pm

Hello,

I have an application in C++, and I record 640x480 jpg images to an SD-card on the PI3B+. This works, but sometimes I get some frame skips. The pts timestamps shows a diff of 1800 ms sometimes, so there is a gap there. Now when I record to a tmpfs instead of an sd-card, then I never have those gaps. Is there some sort of correlation between the camera bandwidth and SD-card writes? How could I detect where the framedrop happens, and why?

Best regards,
Tom,

User avatar
topguy
Posts: 5935
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: FPS influence possible by writing to sd-card?

Mon Dec 02, 2019 7:05 pm

I think the ext4 file system flush its cached data about every 5 seconds and writing to sd-flash is a bit slow, so while this is happening creating/writing new files might be blocking. In a RAM disk write time is not an issue.

metalmajor
Posts: 36
Joined: Fri Oct 20, 2017 9:40 pm

Re: FPS influence possible by writing to sd-card?

Mon Dec 02, 2019 7:43 pm

Hello,

Maybe I should have mentioned that I already do the writes in a separate thread.

I just did a test where I only capture the camera in my program, and in a separate shell i run a dd /dev/urandom to a file on my sdcard, and after a few seconds i start to see the frameskips in my program.

So I want to know if this is some known behaviour that sdcard bandwidth and the camera bandwidth are somehow shared?

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

Re: FPS influence possible by writing to sd-card?

Mon Dec 02, 2019 9:29 pm

metalmajor wrote:
Mon Dec 02, 2019 7:43 pm
Hello,

Maybe I should have mentioned that I already do the writes in a separate thread.

I just did a test where I only capture the camera in my program, and in a separate shell i run a dd /dev/urandom to a file on my sdcard, and after a few seconds i start to see the frameskips in my program.

So I want to know if this is some known behaviour that sdcard bandwidth and the camera bandwidth are somehow shared?
Not shared, but they do affect each other. The camera can work fine is you dump the data to NUL, but as soon as you start writing to the SD card, that can affect the rest of the system. So if the system has to go off and write a load of data to the card, that can affect processing elsewhere. There could be locks going on inside the kernel that are held a bit longer whilst the write is happening for example, that could affect something else. Not easy to find out what though, but there is no direct link between the CSI bus and the SD card bus.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

User avatar
HermannSW
Posts: 1649
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: FPS influence possible by writing to sd-card?

Tue Dec 03, 2019 12:06 am

metalmajor wrote:
Mon Dec 02, 2019 6:43 pm
I have an application in C++, and I record 640x480 jpg images to an SD-card on the PI3B+. This works, but sometimes I get some frame skips. The pts timestamps shows a diff of 1800 ms sometimes, so there is a gap there.
1800ms frame skip is 900ms between frames, is roughly 1 frame per second only.
If you alternatively would record a [email protected] video, even the Pi Zero would have no problem to store the resulting [GPU] compressed .h264 video to SD card.
And you can extract the frames easily into JPEG frames with this command in post-processing:

Code: Select all

ffmpeg -i tst.h264 frame.%06d.jpg
You can verify that no frameskips happen that way by using raspivid's "-pts" option that writes timestamps while recording:

Code: Select all

raspivid -md 7 -w 640 -h 480 -p 22,50,640,480 -pts tst.pts -o tst.h264
You can analyze the generated timestamp file using this tool:
https://github.com/Hermann-SW/userland/ ... ptsanalyze

Code: Select all

./ptsanalyze tst.pts 0
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”