ocrvid


Nameocrvid JSON
Version 0.5.3 PyPI version JSON
download
home_page
SummaryCLI tool for OCR-ing video frames on macOS
upload_time2024-02-21 14:50:53
maintainer
docs_urlNone
authorkj-9
requires_python>=3.8
licenseApache-2.0
keywords ocr macos video movie cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ocrvid

[![PyPI](https://img.shields.io/pypi/v/ocrvid.svg)](https://pypi.org/project/ocrvid/)
[![Changelog](https://img.shields.io/github/v/release/kj-9/ocrvid?include_prereleases&label=changelog)](https://github.com/kj-9/ocrvid/releases)
[![Tests](https://github.com/kj-9/ocrvid/workflows/CI/badge.svg)](https://github.com/kj-9/ocrvid/actions?query=workflow%3ACI)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/kj-9/ocrvid/blob/master/LICENSE)


CLI tool to extract text from videos using OCR on macOS.


> [!NOTE]
> Currently, this tool only tested and works on macOS 13 or later.


> [!CAUTION]
> This tool is still in early development stage. Current v0.x releases are not stable and may have breaking changes.

## Installation

Install this tool using `pip`:

    pip install ocrvid


## Usage

<!-- [[[cog
import cog
from ocrvid import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["--help"])
help = result.output.replace("Usage: cli", "Usage: ocrvid")
cog.out(
    f"```\n{help}\n```"
)
]]] -->
```
Usage: ocrvid [OPTIONS] COMMAND [ARGS]...

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  detect  Run OCR on a single picture, and print the results as json
  langs   Show supported recognition languages
  props   Show properties of video file
  run     Run OCR on a video, and save result as a json file

```
<!-- [[[end]]] -->

### Run OCR on a video

Use `ocr run` sub command to run ocr on a video file:

<!-- [[[cog
runner = CliRunner()
result = runner.invoke(cli.cli, ["run", "--help"])
help = result.output.replace("Usage: cli", "Usage: ocrvid")
cog.out(
    f"```\n{help}\n```"
)
]]] -->
```
Usage: ocrvid run [OPTIONS] INPUT_VIDEO

  Run OCR on a video, and save result as a json file

Options:
  -o, --output FILE            Path to output json file. By default, if you run
                               `ocrvid run some/video.mp4` then the output file
                               will be `./video.json`
  -fd, --frames-dir DIRECTORY  If passed, then save video frames to this
                               directory. By default, frames are not saved.
  -fs, --frame-step INTEGER    Number of frames to skip between each frame to be
                               processed. By default, 100 which means every 100
                               frames, 1 frame will be processed.
  -bs, --by-second FLOAT       If passed, then process 1 frame every N seconds.
                               This option relies on fps metadata of the video.
  -l, --langs TEXT             Prefered languages to detect, ordered by
                               priority. See avalable languages run by `ocrvid
                               langs`. If not passed, language is auto detected.
  --help                       Show this message and exit.

```
<!-- [[[end]]] -->

For example, run against the test video file at `tests/video/pexels-eva-elijas.mp4` in this repo:

```
ocrvid run tests/video/pexels-eva-elijas.mp4
```

Then `pexels-eva-elija.json` is generated in the current directory which looks like this:

```json
{
    "video_file":"tests/video/pexels-eva-elijas.mp4",
    "frames":[
        {
            "frame_index":0,
            "results":[
                {
                    "text":"INSPIRING WORDS",
                    "confidence":1.0,
                    "bbox":[
                        0.17844826551211515,
                        0.7961793736859821,
                        0.3419540405273438,
                        0.10085802570754931
                    ]
                },
                {
                    "text":"\"Foar kills more dre",
                    "confidence":1.0,
                    "bbox":[
                        0.0724226723609706,
                        0.6839455987759758,
                        0.4780927975972494,
                        0.14592710683043575
                    ]
                },
                {
                    "text":"than failure ever",
                    "confidence":1.0,
                    "bbox":[
                        0.018455287246445035,
                        0.6549868414269003,
                        0.45329265594482426,
                        0.14363905857426462
                    ]
                },
                {
                    "text":"IZY KASSEM",
                    "confidence":0.5,
                    "bbox":[
                        -0.015967150208537523,
                        0.6675747977206025,
                        0.23065692583719888,
                        0.08114868486431293
                    ]
                },
                {
                    "text":"Entrepreneur",
                    "confidence":1.0,
                    "bbox":[
                        0.01941176222542875,
                        0.1353812367971159,
                        0.9058370590209961,
                        0.26137274083956863
                    ]
                }
            ]
        },
...
```


### Show supported languages

You can run `ocrvid langs` to show supported languages to detect.
Results may change depending on running macos version.

On macOS version:
<!-- [[[cog
import platform
cog.out(
    f"""```\n{platform.mac_ver()[0]=}\n```""")
]]] -->
```
platform.mac_ver()[0]='14.2.1'
```
<!-- [[[end]]] -->


Result of `ocrvid langs`:
<!-- [[[cog
runner = CliRunner()
result = runner.invoke(cli.cli, ["langs"])
help = result.output.replace("Usage: cli", "Usage: ocrvid")
cog.out(
    f"```\n{help}\n```"
)
]]] -->
```
en-US
fr-FR
it-IT
de-DE
es-ES
pt-BR
zh-Hans
zh-Hant
yue-Hans
yue-Hant
ko-KR
ja-JP
ru-RU
uk-UA
th-TH
vi-VT

```
<!-- [[[end]]] -->

## How can I run OCR on YouTube videos?

Take a look at [yt-dlp](https://github.com/yt-dlp/yt-dlp).


## Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

    cd ocrvid
    python -m venv venv
    source venv/bin/activate

Now install the dependencies and test dependencies:

    pip install -e '.[test]'

To run the tests:

    make test

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ocrvid",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "ocr,macos,video,movie,cli",
    "author": "kj-9",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/76/2a/1c6aa1e56e110d7d7aa0c120d13f63019cee124b0556224158e538ed43b6/ocrvid-0.5.3.tar.gz",
    "platform": null,
    "description": "# ocrvid\n\n[![PyPI](https://img.shields.io/pypi/v/ocrvid.svg)](https://pypi.org/project/ocrvid/)\n[![Changelog](https://img.shields.io/github/v/release/kj-9/ocrvid?include_prereleases&label=changelog)](https://github.com/kj-9/ocrvid/releases)\n[![Tests](https://github.com/kj-9/ocrvid/workflows/CI/badge.svg)](https://github.com/kj-9/ocrvid/actions?query=workflow%3ACI)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/kj-9/ocrvid/blob/master/LICENSE)\n\n\nCLI tool to extract text from videos using OCR on macOS.\n\n\n> [!NOTE]\n> Currently, this tool only tested and works on macOS 13 or later.\n\n\n> [!CAUTION]\n> This tool is still in early development stage. Current v0.x releases are not stable and may have breaking changes.\n\n## Installation\n\nInstall this tool using `pip`:\n\n    pip install ocrvid\n\n\n## Usage\n\n<!-- [[[cog\nimport cog\nfrom ocrvid import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: ocrvid\")\ncog.out(\n    f\"```\\n{help}\\n```\"\n)\n]]] -->\n```\nUsage: ocrvid [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --version  Show the version and exit.\n  --help     Show this message and exit.\n\nCommands:\n  detect  Run OCR on a single picture, and print the results as json\n  langs   Show supported recognition languages\n  props   Show properties of video file\n  run     Run OCR on a video, and save result as a json file\n\n```\n<!-- [[[end]]] -->\n\n### Run OCR on a video\n\nUse `ocr run` sub command to run ocr on a video file:\n\n<!-- [[[cog\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"run\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: ocrvid\")\ncog.out(\n    f\"```\\n{help}\\n```\"\n)\n]]] -->\n```\nUsage: ocrvid run [OPTIONS] INPUT_VIDEO\n\n  Run OCR on a video, and save result as a json file\n\nOptions:\n  -o, --output FILE            Path to output json file. By default, if you run\n                               `ocrvid run some/video.mp4` then the output file\n                               will be `./video.json`\n  -fd, --frames-dir DIRECTORY  If passed, then save video frames to this\n                               directory. By default, frames are not saved.\n  -fs, --frame-step INTEGER    Number of frames to skip between each frame to be\n                               processed. By default, 100 which means every 100\n                               frames, 1 frame will be processed.\n  -bs, --by-second FLOAT       If passed, then process 1 frame every N seconds.\n                               This option relies on fps metadata of the video.\n  -l, --langs TEXT             Prefered languages to detect, ordered by\n                               priority. See avalable languages run by `ocrvid\n                               langs`. If not passed, language is auto detected.\n  --help                       Show this message and exit.\n\n```\n<!-- [[[end]]] -->\n\nFor example, run against the test video file at `tests/video/pexels-eva-elijas.mp4` in this repo:\n\n```\nocrvid run tests/video/pexels-eva-elijas.mp4\n```\n\nThen `pexels-eva-elija.json` is generated in the current directory which looks like this:\n\n```json\n{\n    \"video_file\":\"tests/video/pexels-eva-elijas.mp4\",\n    \"frames\":[\n        {\n            \"frame_index\":0,\n            \"results\":[\n                {\n                    \"text\":\"INSPIRING WORDS\",\n                    \"confidence\":1.0,\n                    \"bbox\":[\n                        0.17844826551211515,\n                        0.7961793736859821,\n                        0.3419540405273438,\n                        0.10085802570754931\n                    ]\n                },\n                {\n                    \"text\":\"\\\"Foar kills more dre\",\n                    \"confidence\":1.0,\n                    \"bbox\":[\n                        0.0724226723609706,\n                        0.6839455987759758,\n                        0.4780927975972494,\n                        0.14592710683043575\n                    ]\n                },\n                {\n                    \"text\":\"than failure ever\",\n                    \"confidence\":1.0,\n                    \"bbox\":[\n                        0.018455287246445035,\n                        0.6549868414269003,\n                        0.45329265594482426,\n                        0.14363905857426462\n                    ]\n                },\n                {\n                    \"text\":\"IZY KASSEM\",\n                    \"confidence\":0.5,\n                    \"bbox\":[\n                        -0.015967150208537523,\n                        0.6675747977206025,\n                        0.23065692583719888,\n                        0.08114868486431293\n                    ]\n                },\n                {\n                    \"text\":\"Entrepreneur\",\n                    \"confidence\":1.0,\n                    \"bbox\":[\n                        0.01941176222542875,\n                        0.1353812367971159,\n                        0.9058370590209961,\n                        0.26137274083956863\n                    ]\n                }\n            ]\n        },\n...\n```\n\n\n### Show supported languages\n\nYou can run `ocrvid langs` to show supported languages to detect.\nResults may change depending on running macos version.\n\nOn macOS version:\n<!-- [[[cog\nimport platform\ncog.out(\n    f\"\"\"```\\n{platform.mac_ver()[0]=}\\n```\"\"\")\n]]] -->\n```\nplatform.mac_ver()[0]='14.2.1'\n```\n<!-- [[[end]]] -->\n\n\nResult of `ocrvid langs`:\n<!-- [[[cog\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"langs\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: ocrvid\")\ncog.out(\n    f\"```\\n{help}\\n```\"\n)\n]]] -->\n```\nen-US\nfr-FR\nit-IT\nde-DE\nes-ES\npt-BR\nzh-Hans\nzh-Hant\nyue-Hans\nyue-Hant\nko-KR\nja-JP\nru-RU\nuk-UA\nth-TH\nvi-VT\n\n```\n<!-- [[[end]]] -->\n\n## How can I run OCR on YouTube videos?\n\nTake a look at [yt-dlp](https://github.com/yt-dlp/yt-dlp).\n\n\n## Development\n\nTo contribute to this tool, first checkout the code. Then create a new virtual environment:\n\n    cd ocrvid\n    python -m venv venv\n    source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    make test\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "CLI tool for OCR-ing video frames on macOS",
    "version": "0.5.3",
    "project_urls": {
        "CI": "https://github.com/kj-9/ocrvid/actions",
        "Changelog": "https://github.com/kj-9/ocrvid/releases",
        "Homepage": "https://github.com/kj-9/ocrvid",
        "Issues": "https://github.com/kj-9/ocrvid/issues"
    },
    "split_keywords": [
        "ocr",
        "macos",
        "video",
        "movie",
        "cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b76f8521404c0c54ec4e05e673b6a020d25ae2bc4c9a425e01aece7fc534cd11",
                "md5": "b08008238661db37939a8ac33f4d59b8",
                "sha256": "4a4d2475547a796934f2416fc59678b86331eeff81dbfd52495880f9693c9cd7"
            },
            "downloads": -1,
            "filename": "ocrvid-0.5.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b08008238661db37939a8ac33f4d59b8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13929,
            "upload_time": "2024-02-21T14:50:51",
            "upload_time_iso_8601": "2024-02-21T14:50:51.856279Z",
            "url": "https://files.pythonhosted.org/packages/b7/6f/8521404c0c54ec4e05e673b6a020d25ae2bc4c9a425e01aece7fc534cd11/ocrvid-0.5.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "762a1c6aa1e56e110d7d7aa0c120d13f63019cee124b0556224158e538ed43b6",
                "md5": "d127bcf57229df42332367f93d531712",
                "sha256": "9ad428d034df18a62e68ce7d85cfeb5ab573f0bc1636c0db48fc5dad17a49b9f"
            },
            "downloads": -1,
            "filename": "ocrvid-0.5.3.tar.gz",
            "has_sig": false,
            "md5_digest": "d127bcf57229df42332367f93d531712",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15260,
            "upload_time": "2024-02-21T14:50:53",
            "upload_time_iso_8601": "2024-02-21T14:50:53.414370Z",
            "url": "https://files.pythonhosted.org/packages/76/2a/1c6aa1e56e110d7d7aa0c120d13f63019cee124b0556224158e538ed43b6/ocrvid-0.5.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-21 14:50:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kj-9",
    "github_project": "ocrvid",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ocrvid"
}
        
Elapsed time: 0.27206s