2007-08-09
小练习一则:将.srt格式的视频字幕文件中字幕向前或向后推移一段时间
关键字: ruby
.srt字幕格式如下:
ruby代码如下:
| 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 代码
- # param: time_str : string with "00:01:08,123" like format
- # param: offset : int, seconds to shift ahead
- def offset(time_str, offset)
- new_time = Time.parse(time_str) - offset
- format("%02d:%02d:%02d,%03d", new_time.hour, new_time.min, new_time.sec, new_time.usec/1000)
- end
- def convert(src_file_path, dst_file_path, offset)
- open(dst_file_path, "w") do |dst_file|
- open(src_file_path, "r").each_line do |line|
- if line.include?(" --> ")
- new_line = line.split(" --> ").collect{ |time_str| offset(time_str, offset)}.join(" --> ")
- dst_file.puts new_line
- puts "line #{line} converted to #{new_line}"
- else
- dst_file.puts line
- end
- end
- end
- end
- convert "c:\\src.srt", "c:\\dst.srt", 90
发表评论
最近加入圈子
最新评论
-
dwr作为数据源的extjs gr ...
:D :) :( 引用
-- by qqggcc -
Acegi中的FilterInvocati ...
能具体介绍一下用法么?该怎么配置?
-- by godson_2003 -
dwr作为数据源的extjs gr ...
这样在grid 点击列的排序问题怎么解决呢 ??
-- by sariy -
dwr作为数据源的extjs gr ...
不知道有没有关于tree的方案?
-- by kaki -
Acegi中的FilterInvocati ...
请问一下!我的requestMap为什么一直都是空值啊?
-- by hunter0116







评论排行榜