Saturday, March 15, 2014

A desperate method to burn-in subtitles

While the method may seem 'desperate', this may also prove to be the easiest way to burn-in subtitles (*.srt).  It seems to me that any thread on any forum about burning in subs with ffmpeg appears to be silent.  The lack of eureka's and heartfelt thank-you's only confirms one's suspicion that the thread topic is unresolved.  With resignation, I have concluded that: "It's just me... and everyone else can do it."

Reading up on the somewhat cryptic ffmpeg documentation, I learned that the drawtext filter may probably be only good for PTS, timecode, and single-line text.  The proverbial lightbulb somehow flickered when I came upon the sendcmd filter.  Hmmm...  I imagined hearing the sound of rusty gears slowly turning in my head.  The quietest most hesitant 'eureka' in the history of mankind may have escaped my lips.  Uhh no, I didn't actually say 'eureka', because I'm Filipino, and we don't talk like that, but you get my drift.

After some quick tests, the verdict was out:  All one has to do is create a sendcmd file (*.txt) containing all the drawtext commands telling ffmpeg what text to draw and when to draw it.  It's quite simple really!

The idea is to change this:
1
00:00:19,420 --> 00:00:23,090
A SERBIAN FILM


into this:
00:00:19.420-00:00:23.090 [enter] drawtext reinit text='A SERBIAN FILM', [leave] drawtext reinit text='';


With less than 300 lines of code (AutoIt), I have managed to convert an *.srt file into a text file that could boss around ffmpeg.

This is my eureka moment I want to share with anyone who has lost a good amount of hair trying to figure out how to burn-in those d*mn subtitles.

This tiny app (absolutely free) for Windows is about 641 kb (includes the CLI executable, a GUI, and source code) and you can download it here:



updated: 2014.05.26
http://www.mediafire.com/download/3is5jc5v851h274/srtdrawtext_2014. 05.26.zip


An easier-to-use version that works in conjunction with VidProk (included in 'En Masse' which is also absolutely free) can be downloaded here: http://enmassevideo.blogspot.com/2014/02/en-masse-batch-processor-for-videos.html

Update 2014.05.26:
Yeah, I made a boo-boo... I didn't bother googling SubRip specifications prior to coding with a handful of SubRip files as samples (hehehe oops!).