top / index / prev / next / target / source

2015-02-11 diary: 字幕テキスト (.srt) のテンプレ生成

いがぴょん画像(小) 日記形式でつづる いがぴょんコラム ウェブページです。

字幕テキスト (.srt) のテンプレ生成

Java でテンプレ生成するソースを軽く書いてみました。

import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;

public class MakeSrt {
public static void main(String args[]) throws Exception {
  final Calendar dateFrom = Calendar.getInstance();
  final SimpleDateFormat sd = new SimpleDateFormat("HH:mm:ss,000");
  final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("aaa.srt"), "UTF-8"));
  dateFrom.set(Calendar.HOUR_OF_DAY, 0);
  dateFrom.set(Calendar.MINUTE, 0);
  dateFrom.set(Calendar.SECOND, 0);
  for (int index = 1; index < 70; index++) {
    String from = sd.format(dateFrom.getTime());
    dateFrom.add(Calendar.SECOND, 5);
    String to = sd.format(dateFrom.getTime());
    writer.write("" + index);
    writer.newLine();
    System.out.println(from + " --> " + to);
    writer.write(from + " --> " + to);
    writer.newLine();
    writer.write("(" + index + ")message");
    writer.newLine();
    writer.newLine();
  }
  writer.close();
}
}

生成されたテンプレ

できあがるのは以下の感じのテキストファイル。

1
00:00:00,000 --> 00:00:05,000
(1)message

2
00:00:05,000 --> 00:00:10,000
(2)message

3
00:00:10,000 --> 00:00:15,000
(3)message

4
00:00:15,000 --> 00:00:20,000
(4)message

5
00:00:20,000 --> 00:00:25,000
(5)message

6
00:00:25,000 --> 00:00:30,000
(6)message

7
00:00:30,000 --> 00:00:35,000
(7)message

8
00:00:35,000 --> 00:00:40,000
(8)message

9
00:00:40,000 --> 00:00:45,000
(9)message

10
00:00:45,000 --> 00:00:50,000
(10)message

11
00:00:50,000 --> 00:00:55,000
(11)message

12
00:00:55,000 --> 00:01:00,000
(12)message

13
00:01:00,000 --> 00:01:05,000
(13)message

14
00:01:05,000 --> 00:01:10,000
(14)message

15
00:01:10,000 --> 00:01:15,000
(15)message

16
00:01:15,000 --> 00:01:20,000
(16)message

17
00:01:20,000 --> 00:01:25,000
(17)message

18
00:01:25,000 --> 00:01:30,000
(18)message

19
00:01:30,000 --> 00:01:35,000
(19)message

20
00:01:35,000 --> 00:01:40,000
(20)message

21
00:01:40,000 --> 00:01:45,000
(21)message

22
00:01:45,000 --> 00:01:50,000
(22)message

23
00:01:50,000 --> 00:01:55,000
(23)message

24
00:01:55,000 --> 00:02:00,000
(24)message

25
00:02:00,000 --> 00:02:05,000
(25)message

26
00:02:05,000 --> 00:02:10,000
(26)message

27
00:02:10,000 --> 00:02:15,000
(27)message

28
00:02:15,000 --> 00:02:20,000
(28)message

29
00:02:20,000 --> 00:02:25,000
(29)message

30
00:02:25,000 --> 00:02:30,000
(30)message

31
00:02:30,000 --> 00:02:35,000
(31)message

32
00:02:35,000 --> 00:02:40,000
(32)message

33
00:02:40,000 --> 00:02:45,000
(33)message

34
00:02:45,000 --> 00:02:50,000
(34)message

35
00:02:50,000 --> 00:02:55,000
(35)message

36
00:02:55,000 --> 00:03:00,000
(36)message

37
00:03:00,000 --> 00:03:05,000
(37)message

38
00:03:05,000 --> 00:03:10,000
(38)message

39
00:03:10,000 --> 00:03:15,000
(39)message

40
00:03:15,000 --> 00:03:20,000
(40)message

41
00:03:20,000 --> 00:03:25,000
(41)message

42
00:03:25,000 --> 00:03:30,000
(42)message

43
00:03:30,000 --> 00:03:35,000
(43)message

44
00:03:35,000 --> 00:03:40,000
(44)message

45
00:03:40,000 --> 00:03:45,000
(45)message

46
00:03:45,000 --> 00:03:50,000
(46)message

47
00:03:50,000 --> 00:03:55,000
(47)message

48
00:03:55,000 --> 00:04:00,000
(48)message

49
00:04:00,000 --> 00:04:05,000
(49)message

50
00:04:05,000 --> 00:04:10,000
(50)message

51
00:04:10,000 --> 00:04:15,000
(51)message

52
00:04:15,000 --> 00:04:20,000
(52)message

53
00:04:20,000 --> 00:04:25,000
(53)message

54
00:04:25,000 --> 00:04:30,000
(54)message

55
00:04:30,000 --> 00:04:35,000
(55)message

56
00:04:35,000 --> 00:04:40,000
(56)message

57
00:04:40,000 --> 00:04:45,000
(57)message

58
00:04:45,000 --> 00:04:50,000
(58)message

59
00:04:50,000 --> 00:04:55,000
(59)message

60
00:04:55,000 --> 00:05:00,000
(60)message

61
00:05:00,000 --> 00:05:05,000
(61)message

62
00:05:05,000 --> 00:05:10,000
(62)message

63
00:05:10,000 --> 00:05:15,000
(63)message

64
00:05:15,000 --> 00:05:20,000
(64)message

65
00:05:20,000 --> 00:05:25,000
(65)message

66
00:05:25,000 --> 00:05:30,000
(66)message

67
00:05:30,000 --> 00:05:35,000
(67)message

68
00:05:35,000 --> 00:05:40,000
(68)message

69
00:05:40,000 --> 00:05:45,000
(69)message

この日記について