Skip to content

Commit

Permalink
support subtitle batch alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
baxtree committed May 24, 2021
1 parent 38a7e0d commit 94f5926
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 864 deletions.
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ install:
.$(PYTHON)/bin/pip install -e . --ignore-installed
cp ./bin/subaligner_1pass .$(PYTHON)/bin/subaligner_1pass
cp ./bin/subaligner_2pass .$(PYTHON)/bin/subaligner_2pass
cp ./bin/subaligner_batch .$(PYTHON)/bin/subaligner_batch
cp ./bin/subaligner_convert .$(PYTHON)/bin/subaligner_convert
cp ./bin/subaligner_train .$(PYTHON)/bin/subaligner_train
cp ./bin/subaligner_tune .$(PYTHON)/bin/subaligner_tune
cp ./bin/subaligner .$(PYTHON)/bin/subaligner

uninstall:
rm -f .$(PYTHON)/bin/subaligner
rm -f .$(PYTHON)/bin/subaligner_1pass
rm -f .$(PYTHON)/bin/subaligner_2pass
rm -f .$(PYTHON)/bin/subaligner_batch
rm -f .$(PYTHON)/bin/subaligner_convert
rm -f .$(PYTHON)/bin/subaligner_train
rm -f .$(PYTHON)/bin/subaligner_tune

Expand All @@ -57,7 +63,7 @@ test:
cat requirements.txt | xargs -L 1 .$(PYTHON)/bin/pip install; \
cat requirements-dev.txt | xargs -L 1 .$(PYTHON)/bin/pip install
PYTHONPATH=. .$(PYTHON)/bin/python -m unittest discover
-.$(PYTHON)/bin/pycodestyle subaligner tests examples misc bin/subaligner bin/subaligner_1pass bin/subaligner_2pass bin/subaligner_train bin/subaligner_tune setup.py --ignore=E203,E501,W503 --exclude="subaligner/lib"
-.$(PYTHON)/bin/pycodestyle subaligner tests examples misc bin/subaligner bin/subaligner_1pass bin/subaligner_2pass bin/subaligner_batch bin/subaligner_convert bin/subaligner_train bin/subaligner_tune setup.py --ignore=E203,E501,W503 --exclude="subaligner/lib"

