Prab's Code Blog

Because talk is cheap, show me the code!

Ruby Script to Generate 3D Subtitles From Srt Files

So, you’ve got a bunch of 3D movies with SRT subtitles which your 3D TV can play from a USB storage and show the subtitles correctly but can not if you are running the movie on your laptop and sending the display to TV over HDMI; for obvious reasons. The solution is to use .ass format subtitles with your media player(I recommed mplayer/smplayer). Just run this script from a directory that contains all your movies in separate directories under that directory. Make sure, srt file is present in each 3D movie directory and has the same name as the movie file. Also make sure, the directories for 3D movies have 3D in their names somewhere. Moreover, you must have the program sub3dtool installed. Get it from here. After you run the script, all your 3D movie directories will be populated with .ass files automatically. Remember, VLC media player does not play well with .ass subtitles. It skips many dialogues.

Convert SRT subtitles into ASS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Dir.entries(".").each do |file|
  if file.include? "3D"
    puts "3D movie found - #{file}. Going ahead to generate .ass subtitle for it"
    Dir.entries(file).each do |file1|
      if file1.include? ".srt"
        puts "Found srt file: #{file1}"
        outfile_name = "#{file1[0,file1.length-3]}ass"
        puts "Out file name : #{outfile_name}"
        `sub3dtool "#{file}/#{file1}" --3dsbs -o "#{file}/#{outfile_name}"`
        puts "Generated successfully"
      end
    end
  end
end

All the movie directories will be populated with corresponding .ass files. Now just run it by mplayer -ass movie_file_name. Use j to cycle through subtitles, f for fullscreen, q to quit mplayer.

Comments