Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Apr 11, 2024
1 parent 0dc9dcc commit d0d0c0e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 77 deletions.
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,18 @@
[简体中文](https://github.com/SWHL/RapidVideOCR/blob/main/docs/README_zh.md) | English
</div>

<details>
<summary>Contents</summary>

- [Introduction](#introduction)
- [Demo](#demo)
- [Overall framework](#overall-framework)
- [Installation](#installation)
- [Usage](#usage)
- [Documentation](#documentation)
- [Code Contributors](#code-contributors)
- [Contributing](#contributing)
- [Sponsor](#sponsor)
- [License](#license)

</details>

### Introduction
- Video hard subtitle extraction, automatically generate the corresponding `srt | txt` file.
- Supported subtitle languages: Chinese | English (For other supported languages, see: [List of supported languages](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/multi_languages.md#%E8%AF%AD%E7%A7%8D%E7%BC%A9%E5%86%99))
- The advantages are as follows:
- **Faster extraction**: Used in conjunction with [VideoSubFinder](https://sourceforge.net/projects/videosubfinder/) software to extract key subtitle frames faster.
- **More accurate recognition**: Use [RapidOCR](https://github.com/RapidAI/RapidOCR) as the recognition library.
- **More convenient to use**: pip can be installed directly and used.

- For desktop EXE version, please go to [RapidVideOCRDesktop](https://github.com/SWHL/RapidVideOCRDesktop).
- If it helps you, please give a star ⭐.

### [Demo](https://huggingface.co/spaces/SWHL/RapidVideOCR)
### [Online Demo](https://huggingface.co/spaces/SWHL/RapidVideOCR)
<div align="center">
<img src="https://github.com/SWHL/RapidVideOCR/releases/download/v2.0.1/OnlineDemo.gif" alt="Demo" width="100%" height="100%">
</div>
Expand All @@ -54,15 +40,16 @@ flowchart LR
```

### Installation
> [!WARNING]
>
> The input image path of `rapid_videocr` must be the path output by the **VideoSubFinder** software (RGBImages/TXTImages).
```bash
pip install rapid_videocr
```

### Usage

> [!NOTE]
>
> The input image path of `rapid_videocr` must be the path of **RGBImages** or **TXTImages** output by **VideoSubFinder** software.
```bash
rapid_videocr -i RGBImages
```
Expand Down
32 changes: 8 additions & 24 deletions docs/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,18 @@
</div>


<details>
<summary>目录</summary>

- [简介](#简介)
- [Demo](#demo)
- [整体框架](#整体框架)
- [安装](#安装)
- [使用](#使用)
- [文档](#文档)
- [贡献者](#贡献者)
- [贡献指南](#贡献指南)
- [加入我们](#加入我们)
- [赞助](#赞助)
- [开源许可证](#开源许可证)

</details>

### 简介
- 视频硬字幕提取,自动生成对应`srt | txt`文件。
- 支持字幕语言:中文 | 英文 (其他可以支持的语言参见:[支持语种列表](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/multi_languages.md#%E8%AF%AD%E7%A7%8D%E7%BC%A9%E5%86%99))
- 优势如下:
- **提取更快**:与[VideoSubFinder](https://sourceforge.net/projects/videosubfinder/)软件结合使用,提取关键字幕帧更快。
- **识别更准**:采用[RapidOCR](https://github.com/RapidAI/RapidOCR)作为识别库。
- **使用更方便**:pip直接安装即可使用。

- 桌面EXE版,请移步[RapidVideOCRDesktop](https://github.com/SWHL/RapidVideOCRDesktop)
- 如果有帮助到您的话,请给个小星星⭐。

### [Demo](https://www.modelscope.cn/studios/liekkas/RapidVideOCR/summary)
### [在线Demo](https://www.modelscope.cn/studios/liekkas/RapidVideOCR/summary)
<div align="center">
<img src="https://github.com/SWHL/RapidVideOCR/releases/download/v2.0.1/OnlineDemo.gif" alt="Demo" width="100%" height="100%">
</div>
Expand All @@ -56,17 +41,16 @@ flowchart LR
```

### 安装

> [!WARNING]
>
> `rapid_videocr`的输入图像路径必须是**VideoSubFinder**软件输出的路径(RGBImages / TXTImages)。

```bash
pip install rapid_videocr
```

### 使用

> [!NOTE]
>
> `rapid_videocr`输入图像路径必须是**VideoSubFinder**软件输出的RGBImages或TXTImages的路径。
```bash
rapid_videocr -i RGBImages
```
Expand Down
36 changes: 12 additions & 24 deletions rapid_videocr/logger.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: [email protected]
import functools
import sys
from pathlib import Path
import logging

from loguru import logger

def get_logger():
logger = logging.getLogger()
logger.setLevel(logging.INFO)

@functools.lru_cache()
def get_logger(save_dir: str = "."):
loguru_format = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
)
fmt = "%(asctime)s - %(levelname)s: %(message)s"
format_str = logging.Formatter(fmt)

logger.remove()
logger.add(
sys.stderr,
format=loguru_format,
level="INFO",
enqueue=True,
)

file_name = "{time:YYYY-MM-DD-HH-mm-ss}.log"
save_file = Path(save_dir) / file_name
logger.add(save_file, rotation=None, retention="2 days")
# 注意这里,想要写到不同log文件中,这里会存在写到同一个log文件中问题
if not logger.handlers:
sh = logging.StreamHandler()
logger.addHandler(sh)
sh.setFormatter(format_str)
return logger


log_dir = Path(__file__).resolve().parent / "log"
logger = get_logger(str(log_dir))
logger = get_logger()
8 changes: 4 additions & 4 deletions rapid_videocr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __call__(self, video_path: str, output_dir: str = "outputs"):
video_num = len(video_list)
for i, one_video in enumerate(video_list):
logger.info(
f"[{i+1}/{video_num}] Starting to extract {one_video} key frame",
"[%s/%s] Starting to extract %s key frame", i + 1, video_num, one_video
)

save_name = Path(one_video).stem
Expand All @@ -100,14 +100,14 @@ def __call__(self, video_path: str, output_dir: str = "outputs"):
try:
self.vsf(str(one_video), str(save_vsf_dir))
except Exception as e:
logger.error(f"Extract {one_video} error, {e}, skip")
logger.error("Extract %s error, %s, skip", one_video, e)
continue

logger.info(f"[{i+1}/{video_num}] Starting to run {one_video} ocr")
logger.info("[%s/%s] Starting to run %s ocr", i + 1, video_num, one_video)

rgb_dir = Path(save_vsf_dir) / "RGBImages"
if not list(rgb_dir.iterdir()):
logger.warning(f"Extracting frames from {one_video} is 0, skip")
logger.warning("Extracting frames from %s is 0, skip", one_video)
continue
self.video_ocr(rgb_dir, save_dir, save_name=save_name)

Expand Down
4 changes: 2 additions & 2 deletions rapid_videocr/rapid_videocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def export_file(
self.save_file(srt_path, srt_result)
else:
raise ValueError(f"The {self.out_format} dost not support.")
logger.info(f"[OCR] The result has been saved to {save_dir} directory.")
logger.info("[OCR] The result has been saved to %s directory.", save_dir)

def print_console(self, txt_result: List) -> None:
for v in txt_result:
Expand All @@ -309,7 +309,7 @@ def save_file(save_path: Union[str, Path], content: List, mode: str = "w") -> No
with open(save_path, mode, encoding="utf-8") as f:
for value in content:
f.write(f"{value}\n")
logger.info(f"[OCR] The file has been saved in the {save_path}")
logger.info("[OCR] The file has been saved in the %s", save_path)

@staticmethod
def _compute_centroid(points: np.ndarray) -> List:
Expand Down
2 changes: 0 additions & 2 deletions rapid_videocr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import shapely
from shapely.geometry import MultiPoint, Polygon

logger_initialized = {}


class RecMode(Enum):
SINGLE = "single"
Expand Down

0 comments on commit d0d0c0e

Please sign in to comment.