{"id":16765096,"url":"https://github.com/dataplayer12/video-writer","last_synced_at":"2025-04-10T18:22:16.648Z","repository":{"id":111555396,"uuid":"425135252","full_name":"dataplayer12/video-writer","owner":"dataplayer12","description":"Super fast video writer for opencv using ffmpeg and libav","archived":false,"fork":false,"pushed_at":"2021-11-06T13:45:45.000Z","size":12,"stargazers_count":22,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T16:02:39.417Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dataplayer12.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-11-06T02:15:39.000Z","updated_at":"2024-04-11T09:27:17.000Z","dependencies_parsed_at":"2023-05-29T10:09:09.947Z","dependency_job_id":null,"html_url":"https://github.com/dataplayer12/video-writer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataplayer12%2Fvideo-writer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataplayer12%2Fvideo-writer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataplayer12%2Fvideo-writer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataplayer12%2Fvideo-writer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dataplayer12","download_url":"https://codeload.github.com/dataplayer12/video-writer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248270547,"owners_count":21075794,"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","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-10-13T05:28:20.534Z","updated_at":"2025-04-10T18:22:16.641Z","avatar_url":"https://github.com/dataplayer12.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# video-writer\nSuper fast video writer for opencv using ffmpeg and libav\n(C++ and python)\n\n## The Problem\n\nOpencv's `cv::VideoWriter` is a pain to use. \n- It hides the critical choice of encoders behind an obscure fourcc code and it isn't always transparent which codecs are available for use on the system. This is because opencv depends on a number of [backends](https://docs.opencv.org/3.4.15/d0/da7/videoio_overview.html) like ffmpeg and VFW. If you are someone who codes a lot on multiple systems (linux/mac/win/x86/arm) and embedded boards, this can quickly become frustrating.\n- Even setting aside the issue of codecs, `cv::VideoWriter` doesn't let you set important parameters like bitrate and pixel format.\n\nWouldn't it be nice if there were a lightweight and transparent API for writing videos using hardware acceleration on python and C++?\n\n## The easy solution\n\nUnsurprisingly, many other people have noticed the issue and the [most upvoted solution](https://stackoverflow.com/questions/38686359/opencv-videowriter-control-bitrate) on stackoverflow recommends (at least for python) opening a subprocess with ffmpeg and passing frames as JPEGs. Now there are better formats to pass frames into ffmpeg than JPEG and you would be better off really adapting this pipeline for your own usecase, but the bigger problem is that due to the limitations of python multiprocessing, the shells created this way are not freed as long as the parent python program is running (effin' GIL). This lead of all kinds of ugliness. For example, if you are making many videos from one python script, videos which have finished writing will not be viewable in vlc/ffplay/etc until all the videos have finished processing and the parent python script has exited.\n\n## Why this project?\nIn spite of its limitations, the easy solution works and 99% of users don't need anything else, but if video processing is an essential part of your workflow, you might find it worthwhile to invest in a more satisfying solution. This is where this project comes in. We use LibAV, the backend behind ffmpeg to build a simple video writer object which can be used in C++ an python.\n\n## Status\nThis is a **work in progress**. Please do not use it in anything critical and feel free to contribute by sending PRs.\n\n## Build\nCurrently verified on macOS.\n\n```Shell\n#Install dependencies\nbrew install ffmpeg pkg-config cmake\n\n#Clone repo\ngit clone https://github.com/dataplayer12/video-writer.git\ncd video-writer\nmkdir build\ncd build\n\n#Configure and build project\ncmake ../\nmake\n```\n\n`make` will generate a minimum C++ sample and a shared library which can be used in a python script with ctypes module.\n\n## How to use and To-Dos\n\nThe goal is to create a `VideoWriter` class which can be instantiated like\n```Cpp\n//C++\nVideoWriter writer(\"filename.mp4\", fps, width, height, encoder_name, bitrate);\nwriter.write(cvFrame); //cvFrame is a cv::Mat object\n```\n\n```Python\n#python\nimport video_writer as vw\nimport numpy as np\n\nwriter= vw.VideoWriter(filename, fps, width, height, encoder_name, bitrate)\nx=np.ones((height, width, 3), dtype=np.uint8)\nwriter.write(x)\n```\nCurrently the `write` method accepts pointers and is not ready for use in python.\n\n- Make write method functional.\n- Add support for writing cvMat as frame.\n- Add support for python.\n- Make C++ and python examples\n\n## Credits\nIn making this project, I have learnt a lot from the excellent work of [Bartholomew Joyce](https://github.com/bartjoyce), his [videos](https://www.youtube.com/watch?v=MEMzo59CPr8) and [git repo](https://github.com/bartjoyce/video-app). It helped me set up the environment and get a feel for the functions of libav. The difference between his repo and this is that I want to encode rather than decode.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdataplayer12%2Fvideo-writer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdataplayer12%2Fvideo-writer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdataplayer12%2Fvideo-writer/lists"}