Subaligner provides two ways of aligning subtitles: single-stage alignment and dual-stage alignment. The former way has lower latency and shifts all subtitle segments globally. The latter way has higher latency and shifts the segments individually with an option of stretching each segment. Multilingual translation on subtitles can be achieved together with the alignment in one go or separately (see in Advanced Usage).

Make sure you have got the virtual environment activated upfront.

Single-stage alignment (high-level shift with lower latency):

(.venv) $ subaligner_1pass -v video.mp4 -s
(.venv) $ subaligner_1pass -v -s -o

Dual-stage alignment (low-level shift with higher latency):

(.venv) $ subaligner_2pass -v video.mp4 -s
(.venv) $ subaligner_2pass -v -s -o

Pass in single-stage or dual-stage as the alignment mode:

(.venv) $ subaligner -m single -v video.mp4 -s
(.venv) $ subaligner -m single -v -s -o
(.venv) $ subaligner -m dual -v video.mp4 -s
(.venv) $ subaligner -m dual -v -s -o

Alignment on segmented plain texts (double newlines as the delimiter):

(.venv) $ subaligner -m script -v test.mp4 -s subtitle.txt -o
(.venv) $ subaligner -m script -v -s -o

Translative alignment with the ISO 639-3 language code pair (src,tgt):

(.venv) $ subaligner_1pass --languages
(.venv) $ subaligner_1pass -v video.mp4 -s -t src,tgt
(.venv) $ subaligner_2pass --languages
(.venv) $ subaligner_2pass -v video.mp4 -s -t src,tgt
(.venv) $ subaligner --languages
(.venv) $ subaligner -m single -v video.mp4 -s -t src,tgt
(.venv) $ subaligner -m dual -v video.mp4 -s -t src,tgt
(.venv) $ subaligner -m script -v test.mp4 -s subtitle.txt -o -t src,tgt

Run batch alignment against directories:

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

Run alignments with the docker image:

$ docker pull baxtree/subaligner
$ docker run -v `pwd`:`pwd` -w `pwd` -it baxtree/subaligner subaligner_1pass -v video.mp4 -s
$ docker run -v `pwd`:`pwd` -w `pwd` -it baxtree/subaligner subaligner_2pass -v video.mp4 -s
$ docker run -it baxtree/subaligner subaligner_1pass -v -s -o
$ docker run -it baxtree/subaligner subaligner_2pass -v -s -o

Run alignments with pipx:

$ pipx run subaligner -m single -v video.mp4 -s
$ pipx run subaligner -m dual -v video.mp4 -s

Run the module as a script:

$ python -m subaligner -m single -v video.mp4 -s
$ python -m subaligner -m dual -v video.mp4 -s
$ python -m subaligner.subaligner_1pass -v video.mp4 -s
$ python -m subaligner.subaligner_2pass -v video.mp4 -s

Currently the stretching is experimental and make sure subaligner[stretch] is installed before switching it on with -so or –stretch_on as shown below.

Switch on stretching when aligning subtitles:

(.venv) $ subaligner_2pass -v video.mp4 -s -so
(.venv) $ subaligner -m dual -v video.mp4 -s -so

Save the aligned subtitle to a specific location:

(.venv) $ subaligner_2pass -v video.mp4 -s -o /path/to/the/output/
(.venv) $ subaligner -m dual -v video.mp4 -s -o /path/to/the/output/

On Windows:

docker run -v "/d/media":/media -w "/media" -it baxtree/subaligner COMMAND

The aforementioned commands can be run with Docker Desktop on Windows 10.

Re-configure FFmpeg/Libav path:

(.venv) $ export FFMPEG_PATH=/path/to/ffmpeg
(.venv) $ subaligner -m dual -v video.mp4 -s
(.venv) $ FFMPEG_PATH=/path/to/ffmpeg subaligner -m dual -v video.mp4 -s
or when using `Libav<>`_
(.venv) $ FFMPEG_PATH=/path/to/avconv subaligner -m dual -v video.mp4 -s

The lower case “ffmpeg_path” is also supported.