-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mp4.c
More file actions
executable file
·169 lines (138 loc) · 4.61 KB
/
test_mp4.c
File metadata and controls
executable file
·169 lines (138 loc) · 4.61 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* =====================================================================================
*
* Filename: main.c
*
* Description:
*
* Version: 1.0
* Created: 2016年05月04日 10时45分09秒
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24))
#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))
typedef struct _tag_mp4box_
{
union size_byte
{
int size;
char byte[4];
};
int type;
}mp4box;
int check_box_type_has_child(char *type)
{
if ((type[0] == 'm') &&
(type[1] == 'o') &&
(type[2] == 'o') &&
(type[3] == 'f'))
return 1;
else if
((type[0] == 't') &&
(type[1] == 'r') &&
(type[2] == 'a') &&
(type[3] == 'f'))
return 1;
else if
((type[0] == 'm') &&
(type[1] == 'o') &&
(type[2] == 'o') &&
(type[3] == 'v'))
return 1;
else
return 0;
}
static int box_depth = 0;
static char buf[1024];
int read_mov_box(FILE *f)
{
int size_tmp, size, i;
char type[4];
if (4 != fread(&size_tmp, sizeof(char), 4, f))
return -1;
if (4 != fread(type, sizeof(char), 4, f))
return -1;
size = 0;
size = (size_tmp&0xFF)<<24 | (size_tmp&0xFF00)<<8 | (size_tmp&0xFF0000)>>8 | (size_tmp&0xFF000000)>>24;
for (i = 0; i < box_depth; i++)
printf("\t");
printf("type %c%c%c%c\tsize %d\n", type[0], type[1], type[2], type[3], size);
if (check_box_type_has_child(type))
{
box_depth ++;
printf("+++");
read_mov_box(f);
box_depth --;
}
else
{
if ((type[0] == 'm') && (type[1] == 'v') && (type[2] == 'h') && (type[3] == 'd')) {
//read full box
char version;
fread(&version, sizeof(char), 1, f); printf("version %d\n", (int)version);
fread(buf, sizeof(char), 3, f); printf("flag %d, %d, %d\n", buf[0], buf[1], buf[2]);
if (version==1) {
fread(buf, sizeof(char), 8, f);
printf("create time %d,%d,%d,%d,%d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]);
fread(buf, sizeof(char), 8, f);
printf("modification time %d,%d,%d,%d,%d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]);
fread(buf, sizeof(char), 4, f);
printf("time scale %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
fread(buf, sizeof(char), 8, f);
printf("duration %d,%d,%d,%d,%d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]);
} else {
fread(buf, sizeof(char), 4, f);
printf("create time %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
fread(buf, sizeof(char), 4, f);
printf("modification time %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
fread(buf, sizeof(char), 4, f);
printf("time scale %x,%x,%x,%x\n", buf[0],buf[1],buf[2],buf[3]);
fread(buf, sizeof(char), 4, f);
printf("duration %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
}
fread(buf, sizeof(char), 4, f);
printf("rate %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
fread(buf, sizeof(char), 2, f);
printf("volume %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
fread(buf, sizeof(char), 10, f);
for (int i = 0; i < 9; i++) {
fread(buf, sizeof(char), 4, f);
printf("matrix[%d] %d,%d,%d,%d\n", i, buf[0],buf[1],buf[2],buf[3]);
}
for (int i = 0; i < 6; i++) {
fread(buf, sizeof(char), 4, f);
printf("pre def[%d] %d,%d,%d,%d\n", i, buf[0],buf[1],buf[2],buf[3]);
}
fread(buf, sizeof(char), 4, f);
printf("next track id %d,%d,%d,%d\n", buf[0],buf[1],buf[2],buf[3]);
}
else {
fseek(f, size - 8, SEEK_CUR);//minus type&size
}
return 0;
}
}
int main (int argc, char *argv[])
{
unsigned int size, size_tmp, type;
FILE *f = fopen(argv[1], "rb");
if (!f)
{
printf("file open failed!\n");
}
while (1)
{
if (read_mov_box(f) < 0)
break;
}
if (f)
fclose(f);
}