{ "info": { "author": "Yi Ge", "author_email": "me@yige.ch", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# videocr\n\nExtract hardcoded (burned-in) subtitles from videos using the [Tesseract](https://github.com/tesseract-ocr/tesseract) OCR engine with Python.\n\nInput a video with hardcoded subtitles:\n\n

\n \"screenshot\"\n \"screenshot\"\n

\n\n```python\n# print_sub.py\n\nimport videocr\n\nif __name__ == '__main__':\n print(videocr.get_subtitles('video.mp4', lang='chi_sim+eng',\n sim_threshold=70, conf_threshold=65))\n```\n\n`$ python3 print_sub.py`\n\nOutput:\n\n``` \n0\n00:00:01,042 --> 00:00:02,877\n\u559d \u70b9 \u4ec0\u4e48 ? \nWhat can I get you?\n\n1\n00:00:03,044 --> 00:00:05,463\n\u6211 \u4e0d \u77e5\u9053\nUm, I'm not sure.\n\n2\n00:00:08,091 --> 00:00:10,635\n\u4f11\u95f2 \u65f6 \u5149 \u2026\nFor relaxing times, make it...\n\n3\n00:00:10,677 --> 00:00:12,595\n\u4e09 \u5f97 \u5229 \u65f6 \u5149\nBartender, Bob Suntory time.\n\n4\n00:00:14,472 --> 00:00:17,142\n\u6211 \u8981 \u4e00 \u676f \u4f0f\u7279 \u52a0\nUn, I'll have a vodka tonic.\n\n5\n00:00:18,059 --> 00:00:19,019\n\u8c22\u8c22\nLaughs Thanks.\n```\n\n## Performance\n\nThe OCR process is CPU intensive. It takes 3 minutes on my dual-core laptop to extract a 20 seconds video. More CPU cores will make it faster.\n\n## Installation\n\n1. Install [Tesseract](https://github.com/tesseract-ocr/tesseract/wiki) and make sure it is in your `$PATH`\n\n2. `$ pip install videocr`\n\n## Functions\n\n```python\nget_subtitles(\n video_path: str, lang='eng', time_start='0:00', time_end='',\n conf_threshold=65, sim_threshold=90, use_fullframe=False)\n```\nReturn the subtitles string in SRT format.\n\n\n```python\n\nsave_subtitles_to_file(\n video_path: str, file_path='subtitle.srt', lang='eng', time_start='0:00', time_end='',\n conf_threshold=65, sim_threshold=90, use_fullframe=False)\n```\nWrite subtitles to `file_path`. If the file does not exist, it will be created automatically.\n\n### Parameters\n\n- `lang`\n\n The language of the subtitles. You can extract subtitles in almost any language. All language codes on [this page](https://github.com/tesseract-ocr/tesseract/wiki/Data-Files#data-files-for-version-400-november-29-2016) (e.g. `'eng'` for English) and all script names in [this repository](https://github.com/tesseract-ocr/tessdata_fast/tree/master/script) (e.g. `'HanS'` for simplified Chinese) are supported.\n \n Note that you can use more than one language, e.g. `lang='hin+eng'` for Hindi and English together. \n \n Language files will be automatically downloaded to your `~/tessdata`. You can read more about Tesseract language data files on their [wiki page](https://github.com/tesseract-ocr/tesseract/wiki/Data-Files).\n\n- `conf_threshold`\n\n Confidence threshold for word predictions. Words with lower confidence than this value will be discarded. The default value `65` is fine for most cases. \n\n Make it closer to 0 if you get too few words in each line, or make it closer to 100 if there are too many excess words in each line.\n\n- `sim_threshold`\n\n Similarity threshold for subtitle lines. Subtitle lines with larger [Levenshtein](https://en.wikipedia.org/wiki/Levenshtein_distance) ratios than this threshold will be merged together. The default value `90` is fine for most cases.\n\n Make it closer to 0 if you get too many duplicated subtitle lines, or make it closer to 100 if you get too few subtitle lines.\n\n- `time_start` and `time_end`\n\n Extract subtitles from only a clip of the video. The subtitle timestamps are still calculated according to the full video length.\n\n- `use_fullframe`\n\n By default, only the bottom half of each frame is used for OCR. You can explicitly use the full frame if your subtitles are not within the bottom half of each frame.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/apm1467/videocr/archive/v0.1.5.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/apm1467/videocr", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "videocr", "package_url": "https://pypi.org/project/videocr/", "platform": "", "project_url": "https://pypi.org/project/videocr/", "project_urls": { "Download": "https://github.com/apm1467/videocr/archive/v0.1.5.tar.gz", "Homepage": "https://github.com/apm1467/videocr" }, "release_url": "https://pypi.org/project/videocr/0.1.5/", "requires_dist": null, "requires_python": "", "summary": "Extract hardcoded subtitles from videos using machine learning", "version": "0.1.5" }, "last_serial": 5286478, "releases": { "0.1.4": [ { "comment_text": "", "digests": { "md5": "0472f0cf6ac2577669fb7e4684fd6cd2", "sha256": "5faeed7faf2c40bb17b70baba15b3ca3eae0aed163bc3ea931041403e32265d9" }, "downloads": -1, "filename": "videocr-0.1.4.tar.gz", "has_sig": false, "md5_digest": "0472f0cf6ac2577669fb7e4684fd6cd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6247, "upload_time": "2019-04-29T23:18:35", "url": "https://files.pythonhosted.org/packages/7f/f9/8ba9872f41423b66fa86aadb2bd45ce559c9e1d8908f3d4be1d13354c6d6/videocr-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "c0b7f0da1c83cbdecacf164ae1ec4506", "sha256": "4d9d4559e2e5ff504a62d31cf3cebb64e136f116145cd6a7131073672a31ff3e" }, "downloads": -1, "filename": "videocr-0.1.5.tar.gz", "has_sig": false, "md5_digest": "c0b7f0da1c83cbdecacf164ae1ec4506", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6240, "upload_time": "2019-05-18T19:41:31", "url": "https://files.pythonhosted.org/packages/11/a4/b16cae7c37e3d29b18daf27f82919dce549dc22a4a48692e5eed36419fb6/videocr-0.1.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c0b7f0da1c83cbdecacf164ae1ec4506", "sha256": "4d9d4559e2e5ff504a62d31cf3cebb64e136f116145cd6a7131073672a31ff3e" }, "downloads": -1, "filename": "videocr-0.1.5.tar.gz", "has_sig": false, "md5_digest": "c0b7f0da1c83cbdecacf164ae1ec4506", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6240, "upload_time": "2019-05-18T19:41:31", "url": "https://files.pythonhosted.org/packages/11/a4/b16cae7c37e3d29b18daf27f82919dce549dc22a4a48692e5eed36419fb6/videocr-0.1.5.tar.gz" } ] }