-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-ndx.c
91 lines (79 loc) · 2.5 KB
/
build-ndx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (C) 2002 John Todd Larason <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdio.h>
#include <string.h>
#include "rtv.h"
#include "ndx.h"
#define GOP_START 0x000001b8
#define VIDEO_START 0x000001e0
#define AUDIO_START 0x000001c0
static void report(int recno, u64 video, u64 audio)
{
struct ndx_record r;
u64 block = video / 0x8000;
u16 video_offset = (u16)(video - (block * 0x8000));
u32 audio_offset = (u32)(audio - video);
r.flag_1 = 0;
r.commercial_flag = 0;
r.video_offset = video_offset;
r.unk_fe = 0xfe;
r.macrovision = 0;
r.macrovision_count = 0;
r.audio_offset = audio_offset;
r.unused1 = 0;
r.timestamp = (u64)(recno * 1000000000.0/2);
r.stream_position = block * 0x8000;
write_ndx_record(stdout, &r);
}
static void write_header(void)
{
struct ndx_record r;
memset(&r, 0, sizeof r);
r.flag_1 = 2;
r.commercial_flag = 2;
write_ndx_record(stdout, &r);
}
int main(int argc, char ** argv)
{
unsigned char buf[32768];
unsigned char * p;
size_t words_in_buf;
size_t cur_word;
u64 buf_start = 0;
u64 value;
u64 video_start = 0, gop = 0, audio_start = 0;
int recno = 0;
(void)argc;
(void)argv;
write_header();
while ((words_in_buf = fread(buf, 4, sizeof(buf)/4, stdin)) > 0) {
p = buf;
for (cur_word = 0; cur_word < words_in_buf; cur_word++) {
value = rtv_to_u32(&p);
if (value == VIDEO_START && !gop) {
video_start = buf_start + cur_word * 4;
}
if (value == GOP_START) {
gop = buf_start + cur_word * 4;
}
if (value == AUDIO_START && gop) {
audio_start = buf_start + cur_word * 4;
report(recno++, video_start, audio_start);
video_start = gop = audio_start = 0;
}
}
buf_start += sizeof(buf);
}
return 0;
}