test-all: ## run tests on every Python version with tox
.$(PYTHON)/bin/tox
Expand All @@ -79,17 +85,18 @@ pydoc: clean-doc ## generate pydoc HTML documentation based on docstrings
cat requirements.txt | xargs -L 1 .$(PYTHON)/bin/pip install; \
.$(PYTHON)/bin/python -m pydoc -w subaligner; mv subaligner.html docs/index.html
.$(PYTHON)/bin/python -m pydoc -w subaligner.embedder; mv subaligner.embedder.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.exception; mv subaligner.exception.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.hparam_tuner; mv subaligner.hparam_tuner.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.hyperparameters; mv subaligner.hyperparameters.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.logger; mv subaligner.logger.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.media_helper; mv subaligner.media_helper.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.network; mv subaligner.network.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.predictor; mv subaligner.predictor.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.singleton; mv subaligner.singleton.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.subtitle; mv subaligner.subtitle.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.trainer; mv subaligner.trainer.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.translator; mv subaligner.translator.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.utils; mv subaligner.utils.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.subtitle; mv subaligner.subtitle.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.logger; mv subaligner.logger.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner.exception; mv subaligner.exception.html docs
.$(PYTHON)/bin/python -m pydoc -w subaligner._version; mv subaligner._version.html docs
$(BROWSER) docs/index.html

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ $ subaligner -m single -v video.mp4 -s subtitle.srt -t src,tgt
$ subaligner -m dual -v video.mp4 -s subtitle.srt -t src,tgt
```
```
# Run batch alignment
$ subaligner_batch -m single -vd /videos -sd /subtitles -od /aligned_subtitles
$ subaligner_batch -m dual -vd /videos -sd /subtitles -od /aligned_subtitles
```
```
# Run alignments with pipx
$ pipx run subaligner -m single -v video.mp4 -s subtitle.srt
Expand All @@ -116,7 +122,7 @@ $ docker run -it baxtree/subaligner subaligner_1pass -v https://example.com/vide
$ docker run -it baxtree/subaligner subaligner_2pass -v https://example.com/video.mp4 -s https://example.com/subtitle.srt -o subtitle_aligned.srt
```
The aligned subtitle will be saved at `subtitle_aligned.srt`. For details on CLI, run `subaligner_1pass -h`, `subaligner_2pass -h` or `subaligner -h`.
Additional utilities can be used after consulting `subaligner_convert -h`, `subaligner_train -h` and `subaligner_tune -h`.
Additional utilities can be used after consulting `subaligner_batch -h`, `subaligner_convert -h`, `subaligner_train -h` and `subaligner_tune -h`.

![](figures/screencast.gif)
## Supported Formats
Expand Down
1 change: 1 addition & 0 deletions bin/subaligner_batch
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"subaligner.lib",
"subaligner.subaligner_1pass",
"subaligner.subaligner_2pass",
"subaligner.subaligner_batch",
"subaligner.subaligner_convert",
"subaligner.subaligner_train",
"subaligner.subaligner_tune",
Expand All @@ -59,6 +60,7 @@
"bin/subaligner",
"bin/subaligner_1pass",
"bin/subaligner_2pass",
"bin/subaligner_batch",
"bin/subaligner_convert",
"bin/subaligner_train",
"bin/subaligner_tune",
Expand All @@ -68,6 +70,7 @@
"subaligner=subaligner.__main__:main",
"subaligner_1pass=subaligner.subaligner_1pass.__main__:main",
"subaligner_2pass=subaligner.subaligner_2pass.__main__:main",
"subaligner_batch=subaligner.subaligner_batch.__main__:main",
"subaligner_convert=subaligner.subaligner_convert.__main__:main",
"subaligner_train=subaligner.subaligner_train.__main__:main",
"subaligner_tune=subaligner.subaligner_tune.__main__:main",
Expand Down
2 changes: 2 additions & 0 deletions site/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ to create a virtual environment and set up all the dependencies:
(.venv) $ subaligner --help
(.venv) $ subaligner_1pass --help
(.venv) $ subaligner_2pass --help
(.venv) $ subaligner_batch --help
(.venv) $ subaligner_convert --help
(.venv) $ subaligner_train --help
(.venv) $ subaligner_tune --help

Expand Down
5 changes: 5 additions & 0 deletions site/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Make sure you have got the virtual environment activated upfront.
(.venv) $ subaligner -m single -v video.mp4 -s subtitle.srt -t src,tgt
(.venv) $ subaligner -m dual -v video.mp4 -s subtitle.srt -t src,tgt

**Run batch alignment**::

(.venv) $ subaligner_batch -m single -vd /videos -sd /subtitles -od /aligned_subtitles
(.venv) $ subaligner_batch -m dual -vd /videos -sd /subtitles -od /aligned_subtitles

**Run alignments with the docker image**::

$ docker pull baxtree/subaligner
Expand Down
6 changes: 6 additions & 0 deletions subaligner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,23 @@ def main():
sys.exit(0)
if FLAGS.mode == "":
print("--mode was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.video_path == "":
print("--video_path was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path == "":
print("--subtitle_path was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path.lower().startswith("http") and FLAGS.output == "":
print("--output was not passed in for alignment on a remote subtitle file")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path.lower().startswith("teletext:") and FLAGS.output == "":
print("--output was not passed in for alignment on embedded subtitles")
parser.print_usage()
sys.exit(21)

local_video_path = FLAGS.video_path
Expand Down Expand Up @@ -194,6 +199,7 @@ def main():
Utils.extract_matroska_subtitle(local_video_path, int(params["stream_index"]), local_subtitle_path)
else:
print("Embedded subtitle selector cannot be empty")
parser.print_usage()
sys.exit(21)

predictor = Predictor()
Expand Down
5 changes: 5 additions & 0 deletions subaligner/subaligner_1pass/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,19 @@ def main():
sys.exit(0)
if FLAGS.video_path == "":
print("--video_path was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path == "":
print("--subtitle_path was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path.lower().startswith("http") and FLAGS.output == "":
print("--output was not passed in for alignment on a remote subtitle file")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path.lower().startswith("teletext:") and FLAGS.output == "":
print("--output was not passed in for alignment on embedded subtitles")
parser.print_usage()
sys.exit(21)

local_video_path = FLAGS.video_path
Expand Down Expand Up @@ -151,6 +155,7 @@ def main():
Utils.extract_matroska_subtitle(local_video_path, int(params["stream_index"]), local_subtitle_path)
else:
print("Embedded subtitle selector cannot be empty")
parser.print_usage()
sys.exit(21)

predictor = Predictor()
Expand Down
5 changes: 5 additions & 0 deletions subaligner/subaligner_2pass/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,19 @@ def main():
sys.exit(0)
if FLAGS.video_path == "":
print("--video_path was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path == "":
print("--subtitle_path was not passed in")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path.lower().startswith("http") and FLAGS.output == "":
print("--output was not passed in for alignment on a remote subtitle file")
parser.print_usage()
sys.exit(21)
if FLAGS.subtitle_path.lower().startswith("teletext:") and FLAGS.output == "":
print("--output was not passed in for alignment on embedded subtitles")
parser.print_usage()
sys.exit(21)

local_video_path = FLAGS.video_path
Expand Down Expand Up @@ -181,6 +185,7 @@ def main():
Utils.extract_matroska_subtitle(local_video_path, int(params["stream_index"]), local_subtitle_path)
else:
print("Embedded subtitle selector cannot be empty")
parser.print_usage()
sys.exit(21)

predictor = Predictor()
Expand Down
Empty file.
Loading

0 comments on commit 94f5926

Please sign in to comment.