all repos — videocr @ 6025e09a878365e03be6cac30fcba9583b5fc8e9

Extract hardcoded subtitles from videos using machine learning

update README
Yi Ge me@yige.ch
Fri, 17 May 2019 17:46:43 +0200
commit

6025e09a878365e03be6cac30fcba9583b5fc8e9

parent

da8cd05f08a92180317a123ae6b9e45ce6428de8

1 files changed, 14 insertions(+), 13 deletions(-)

jump to
M README.mdREADME.md

@@ -15,7 +15,8 @@

import videocr if __name__ == '__main__': - print(videocr.get_subtitles('video.avi', lang='chi_sim+eng', sim_threshold=70)) + print(videocr.get_subtitles('video.mp4', lang='chi_sim+eng', + sim_threshold=70, conf_threshold=65)) ``` `$ python3 print_sub.py`

@@ -56,7 +57,7 @@ ```

## Performance -The OCR process runs in parallel and is CPU intensive. It takes 3 minutes on my dual-core laptop to extract a 20 seconds video. You may want more cores for longer videos. +The 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. ## Installation

@@ -64,7 +65,7 @@ 1. Install [Tesseract](https://github.com/tesseract-ocr/tesseract/wiki) and make sure it is in your `$PATH`

2. `$ pip install videocr` -## API +## Functions ```python get_subtitles(

@@ -88,25 +89,25 @@ - `lang`

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. - Note that you can use more than one language. For example, `'hin+eng'` means using Hindi and English together for recognition. More details are available in the [Tesseract documentation](https://github.com/tesseract-ocr/tesseract/wiki/Command-Line-Usage#using-multiple-languages). + Note that you can use more than one language, e.g. `lang='hin+eng'` for Hindi and English together. - Language data files will be automatically downloaded to your `$HOME/tessdata` directory when necessary. You can read more about Tesseract language data files on their [wiki page](https://github.com/tesseract-ocr/tesseract/wiki/Data-Files). + 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). -- `time_start` and `time_end` +- `conf_threshold` - Extract subtitles from only a part of the video. The subtitle timestamps are still calculated according to the full video length. + Confidence threshold for word predictions. Words with lower confidence than this value will be discarded. The default value `65` is fine for most cases. -- `conf_threshold` + 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. - Confidence threshold for word predictions. Words with lower confidence than this threshold are discarded. The default value is fine for most cases. +- `sim_threshold` - Make it closer to 0 if you get too few words from the predictions, or make it closer to 100 if you get too many excess words. + 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. -- `sim_threshold` + 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. - Similarity threshold for subtitle lines. Neighbouring subtitles with larger [Levenshtein](https://en.wikipedia.org/wiki/Levenshtein_distance) ratios than this threshold will be merged together. The default value is fine for most cases. +- `time_start` and `time_end` - 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. + Extract subtitles from only a clip of the video. The subtitle timestamps are still calculated according to the full video length. - `use_fullframe`