Skip to content

Instantly share code, notes, and snippets.

@j9ac9k

j9ac9k/dvd_conversion.md

Last active Apr 17, 2019
Embed
What would you like to do?
notes for converting some DVDs to a modern file format; including cropping of the letterbox, converting bitmap subtitles to text based, and visually lossless encoding.

FFMpeg DVD Conversion

To get crop geometry:

ffmpeg -i input.mkv -vf cropdetect=24:16:0 dummy.mkv
...
[Parsed_cropdetect_0 @ 0x3704360] x1:0 x2:639 y1:43 y2:317 w:640 h:272 x:0 y:46 pts:181320 t:181.320000 crop=640:272:0:46
...

In the example above we care about the 640:272:0:46 bit...

If we were to use those values in another video it would be:

ffmpeg -i Star\ Wars\ -\ Episode\ VI\ -\ Return\ of\ the\ Jedi.mkv \
-vf crop=704:272:8:104 \
-aspect 704:272 \
-c:v libx264 \
-crf 17 \
-c:a copy \
-profile:v high \
-preset medium \
-tune fastdecode \
-tune film \
-tune grain \
-level 4.1 \
-movflags +faststart \
output.mkv

For the empire strikes back I got the following values:

704:272:8:106

Explanations

Level 4.1 sets the video to be compatible with first generation chromecast (probably oldest/lowest power device we routinely use) and original raspberry pi's

Subtitles

Subtitles in these dvds are stored in vorbis format, which are effectively images, so we need to extract them, use some OCR and convert them to srt format.

Extracting The Vorbis Files

mkvinfo some_movies.mkv

Look for something like...

| + Track
|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)
|  + Track UID: 3
|  + Track type: subtitles
|  + Enabled: 1
|  + Default track flag: 1
|  + Forced track flag: 0
|  + Lacing flag: 0
|  + Minimum cache: 0
|  + Maximum block additional ID: 0
|  + Codec ID: S_VOBSUB
|  + Codec decode all: 1
|  + Language: eng
|  + Codec's private data: size 508
| + Track
|  + Track number: 4 (track ID for mkvmerge & mkvextract: 3)
|  + Track UID: 4
|  + Track type: subtitles
|  + Enabled: 1
|  + Default track flag: 0
|  + Forced track flag: 0
|  + Lacing flag: 0
|  + Minimum cache: 0
|  + Maximum block additional ID: 0
|  + Codec ID: S_VOBSUB
|  + Codec decode all: 1
|  + Language: fre
|  + Codec's private data: size 508
| + Track
|  + Track number: 5 (track ID for mkvmerge & mkvextract: 4)
|  + Track UID: 5
|  + Track type: subtitles
|  + Enabled: 1
|  + Default track flag: 0
|  + Forced track flag: 0
|  + Lacing flag: 0
|  + Minimum cache: 0
|  + Maximum block additional ID: 0
|  + Codec ID: S_VOBSUB
|  + Codec decode all: 1
|  + Language: spa
|  + Codec's private data: size 508

extract them via

mkvextract tracks \
some_movie.mkv \
3:some_movie.eng.srt \
4:some_movie.fre.srt \
5:some_movie.spa.srt

OCR Baby

Use vobsub2srt here:

GitHub - ruediger/VobSub2SRT: Converts VobSub subtitles (.idx/.srt format) into .srt subtitles.

brew install --with-all-languages tesseract
brew install --HEAD https://github.com/ruediger/VobSub2SRT/raw/master/packaging/vobsub2srt.rb

Create the srt files

vobsub2srt some_movie.eng
vobsub2srt some_movie.fre
vobsub2srt some_movie.spa

Convert the files to ass files

ffmpeg -i some_movie.eng.srt some_movie.eng.ass

Embed the file into the movie

ffmpeg -i some_movie.mkv -i some_movie.eng.ass \
-codec copy \
-map 0 \
-map 1 \
-metadata:s:s:0 language=eng \
output.mkv

References

[GUIDE] extract vobsub from .mkv and convert to .srt external file - Computers - Plex Forum

How to Add Font size in subtitles in ffmpeg video filter - Stack Overflow

GitHub - ruediger/VobSub2SRT: Converts VobSub subtitles (.idx/.srt format) into .srt subtitles.

Set a subtitle language using ffmpeg - Stack Overflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment