Gstreamer Filesink Output File Size

Hi everyone,

I’ve seen something interesting about Gstreaemer and wanted some clarity. I’m saving a camera stream to file. The camera used BGRx (32 bits per pixel) and has a resolution of 1456x1088 pixels. In theory, each frame should be 50.692096 Megabits. At 50FPS, a 30 second video should weight ~9.5 Gigabytes. However when running the pipeline below, the output file is only 1.5GB!

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=BGRx! filesink location=test

Curiously however, if I use v4l2-ctl, I get a value size equal to the theoretical file size

v4l2-ctl -d /dev/video0 --set-fmt-video=width=1456,height=1088,pixelformat=BGRx --set-ctrl bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test

In the above, the “test” frame is 50.692096 Megabits, which is as expected. My questions would be, why/how is Gstreamer compressing the files, and what sort of information am I loosing (e.g. am I loosing colour information?)

The gstreamer equivalent would be:

gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! video/x-raw, width=1456, height=1088, format=BGRx ! filesink location=test.BGRx

Depending on how you stop the pipeline, you may have to add -e to gst-launch:

gst-launch-1.0 -e v4l2src device=/dev/video0 ! video/x-raw, width=1456, height=1088, format=BGRx ! filesink location=test.BGRx

Be aware this may fill your filesystem very quickly. Better save to external storage.

Hi @Honey_Patouceul

Thanks for your input. This does indeed work. However, after 300+ frames, my FPS drops from 50 to 5FPS.

I’m also curious, so when not using “num-buffers” and getting a smaller file size. What information do I lose? do I lose Frames? Colour information? Or does gstreamer perform some sort of lossless compression?

1456x1088@50fps is almost 80MPixels/s and with BGRx format you would have to save 316MB/s. Do you have a NVME SSD ? Maybe your SD Card cannot write so much, so the first frames are buffered, but since it writes slower than frames arrive it gets stuck.
Or you may try a compression that would decrease the size of data, but of course there would be some loss of information. You would have to try and tune for your needs.