-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mp4File.cpp
81 lines (66 loc) · 1.77 KB
/
Mp4File.cpp
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
/**
*
* author Jose Mortensen
* brief Iso Mp4 Box parser
*
*/
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <ctime>
#include <algorithm>
#include "Mp4File.h"
#include "Mp4FileImpl.h"
#include "Mp4Boxes.h"
#include "MediaInformationBoxes.h"
#include "Mp4SampleBoxes.h"
const Mp4File::TrackType Mp4File::MP4FILE_VIDEO = "vmhd";
const Mp4File::TrackType Mp4File::MP4FILE_SOUND = "smhd";
const Mp4File::TrackType Mp4File::MP4FILE_META = "mdhd";
const Mp4File::TrackType Mp4File::MP4FILE_AMF0 = "amf0";
const Mp4File::TrackType Mp4File::MP4FILE_ANY = "";
Mp4File& Mp4File::create() {
Mp4File* file = new Mp4FileImpl();
return *file;
}
void Mp4File::destroy(Mp4File& mp4file)
{
delete &mp4file;
}
bool Mp4File::isMp4File(const char* filename)
{
bool ret = false;
LargeIfstream file(filename);
if (file.bad())
throw std::runtime_error("Bad File");
while (true) {
// read box header
uint32_t _size = Box::read32(file);
uint64_t _largesize = _size;
int _consumed = 8; // size + type
if (file.eof()) return false;
if (_size == 1) {
_largesize = Box::read64(file);
_consumed += 8;
} else if (_size == 0)
throw std::runtime_error ("Box not supported");
// create box based on header
char type[5] = {0,0,0,0,0};
file.read((char*)type, 4);
if (file.eof()) return false;
if (strncmp(type, "ftyp", 4) == 0) {
Ftyp ftyp;
ftyp.sizexx = _size;
ftyp.largesize = _largesize;
ftyp.consumed = _consumed;
ftyp.read(file);
//std::cout << "Found Box: " << ftyp << std::endl;
return true;
} else {
// skip box;
//std::cout << "Found Box: " << type << std::endl;
file.seekg(_largesize-_consumed, std::ios_base::cur);
}
}
return false;
}