mwlinder wrote:I understand what you are saying about the high data rate, but the bottom line is that it works just fine! The GPU doesn't seem to have any issue with 1080p 60fps, encoding it just fine.
I suspect the GPU is dropping frames and you're just not noticing it.
Assuming you're using raspivid or similar
(a) you'll need to select H264 level 4.2 to allow 1080P60 ("-lev 4.2"). The default level 4.0 only allows up to 245760 macroblocks/s, or 1920x1080@30.1fps.
(b) use the "-pts <filename>" option to save the timestamps of the frames. Those are usec accurate timestamps from when the CSI2 receiver generates the frame start interrupt. Those should all be nice and uniform, but I suspect that they aren't.
It may take a little while for the system to get far enough behind to actually drop buffers. Memory says that by default there are 4 image buffers allocated on the output side of the ISP (input side has 3). The codec needs to hold on to one for use as the reference frame, and get the new one in. It has an input FIFO that will happily swallow as many buffers as are going. Once all the buffers are inside the codec or in the FIFO, the ISP side will eventually get to a stage where it has no output buffer to process an input buffer into before a new input buffer comes along. One of those two input buffers will be dropped, and you'll see a glitch in the time stamps.
The regression tests that we used to run at Broadcom ran the camera, ISP, and codec at 1080P33 as that was judged to be within expectations of working reliably. There wasn't a huge amount of headroom above that, mainly due to the codec block.
mwlinder wrote:You are absolutely right that the "sensor mode" needs to match the incoming data. We have been using Mode 6 for 480p, Mode 5 for 720p, and Mode 1 for 1080p. If there is a mismatch between what the PiCapture is sending and what the Raspberry Pi is expecting you will either get buffer garbage for part of the picture or sometimes an MMAL error. Since Mode 5 is a few pixels larger than 720p in each dimension we add the extra to the right and bottom of the frame (which can be removed by selecting the ROI)
The one problem with 60fps data is that encoded H.264 video will play back in slow motion because the computer thinks it is at 30fps. There are two solutions to this that we are using: MP4Box will put an MP4 "wrapper" on the video that specifies the correct 60fps frame rate (this is what was done with the linked examples), or we can drop half the frames and record at 30fps.
The -pts option is really what you want again.
Code: Select all
raspivid -pts timecodes.txt -o video.h264
mkvmerge -o video.mkv --timecodes 0:timecodes.txt video.h264
should produce a correct file based on the timestamps gathered from the SoC.
You will probably find that the bitrate control has gone a bit crazy in the codec - you told it to expect 30 frames per second and have given it ~60, so all the predictions it has made for how many bits to allocate to a frame will be out by a factor of 2.
Purely from memory, I'd hope that the following command should capture a stream accurately described as 1080P60 from your board:
Code: Select all
raspivid -o stream.h264 -pts timestamps.txt -md 1 -w 1920 -h 1080 -fps 60 -b 20000000 -t 30000
I'm guessing you need to add at least "-awb=off -awbg 1.0,1.0" to stop it messing with the colour balance. I'd be interested to see the raw output files from that.
mwlinder wrote:This entire project has been a bit of an adventure because so much of what happens in the SOC GPU is a "black box", but the GPU is very capable and the implementation is tolerant of the differences between what it expects from the camera module and what PiCapture is sending. The ARM processor is able to deal with it just fine as well, with very low latency, because the GPU does the heavy lifting.
I'm working on getting the CSI2 receiver exposed via V4L2 to make it slightly less of a black box, but time is a scarce commodity at the moment

Things will be changing next year.
It's already done via MMAL, but not in a state that can be supported long term. The ISP is now also exposed as a generic resize/format conversion for YUV and RGB input formats to YUV and RGB output formats. That opens up a fair few possibilities for these capture devices, but needs the software effort to support the various input devices. I'm hoping to shift that effort on to the existing kernel drivers for things such as the TC358743, ADV7282, etc (basically anything with a CSI2 output).
The ARM will cope with a suitable bitrate H264 stream. It will struggle to do anything useful if given 60 YUV420 images at 1920x1080 every second. That's why I'm querying what can be achieved when given a 1080P60 source.
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.