Media utils
Video Subtitles
This tutorial explains how to add subtitles to the video files.
Prepare
Install:
sudo apt install qnapi uchardet ffmpeg recode
Download subtitles for your language
Qnapi
qnapi -l pl *.mp4
qnapi -l pl *.mkv
VLsub
or open with VLC, with VLsub extension.
Subliminal
pip install subliminal
subliminal download -l pl *.mkv
Detect encoding
uchardet *.txt
UTF-8
, Windows-1250
or UTF-16
.
Verify that converted encoding is actually fine
cat *.txt | recode cp1250..utf8
cat *.txt | recode utf16..utf8
Available encodings:
recode --list
Recode to UTF8
recode cp1250..utf8 *.txt
# or
recode utf16..utf8 *.txt
Convert to SRT
Convert TXT to SRT, add .default.srt
suffix for Jellyfin:
ffmpeg -i 'S01E03.txt' 'S01E03.default.srt'
ls -1 *.txt | sed -e 's/\.txt$//g' | xargs -d '\n' -I %s echo 'ffmpeg -i "%s.txt" "%s.default.srt"'
Appendix
Do the ffmpeg conversion for all TXT files in the current directory:
from pathlib import Path
from nuclear import shell
for path in Path('.').iterdir():
if path.name.endswith('.txt'):
stem = path.name[:-4]
print(f'converting {path.name}')
shell(f"ffmpeg -i '{stem}.txt' '{stem}.default.srt'")
Download YouTube video as MP4
pip install -U yt-dlp
yt-dlp -f 'bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' URL