Downloading, extracting and adding subtitles to video on the command line

NapoleonWils0n

Active Member

Reaction score: 51
Messages: 156

Extracting, adding and deleting closed captions from videos

ffmpeg install

Bash:
# pkg install ffmpeg
ccextractor install

Bash:
# pkg install ccextractor
youtube-dl pkg install

Bash:
# pkg install youtube-dl
Youtube-dl manual install

Manually install youtube-dl using pip on Freebsd

Install python 3.6 and pip and mpv

Bash:
# pkg install python36 py36-pip mpv
mpv will install the youtube-dl package, but we will install a more up to date version using pip
mpv will then use the manually installed version of youtube-dl

add the python bin to your shell path

add the following code to your ~/.bashrc if uisng bash,
or to your ~/.zshrc file if your are using the zsh shell

Bash:
# home local python bin
if [ -d "$HOME/.local/bin" ]; then
   PATH="$HOME/.local/bin:$PATH"
fi
source your ~/.bashrc if you are using the bash shell

Bash:
source ~/.bashrc
or source your ~/.zshrc file in using the zsh shell

Bash:
source ~/.zshrc
youtube-dl install

Bash:
pip-3.6 install --user youtube_dl
youtube-dl upgrade

Bash:
pip-3.6 install --upgrade --user youtube_dl
youtube-dl uninstall

Bash:
pip-3.6 uninstall youtube_dl
youtube-dl download subtitles from video

Bash:
youtube-dl --write-sub --sub-lang en --skip-download 'youtube-video-url'
youtube-dl batch download subtitles from a text file with youtube urls

Bash:
youtube-dl --write-sub --sub-lang en --skip-download -a links.txt
Where links.txt is a text file with youtube video urls

Convert the vtt subtitles from youtube to srt format

Bash:
ffmpeg -i infile.vtt -c:s text outfile.srt
Batch convert vtt subtitles to srt format

Bash:
find . -type f -name "*.vtt" -exec sh -c 'ffmpeg -i "$0" \
-c:s text "${0%.*}.srt"' "{}" \;
Extract closed captions

Extract closed captions from a video with ccextractor

Bash:
ccextractor infile.mp4
This will create a .scc captions file which we can convert to srt format with ffmpeg

convert scc closed captions to srt subtitles,
and remove text formatting and font tags for youtube

Bash:
ffmpeg -i infile.scc -c:s text outfile.srt
Batch convert scc closed captions to srt format

Bash:
find . -type f -name "*.scc" -exec sh -c 'ffmpeg -i "$0" \
-c:s text "${0%.*}.srt"' "{}" \;
remove close captions

remove close captions from video without re encode

Bash:
ffmpeg -i infile.mp4 \
-c copy \
-bsf:v "filter_units=remove_type=6" \
-movflags +faststart \
outfile.mp4
ffmpeg add subtitles to video

Add a subtitles track to a video from a srt subtitles file

note this does not burn in the subtitles over the video,
it creates a subtitles track that the user can enable to show the subtitles


Bash:
ffmpeg -i infile.mp4 \
-f srt -i infile.srt \
-c:a copy -c:v copy -c:s \
mov_text -metadata:s:s:0 \
language=eng \
-movflags +faststart \
outfile.mp4
 
Top