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



## NapoleonWils0n (Aug 9, 2019)

Extracting, adding and deleting closed captions from videos

ffmpeg install


```
# pkg install ffmpeg
```

ccextractor install


```
# pkg install ccextractor
```

youtube-dl pkg install


```
# pkg install youtube-dl
```

Youtube-dl manual install

Manually install youtube-dl using pip on Freebsd

Install python 3.6 and pip and mpv


```
# 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


```
# 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


```
source ~/.bashrc
```

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


```
source ~/.zshrc
```

youtube-dl install


```
pip-3.6 install --user youtube_dl
```

youtube-dl upgrade


```
pip-3.6 install --upgrade --user youtube_dl
```

youtube-dl uninstall


```
pip-3.6 uninstall youtube_dl
```

youtube-dl download subtitles from video


```
youtube-dl --write-sub --sub-lang en --skip-download 'youtube-video-url'
```

youtube-dl batch download subtitles from a text file with youtube urls


```
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


```
ffmpeg -i infile.vtt -c:s text outfile.srt
```

Batch convert vtt subtitles to srt format


```
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


```
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


```
ffmpeg -i infile.scc -c:s text outfile.srt
```

Batch convert scc closed captions to srt format


```
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


```
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


```
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
```


----------



## C. Adams (Sep 24, 2022)

So this guide was very useful to me when CCExtractor worked.  However, it has started to give me errors when I use it (report filed here: https://github.com/CCExtractor/ccextractor/issues/1450 ) but even more than that I tried to rebuild my jail and discovered that CCExtractor now no longer has a port/pkg.  (See https://www.freshports.org/multimedia/ccextractor/ )

Do you have a recommendation for a alternative closed caption extractor to use that works with FreeBSD 13+?


----------



## Alain De Vos (Sep 24, 2022)

My dvd player seems to only know divx ...


----------

