Konubinix' opinionated web of thoughts

Burn Subtitle Ffmpeg Handbrake

Fleeting

I have an old chromecast, that does not allow reading subtitles from a separate stream, so I decided to burn them with ffmpeg

with text base subtitles -> easy with -vf:file

With bitmap bqased, trying the overlay stuff suggested in the wiki of ffmpeg dpes not wprk

I needed the complex filter stuff to scale them, and they don’t appezr correctly. They appear and immediately disapear, without leaving time to reqd thrm.

handbrake does the work quite well, but I don’t understand how to have fine control over the output. The resukt generally does not work with my old chromecast well and either to video does not start, or it cannot be seeked.

Also, ffmpeg is the “bash” of video editing. I would like to stick with it.

I moved to try OCRing the bitmap based subtitle.

Trying subtitleedit, it appears to be promising, but… well, its a java program:

  1. the command line looks strange ‘subtitleedit /?’ instead of ‘subtitleedit –help’.

  2. almost no inline documentation

  3. needs a X server to be run

    subtitleedit /?
    
    [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
    Parameter name: Display
      at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x003d0] in <4d2f9aca4e73456d84180e853fb8c1af>:0
      at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <4d2f9aca4e73456d84180e853fb8c1af>:0
      at System.Windows.Forms.XplatUIX11.GetInstance () [0x00019] in <4d2f9aca4e73456d84180e853fb8c1af>:0
      at System.Windows.Forms.XplatUI..cctor () [0x000c0] in <4d2f9aca4e73456d84180e853fb8c1af>:0
       --- End of inner exception stack trace ---
      at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <4d2f9aca4e73456d84180e853fb8c1af>:0
      at Nikse.SubtitleEdit.Program.Main () [0x0002d] in <fd2bd832ecbe49f6a3e141984b2aca8d>:0
    

Also, the result was pretty bad, with typos at almost every word. I assume that if I could specify the OCR lang, it would be better.

Then, I found pgsrip, with a more pythonic approach

pgsrip --help
Usage: pgsrip [OPTIONS] PATH...

Options:
  -c, --config PATH               cleanit configuration path to be used
  -l, --language LANGUAGE         Language as IETF code, e.g. en, pt-BR (can
                                  be used multiple times).
  -t, --tag TEXT                  Rule tags to be used, e.g. ocr, tidy, no-
                                  sdh, no-style, no-lyrics, no-spam (can be
                                  used multiple times).
  -e, --encoding TEXT             Save subtitles using the following encoding.
  -a, --age AGE                   Filter videos newer than AGE, e.g. 12h,
                                  1w2d.
  -A, --srt-age AGE               Filter videos which srt subtitles are newer
                                  than AGE, e.g. 12h, 1w2d.
  -f, --force                     re-rip and overwrite existing srt subtitles,
                                  even if they already exist
  -a, --all                       rip all tracks for a given language, even
                                  another track for that language was already
                                  ripped
  -w, --max-workers INTEGER RANGE
                                  Maximum number of threads to use.
                                  [1<=x<=50]
  --keep-temp-files               Do not delete temporary files created, e.g.
                                  extracted sup files, generated png files and
                                  other useful debug files
  --debug                         Print useful information for debugging and
                                  for reporting bugs.
  -v, --verbose                   Display debug messages
  --version                       Show the version and exit.
  --help                          Show this message and exit.
pgsrip -l en 01.mkv
Collecting pgs subtitles
1 PGS subtitle collected from 1 file / 0 path ignored
Ripping subtitles
1 PGS subtitle ripped from 1 file

So far, I could not find any OCR mistake. It would have been better to be able to decide the output filename, but it is still very satisfying.

Then, I can srt -> vtt the resulting file with ‘ffmpeg -i 01.en.srt -f webvtt 01.en.vtt’ and burn it the usual way.