.srt字幕格式如下:
1
00:00:48,860 --> 00:00:51,400
站好,你不喜欢你的工作吗?

2
00:01:00,160 --> 00:01:01,540
食物

3
00:01:06,090 --> 00:01:08,090
你要去哪里?

.......

ruby代码如下:
ruby 代码
 
  1. # param: time_str : string with "00:01:08,123" like format  
  2. # param: offset : int, seconds to shift ahead  
  3. def offset(time_str, offset)  
  4.   new_time = Time.parse(time_str) - offset  
  5.   format("%02d:%02d:%02d,%03d", new_time.hour, new_time.min, new_time.sec, new_time.usec/1000)  
  6. end  
  7.   
  8. def convert(src_file_path, dst_file_path, offset)  
  9.   open(dst_file_path, "w"do |dst_file|  
  10.     open(src_file_path, "r").each_line do |line|  
  11.       if line.include?(" --> ")  
  12.         new_line = line.split(" --> ").collect{ |time_str| offset(time_str, offset)}.join(" --> ")  
  13.         dst_file.puts new_line  
  14.         puts "line #{line} converted to #{new_line}"  
  15.       else  
  16.         dst_file.puts line  
  17.       end  
  18.     end  
  19.   end  
  20. end  
  21.   
  22. convert "c:\\src.srt""c:\\dst.srt", 90  
评论
发表评论

您还没有登录,请登录后发表评论

半人马
搜索本博客
最近访客
博客分类
最近加入圈子
存档
最新评论
评论排行榜