{"id":15020497,"url":"https://github.com/raspberrypi/raspiraw","last_synced_at":"2025-10-13T04:32:01.261Z","repository":{"id":38086031,"uuid":"113844649","full_name":"raspberrypi/raspiraw","owner":"raspberrypi","description":"Example app directly receiving raw data from CSI2 sensors","archived":false,"fork":false,"pushed_at":"2024-04-15T10:26:13.000Z","size":3039,"stargazers_count":266,"open_issues_count":15,"forks_count":88,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-25T23:02:49.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raspberrypi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-11T10:22:55.000Z","updated_at":"2025-05-25T11:24:52.000Z","dependencies_parsed_at":"2024-12-15T18:02:15.509Z","dependency_job_id":null,"html_url":"https://github.com/raspberrypi/raspiraw","commit_stats":{"total_commits":95,"total_committers":9,"mean_commits":"10.555555555555555","dds":0.5157894736842106,"last_synced_commit":"b770dd2b3302d6ba33996e0451aefc0eb20b97e9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raspberrypi/raspiraw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fraspiraw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fraspiraw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fraspiraw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fraspiraw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raspberrypi","download_url":"https://codeload.github.com/raspberrypi/raspiraw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fraspiraw/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013689,"owners_count":26085390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:55:10.038Z","updated_at":"2025-10-13T04:32:01.245Z","avatar_url":"https://github.com/raspberrypi.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# This repo is deprecated, and only kept for reference.\n\nRaspiraw: An example app that receives data directly from CSI sensors\non the Raspberry Pi.\n\nThe register sets for OV5647 and IMX219 are often under NDA, which means\nthat support can not be offered over their contents without breaking\nthose NDAs. Anything added here by RPF/RPT has to be demonstrable as\nalready being in the public domain, or from 3rd parties having\nreverse engineered how the firmware is working (eg by listening to the\nI2C communications).\n\n\nThe raw Bayer format frames captured by **raspiraw** can be converted to .ppm images by modified **dcraw** image processing app: [https://github.com/6by9/dcraw](https://github.com/6by9/dcraw)\n\nSupported sensors:\n\n\tadv7282m\n\timx219\n\tov5647\n\n## raspiraw command line options\n\nTable of contents:\n\n\t$ raspiraw\n\n\traspiraw Camera App 0.0.1\n\n\t-?, --help\t: This help information\n\t-md, --mode\t: Set sensor mode \u003cmode\u003e\n\t-hf, --hflip\t: Set horizontal flip\n\t-vf, --vflip\t: Set vertical flip\n\t-e, --ss\t: Set the sensor exposure time (not calibrated units)\n\t-g, --gain\t: Set the sensor gain code (not calibrated units)\n\t-o, --output\t: Set the output filename\n\t-hd, --header\t: Write the BRCM header to the output file\n\t-t, --timeout\t: Time (in ms) before shutting down (if not specified, set to 5s)\n\t-sr, --saverate\t: Save every Nth frame\n\t-b, --bitdepth\t: Set output raw bit depth (8, 10, 12 or 16, if not specified, set to sensor native)\n\t-c, --cameranum\t: Set camera number to use (0=CAM0, 1=CAM1).\n\t-eus, --expus\t: Set the sensor exposure time in micro seconds.\n\t-y, --i2c\t: Set the I2C bus to use.\n\t-r, --regs\t: Change (current mode) regs\n\t-hi, --hinc\t: Set horizontal odd/even inc reg\n\t-vi, --vinc\t: Set vertical odd/even inc reg\n\t-f, --fps\t: Set framerate regs\n\t-w, --width\t: Set current mode width\n\t-h, --height\t: Set current mode height\n\t-tp, --top\t: Set current mode top\n\t-hd0, --header0\t: Sets filename to write the BRCM header to\n\t-ts, --tstamps\t: Sets filename to write timestamps to\n\t-emp, --empty\t: Write empty output files\n\t$\n\n## base options\n\n...\n\n\t-md, --mode\t: Set sensor mode \u003cmode\u003e\n\nRange is 1-7.\n\n...\n\n\t-o, --output\t: Set the output filename\n\nFor recording more than one frame specify \"C printf integer format strings\" as part of the filename.\nExample: ... -o /dev/shm/out.%04d.raw ...\n\n\t-hd, --header\t: Write the BRCM header to the output file\n\nIf selected, this prepeneds each stored frame with a 32KB header (needed for **dcraw** being able to process the raw frame). An alternative (needed for high framerate capturing) is option -hd0 (see below section), which allows **dcraw** to process the captured frames later as well.\n\n...\n\n\t-sr, --saverate\t: Save every Nth frame\n\nPer default this is 20, allowing to capture frames to slow SD cards. In high framerate section, storing on (fast) ramdisk allows to use \"-sr 1\" (store all frames).\n\n...\n\n\t-y, --i2c\t: Set the I2C bus to use.\n\nRange is 0-2.\n\n\n## high frame rate options\n\nLookup ov5647, imx219 or adv7282m data sheets for register details.\n\n#### I2C register setting options\n\n\t-r, --regs\t: Change (current mode) regs\n\nAllows to change sensor regs in selected sensor mode. Format is a semicolon separated string of assignments.\nAn assignment consists of a 4 hex digits register address, followed by a comma and one or more 2 hex digit byte values.\nRestriction: Only registers present in selected sensor mode can be modified. Example argument: \"380A,003C;3802,78;3806,05FB\".\nIn case more than one byte appears after the comma, the byte values get written to next addresses.\n\n\t-hi, --hinc\t: Set horizontal odd/even inc reg\n\nSets the horizontal odd and even increment numbers. Argument is a 2 hex digits byte. \"-hi xy\" is convenience shortcut for \"3814,xy\" in --regs for ov5647 sensor. Lookup the sensor mode registers for your sensor header file for default values. TODO: Needs to be extended to deal with the other sensors as well.\n\n\t-vi, --vinc\t: Set vertical odd/even inc reg\n\nSets the vertical odd and even increment numbers. Argument is a 2 hex digits byte. \"-vi xy\" is convenience shortcut for \"3815,xy\" in --regs for ov5647 sensor. TODO: Needs to be extended to deal with the other sensors as well.\n\n\t-f, --fps\t: Set frame rate regs\n\nSets the requested frame rate; argument is a floating point number. All sensors but adv7282m sensor are supported.\n\n#### Sensor mode setting options\n\nThe following options allow to overwrite some sensor mode settings for current sensor mode.\n\n\t-w, --width\t: Set current mode width\n\nSets the width value of current mode.\n\n\t-h, --height\t: Set current mode height\n\nSets the height value of current mode, and sensor mode regs.\n\n\t-tp, --top\t: Set current mode top\n\nSets top line in case --vinc setting jumps two or more lines. The tools *_B* modes make use of it to capture bottom half of fov.\n\n\n#### File output settings\n\n\t-hd0, --header0\t: Write the BRCM header to output file\n\nFor high frame rate modes writing BRCM header to each file is a bottleneck.\nSo this option is a replacement for \"--header\"/\"-hd\" option.\nInstead of writing header to each frame file, it is written to specified output file only.\nFor decoding ith frame with **dcraw** later, you need to concatenate specified output file and frame i and store somewhere, then **dcraw** that file.\n\n\t-ts, --tstamps\t: Write timestamps to output file\n\nWith this option timestamps for the captured frames get written to specified output file.\nThis happens after video has been captured, so does not negatively affect capture frame rate.\nFormat: \"delta,index,timestamp\\n\"\n\nTimestamp distribution analysis can be easily done this way:\n\n\t$ cut -f1 -d, tstamps.csv | sort -n | uniq -c\n\t      1\n\t     13 1499\n\t     17 1500\n\t     31 1501\n\t    147 1502\n\t    376 1503\n\t     22 1504\n\t     33 1505\n\t     14 1506\n\t      3 1507\n\t      1 3005\n\t      2 3006\n\t$\n\n\nThis shows that frame deltas are 1503\u0026micro;s \u0026plusmn; 4\u0026micro;s, which corresponds to 1,000,000/1503=665.3fps.\nThree frame skips happened during recording, and their indices can be easily determined by:\n\n\t$ grep \"^3\" tstamps.csv\n\t3006,2,6027843627\n\t3005,85,6027969857\n\t3006,554,6028676146\n\t$\n\nSo we know that frames 0085-0553 have no frame skips. All tools do this timestamp analysis for you.\n\n\n\t-emp, --empty\t: Write empty output files\n\nThis option allows to determine the maximal frame rate **raspiraw** callback will be triggered. Only empty files will be written for the frames, but the filenames allow to count how many. This would be an example use:\n\n\traspiraw -md 7 -t 3000 -emp {some options from this section} -sr 1 -o /dev/shm/out.%04d.raw 2\u003e/dev/null\n\nUsing **/dev/shm** ramdisk for storage is essential for high frame rates. You precede this command by \"rm /dev/shm/out.\u0026ast;.raw\" and do \"ls -l /dev/shm/out.\u0026ast;.raw | wc --lines\" afterwards to determine the number of frames written (\"-sr 1\" means saverate 1 or writing all frames received from camera). \"--empty\" option allows to determine upper bounds for the absolute maximal frame rate achievable for a given set of high frame rate options.\n\n\n\n#### Examples:\n\nThis is an example making use of most high frame rate command line options:\n\n\t$ rm /dev/shm/out.*.raw\n\t$ raspiraw -md 7 -t 1000 -ts tstamps.csv -hd0 hd0.32k -h 64 --vinc 1F --fps 660 -r \"380A,0040;3802,78;3806,0603\" -sr 1 -o /dev/shm/out.%04d.raw 2\u003e/dev/null\n\tUsing i2C device /dev/i2c-0\n\t$ ls -l /dev/shm/out.*.raw | wc --lines\n\t660\n\t$\n\nThis command captures video from ov5647 camera on CSI-2 interface:\n* based on 640x480 mode (-md 7)\n* captures for 1s (-t 1000)\n* stores \u0026micro;s timestamps in file tstamps.csv (-ts)\n* stores BCRM header needed for **dcraw** only once in file hd0.32k  (-hd0)\n* sets frame capture height to 64 (-h 64)\n* increases line skipping to 1 and 15 instead of 3 and 5. Results in doubling vertical covered area (--vinc 1F, sum 8 vs 16). 1F shows colors (see below), 3D result is pale\n* asks for 660 fps (--fps 660)\n* sets some ov5647 registers (380A,0040;3802,78;3806,0603)\n* sets saverate to 1 (save all frames)\n* outputs in \"/dev/shm\" ramdisk files starting with \"out.0001.raw\"\n* redirects standard error output (lots of mmal messages) to /dev/null (2\u003e/dev/null)\n\nFor being able to convert frame 123 captured frame with **dcraw** these steps are necessary (because of -hd0):\n\n\tcat hd0.32k /dev/shm/out.0123.raw \u003e out.0123.raw\n\tdcraw out.0123.raw\n\nSince line scanning speed was doubled, the captured 128x64 frames need to be stretched by factor 2.\nYou can use this small C code and know exactly what happens, or any other stretching program (gimp, netpbm tools, ...), the result is still a .ppm format file:\n[double.c](tools/double.c)\n\n\tdouble out.0123.ppm \u003e out.0123.ppm.d\n\nThis frame was captured with 665fps. It is surprisingly colorful despite only 1.5ms shutter time:\n![600fps sample frame just described](res/out.0123.ppm.d.png)\n\n\nCurrently the capturing tools do not use --regs option anymore. This option keeps available trying out things quickly.\n\n\n#### Creation of .ogg video from **dcraw** processed and stretched .ppm frames\n\nFirst you need to convert the .ppm frames you are interested in into .png format, eg. with netpbm tools:\n\n\tpnmtopng out.0123.ppm.d \u003e out.0123.ppm.d.png\n\nThis gstreamer pipeline creates .ogg video. You can choose frame rate the video should play with (eg. 1fps for very slow motion), and start index of the frames to be taken.\n\n\tgst-launch-1.0 multifilesrc location=\"out.%04d.ppm.d.png\" index=300 caps=\"image/png,framerate=\\(fraction\\)1/1\" ! pngdec ! videorate ! videoconvert ! videorate ! theoraenc ! oggmux ! filesink location=\"$1.ogg\"\n\nThis is now part of raw2ogg2anim tool.\n\n#### Creation of animated .gif from .ogg video\n\nYou can create high quality animated .gif from .ogg video with ffmpeg based [gifenc.sh](tools/gifenc.sh). You only need to adjust **fps** and **scale** in **filters** variable of that script to match what you want.\n\n\tgifenc.sh $1.ogg $1.anim.gif\n\nSample: 360fps 640x120 (rescaled to 640x240) video taken with v1 camera, played 25x slowed down:\n![360fps sample video](res/out.360fps.25xSlower.2.anim.gif)\n\nThis is now part of raw2ogg2anim tool.\n\n## raspiraw usage\n\n#### do once\n\nYou have to clone the repo.\nThen change directory `cd raspiraw` and build the code by running `make`.  Optionally you can define the compiler with `CC=gcc make` or `CC=clang make`.\nFinally add this line to your `~/.bashrc`.\n\n\t$ tail -1 ~/.bashrc \n\tPATH=~/raspiraw:~/raspiraw/tools:$PATH\n\t$\n\n#### do once after reboot or use of raspistill/raspivid\n\nExecute camera_i2c to make raspiraw work.\n\n\t$ camera_i2c \n\tsetting GPIO for board revsion: a01041\n\tA+, B+, and B2 all revisions - I2C 0 on GPIOs 28 \u0026 29. GPIOs 32 \u0026 41 for LED and power\n\t$\n\n\n#### tools usage\n\nThere are quite soome tools in [tools directory](tools/).\nThey allow to do a video capture with frame delay and frame skip analysis with\njust a single command.\nAnd to repeat the command if you do not like the analysis.\n\nThere are several tools for capturing. [640x128_s](tools/640x128_s) creates 640x128\nframes while only capturing 64 lines. Stretching is needed in post processing.\n[640x128](tools/640x128) captures 640x128 frames as well, but all 128 lines. There\nis a minor difference in viewing the frames, and a bigger difference in capturing\nframerate that can be achieved. Stretched 640x128 frames can be captured at 665(502)\nfps on Pi 2B/3B(Pi Zero[W]), whereas full capturing of 128 lines allows for 350fps\n(only).\n\nThis table gives modes and framerates possible with raspiraw.\n\n|format        | Pi Zero [W] |   Pi 2B/3B |\n|:-------------|------------:|-----------:|\n|640x480       |         90  |         90 |\n|640x480_s     |        180  |        180 |\n|640x240[_B]   |        180  |        180 |\n|640x240[_B]_s |        360  |        360 |\n|640x128  / _s |  350 / 502  |  350 / 665 |\n|640x64   / _s |  502 / 543  |  665 / 750 |\n|640x32        |  543        |  750       |\n|640x416_s     |        210  |        210 |\n|640x400_s     |        220  |        220 |\n|2592x1944_s   |         30  |         30 |\n|1296x730_s    |         98  |         98 |\n|1296x720_S    |        190  |        190 |\n|framerate for normal / stretched | _B is \"bottom half\" | _S is \"4th rows\"\n\nSample:\n\n\t$ 640x128_s 1200\n\tremoving /dev/shm/out.*.raw\n\tcapturing frames for 1200ms with 659fps requested\n\t794 frames were captured at 665fps\n\tframe delta time[us] distribution\n\t      1 \n\t    168 1502\n\t    623 1503\n\t      2 3006\n\tafter skip frame indices (middle column)\n\t3006,2,9698007408\n\t3006,275,9698419172\n\t$\n\n[raw2ogg2anim ](tools/raw2ogg2anim) is script allowing you to create an .ogg video\nand an animated .gif.\nSpecify output file prefix for .ogg video and .anim.gif animated gif created. Then\nspecify frame start and stop index as well, and the target framerate. Optionally\nyou can add \"d\"/\"dd\" argument for stretching each frame by factor of 2/4 vertically\nbefore generation of output. \"d\"/\"dd\" option is used by \"_s\"/\"_S\" mode tools.\n\n\t$ ~/raspiraw/tools/raw2ogg2anim\n\tformat: raw2ogg2anim vname first last fps [d[d]]\n\t$ \n\n## Where is the limit?\n\nAbove sample did capture 640x128 frames (stretched) at 665fps. It is possible to\ncapture 640x64 stretched frames with 900fps!\n[https://www.raspberrypi.org/forums/viewtopic.php?f=63\u0026t=109523\u0026p=1246776#p1246776](https://www.raspberrypi.org/forums/viewtopic.php?f=63\u0026t=109523\u0026p=1246776#p1246776)\n\n![900fps sample frame just described](res/out.3000.ppm.d.png)\n\nSharp and well lighted video can be taken with NoIR camera with lense and 3W\ninfrared LED. This is 640x128 frame from video taken at 665fps:\n\n![665fps NoIR camera with lense sample frame](res/out.1000.ppm.d.png)\n\nThis is 1296x720_S format frame taken at 190fps, only every 4th row gets captured\n(allowing for high framerate while keeping fov), and post processing has to call\n\"double\" tool two times for each frame:\n![1296x720_S mode sample frame](res/Screenshot179.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspberrypi%2Fraspiraw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraspberrypi%2Fraspiraw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspberrypi%2Fraspiraw/lists"}