| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 | const char idx_data[] = "# VobSub index file, v7 (do not modify this line!)\npalette: 000000, ffffff, 000000, 000000, 828282, 828282, 828282, ffffff, 828282, bababa, 828282, 828282, 828282, 828282, 828282, 828282\n\nlangidx: 0\n\nid: en, index: 0\ntimestamp: 00:00:00:000, filepos: 000000000\n";
|
|---|
| 6 |
|
|---|
| 7 | unsigned char sub_data[0x800] = {
|
|---|
| 8 | /* 0x00 */ 0x00, 0x00, 0x01, 0xba, 0x44, 0x02, 0xc4, 0x82, 0x04, 0xa9, 0x01, 0x89, 0xc3, 0xf8, 0x00, 0x00,
|
|---|
| 9 | /*
|
|---|
| 10 | * 0x00, 0x00, 0x01 = "0x00 0x00 0x01"
|
|---|
| 11 | * 0xba = packet start code
|
|---|
| 12 | * 0x44 = mpeg version 4
|
|---|
| 13 | * 0x00, 0x00,
|
|---|
| 14 | */
|
|---|
| 15 | /* 0x10 */ 0x01, 0xbd, 0x00, 0x5c, 0x81, 0x80, 0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0x20, 0x00, 0x53, 0x00,
|
|---|
| 16 | /*
|
|---|
| 17 | * 0x01 = "0x00 0x00 0x01"
|
|---|
| 18 | * 0xbd = packet
|
|---|
| 19 | * 0x00, 0x5c = fragment size = 0x005c = 92 bytes
|
|---|
| 20 | * 0x81 = .VOB stream
|
|---|
| 21 | * 0x80 = pts_flags
|
|---|
| 22 | * 0x05 = header length = 5 bytes
|
|---|
| 23 | * 0x21, 0x00, 0x01, 0x00, 0x01 = header
|
|---|
| 24 | * 0x20 = aid
|
|---|
| 25 | * 0x00, 0x53 = SPDSZ
|
|---|
| 26 | * 0x00,
|
|---|
| 27 | */
|
|---|
| 28 | /* 0x20 */ 0x35, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x87, 0xd7, 0x80,
|
|---|
| 29 | /*
|
|---|
| 30 | * 0x35 = SP_DCSQTA = 0x0035 SP_DCSQT is at 0x001d + 0x0035 = 0x0052
|
|---|
| 31 | */
|
|---|
| 32 | /* 0x30 */ 0x87, 0xd7, 0x80, 0x86, 0xf6, 0x80, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
|
|---|
| 33 | /* 0x40 */ 0x24, 0x24, 0x24, 0x24, 0x87, 0xe7, 0x80, 0x87, 0xd7, 0x80, 0x87, 0xd7, 0x80, 0x24, 0x24, 0x24,
|
|---|
| 34 | /* 0x50 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x01, 0x03, 0x32, 0x10, 0x04, 0xff, 0xf0, 0x05, 0x1d, 0xb1,
|
|---|
| 35 | /*
|
|---|
| 36 | *
|
|---|
| 37 | * 0x00, 0x00 = SP_DCSQ_STM
|
|---|
| 38 | * 0x00, 0x4d = SP_NXT_DCSQ_SA = 0x004d next SP_DCSQT is at 0x1d + 0x4d = 0x6A
|
|---|
| 39 | * 0x01 = STA_DSP
|
|---|
| 40 | * 0x03, 0x32, 0x10 = SET_COLOR
|
|---|
| 41 | * 0x04, 0xff, 0xf0 = SET_CONTR
|
|---|
| 42 | * 0x05, 0x1d, 0x1b,
|
|---|
| 43 | */
|
|---|
| 44 | /* 0x60 */ 0xe3, 0x28, 0x92, 0xab, 0x06, 0x00, 0x04, 0x00, 0x1c, 0xff, 0x00, 0x57, 0x00, 0x4d, 0x02, 0xff,
|
|---|
| 45 | /*
|
|---|
| 46 | * 0xe3, 0x28, 0x92, 0xab = SET_DAREA
|
|---|
| 47 | * 0x06, 0x00, 0x04, 0x00, 0x1c = SET_DSPXA
|
|---|
| 48 | * 0xff = CMD_END
|
|---|
| 49 | * 0x00, 0x57 = SP_DCSQ_STM
|
|---|
| 50 | * 0x00, 0x4d = SP_NXT_DCSQ_SA
|
|---|
| 51 | * 0x02 = STP_DSP
|
|---|
| 52 | * 0xff = CMD_END
|
|---|
| 53 | */
|
|---|
| 54 | /* pad to size 0x800 with byte value 0xff */
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | #define FRAGMENT_SIZE 0x05c
|
|---|
| 58 | #define SPDSZ 0x053
|
|---|
| 59 | #define FRAGMENT_SIZE_OFFSET 0x012 /* 2 bytes, big-endian (most significant byte first) */
|
|---|
| 60 | #define SPDSZ_OFFSET 0x01d /* 2 bytes, big-endian (most significant byte first) */
|
|---|
| 61 | #define PAD_OFFSET 0x070
|
|---|
| 62 | #define PAD_SIZE 0x790
|
|---|
| 63 |
|
|---|
| 64 | int
|
|---|
| 65 | write_file(
|
|---|
| 66 | const char* name,
|
|---|
| 67 | const void *data,
|
|---|
| 68 | size_t size) {
|
|---|
| 69 |
|
|---|
| 70 | int result = -1;
|
|---|
| 71 | FILE* f = NULL;
|
|---|
| 72 |
|
|---|
| 73 | f = fopen(name, "w");
|
|---|
| 74 | if (f == NULL) {
|
|---|
| 75 | fprintf(stderr, "could not open file '%s'\n", name);
|
|---|
| 76 | goto cleanup;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | if (fwrite(data, size, 1, f) != 1) {
|
|---|
| 80 | fprintf(stderr, "could not write to file '%s'\n", name);
|
|---|
| 81 | goto cleanup;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | if (fclose(f) != 0) {
|
|---|
| 85 | fprintf(stderr, "could not close file '%s'\n", name);
|
|---|
| 86 | goto cleanup;
|
|---|
| 87 | }
|
|---|
| 88 | f = NULL;
|
|---|
| 89 |
|
|---|
| 90 | result = 0;
|
|---|
| 91 | cleanup:
|
|---|
| 92 | if (f) {
|
|---|
| 93 | fclose(f);
|
|---|
| 94 | }
|
|---|
| 95 | return result;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | int
|
|---|
| 99 | main(int argc, char**argv) {
|
|---|
| 100 | int result = 1;
|
|---|
| 101 | char* name = NULL;
|
|---|
| 102 |
|
|---|
| 103 | if (argc != 2) {
|
|---|
| 104 | fprintf(stderr, "Usage: %s NAME\n", argv[0]);
|
|---|
| 105 | return 1;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | memset(sub_data + PAD_OFFSET, 0xff, PAD_SIZE);
|
|---|
| 109 |
|
|---|
| 110 | name = malloc(strlen(argv[1]) + 80);
|
|---|
| 111 | if (name == NULL) {
|
|---|
| 112 | fprintf(stderr, "could not allocate memory for file name\n");
|
|---|
| 113 | goto cleanup;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | for (unsigned fragment_size = 0; fragment_size <= FRAGMENT_SIZE; fragment_size++) {
|
|---|
| 117 | const unsigned spdsz = (fragment_size >= (FRAGMENT_SIZE - SPDSZ)) ?
|
|---|
| 118 | (fragment_size - (FRAGMENT_SIZE - SPDSZ)) : 0;
|
|---|
| 119 |
|
|---|
| 120 | sub_data[FRAGMENT_SIZE_OFFSET + 0] = (unsigned char) ((fragment_size >> 8) & 0xFF);
|
|---|
| 121 | sub_data[FRAGMENT_SIZE_OFFSET + 1] = (unsigned char) (fragment_size & 0xFF);
|
|---|
| 122 |
|
|---|
| 123 | sub_data[SPDSZ_OFFSET + 0] = (unsigned char) ((spdsz >> 8) & 0xFF);
|
|---|
| 124 | sub_data[SPDSZ_OFFSET + 1] = (unsigned char) (spdsz & 0xFF);
|
|---|
| 125 |
|
|---|
| 126 | sprintf(name, "%s-%u%s", argv[1], fragment_size, ".idx");
|
|---|
| 127 | if (write_file(name, idx_data, sizeof(idx_data)) == -1) {
|
|---|
| 128 | goto cleanup;
|
|---|
| 129 | }
|
|---|
| 130 | sprintf(name, "%s-%u%s", argv[1], fragment_size, ".sub");
|
|---|
| 131 | if (write_file(name, sub_data, sizeof(sub_data)) == -1) {
|
|---|
| 132 | goto cleanup;
|
|---|
| 133 | }
|
|---|
| 134 | }
|
|---|
| 135 | result = 0;
|
|---|
| 136 |
|
|---|
| 137 | cleanup:
|
|---|
| 138 | if (name) {
|
|---|
| 139 | free(name);
|
|---|
| 140 | }
|
|---|
| 141 | return result;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|