{"id":29828986,"url":"https://github.com/raspberrypi/py-videodev2","last_synced_at":"2025-07-29T08:15:00.890Z","repository":{"id":302611569,"uuid":"1013051139","full_name":"raspberrypi/py-videodev2","owner":"raspberrypi","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-22T08:10:29.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-22T13:52:05.533Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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,"zenodo":null}},"created_at":"2025-07-03T09:31:16.000Z","updated_at":"2025-07-22T08:10:33.000Z","dependencies_parsed_at":"2025-07-03T09:53:19.451Z","dependency_job_id":"092b99df-737d-43a3-895f-fa08e0ff4f80","html_url":"https://github.com/raspberrypi/py-videodev2","commit_stats":null,"previous_names":["raspberrypi/py-videodev2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raspberrypi/py-videodev2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fpy-videodev2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fpy-videodev2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fpy-videodev2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fpy-videodev2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raspberrypi","download_url":"https://codeload.github.com/raspberrypi/py-videodev2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspberrypi%2Fpy-videodev2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267652825,"owners_count":24122100,"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-07-29T02:00:12.549Z","response_time":2574,"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":"2025-07-29T08:14:59.890Z","updated_at":"2025-07-29T08:15:00.844Z","avatar_url":"https://github.com/raspberrypi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# py-videodev2\n\nA Python script that automatically converts Video4Linux2 (V4L2) C header files to Python ctypes bindings.\n\n## Overview\n\nThis tool parses the Linux `videodev2.h` header file and generates clean, Pythonic ctypes bindings for the V4L2 API. It handles complex C constructs like inline unions, enums, structs, and preprocessor definitions, producing ready-to-use Python code.\n\n## Requirements\n\n- Python 3.6+\n- `clang` preprocessor (for header preprocessing)\n- Linux kernel headers (for complete V4L2 definitions)\n\n## Usage\n\n### Basic Usage\n\n```bash\n./convert-videodev2.py /usr/include/linux/videodev2.h -o videodev2.py\n```\n\n### With Custom Defines\n\n```bash\n./convert-videodev2.py videodev2.h -D CUSTOM_DEFINE -D ANOTHER_DEFINE -o output.py\n```\n\n### With Custom Clang Binary\n\n```bash\n./convert-videodev2.py videodev2.h --bin /usr/bin/clang-15 -o output.py\n```\n\n### Command Line Options\n\n- `input_file`: Path to the videodev2.h header file\n- `-o, --output`: Output Python file (default: `videodev2.py`)\n- `-D, --define`: Add preprocessor defines (default: `__aarch64__`, `__KERNEL__`, `__arch64__`)\n- `--bin`: Path to clang binary (default: `clang`)\n\n**Note**: The script includes `__aarch64__`, `__KERNEL__`, and `__arch64__` as default defines to ensure compatibility with ARM64 systems and enable kernel-specific definitions.\n\n## Generated Code Structure\n\nThe generated Python module includes:\n\n### Enums with Global Constants\n```python\nclass v4l2_field(IntEnum):\n    V4L2_FIELD_ANY = 0\n    V4L2_FIELD_NONE = 1\n    V4L2_FIELD_TOP = 2\n\n# Global constants for compatibility\nV4L2_FIELD_ANY = v4l2_field.V4L2_FIELD_ANY\nV4L2_FIELD_NONE = v4l2_field.V4L2_FIELD_NONE\n```\n\n### Structures with Nested Unions\n```python\nclass v4l2_plane(Structure):\n    class _u(Union):\n        _fields_ = [\n            ('mem_offset', c_uint32),\n            ('userptr', c_ulong),\n            ('fd', c_int32)\n        ]\n    \n    _fields_ = [\n        ('bytesused', c_uint32),\n        ('length', c_uint32),\n        ('m', _u),\n        ('data_offset', c_uint32),\n        ('reserved', c_uint32 * 11)\n    ]\n```\n\n### IOCTL Definitions\n```python\nVIDIOC_QUERYCAP = _IOR('V', 0, v4l2_capability)\nVIDIOC_G_FMT = _IOWR('V', 4, v4l2_format)\n```\n\n### Helper Functions\n```python\ndef v4l2_fourcc(a, b, c, d):\n    \"\"\"Create a FOURCC value from four characters\"\"\"\n    return (ord(a) | (ord(b) \u003c\u003c 8) | (ord(c) \u003c\u003c 16) | (ord(d) \u003c\u003c 24))\n```\n\n## Example Usage of Generated Code\n\n```python\nimport videodev2 as v4l2\nimport fcntl\n\n# Open video device\nfd = open('/dev/video0', 'rb+', buffering=0)\n\n# Query capabilities\ncap = v4l2.v4l2_capability()\nfcntl.ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)\nprint(f\"Driver: {cap.driver.decode()}\")\nprint(f\"Card: {cap.card.decode()}\")\n\n# Set format\nfmt = v4l2.v4l2_format()\nfmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE\nfmt.fmt.pix.width = 640\nfmt.fmt.pix.height = 480\nfmt.fmt.pix.pixelformat = v4l2.v4l2_fourcc('Y', 'U', 'Y', 'V')\nfcntl.ioctl(fd, v4l2.VIDIOC_S_FMT, fmt)\n```\n\n\n## License\n\nThis project is licensed under the BSD 3-Clause License. See the script header for full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspberrypi%2Fpy-videodev2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraspberrypi%2Fpy-videodev2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspberrypi%2Fpy-videodev2/lists"}