-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmain.cpp
72 lines (56 loc) · 1.26 KB
/
main.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
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include "FlvParser.h"
using namespace std;
void Process(fstream &fin, const char *filename);
int main(int argc, char *argv[])
{
cout << "Hi, this is FLV parser test program!\n";
if (argc != 3)
{
cout << "FlvParser.exe [input flv] [output flv]" << endl;
return 0;
}
fstream fin;
fin.open(argv[1], ios_base::in | ios_base::binary);
if (!fin)
return 0;
Process(fin, argv[2]);
fin.close();
return 1;
}
void Process(fstream &fin, const char *filename)
{
CFlvParser parser;
int nBufSize = 2000 * 1024;
int nFlvPos = 0;
unsigned char *pBuf, *pBak;
pBuf = new unsigned char[nBufSize];
pBak = new unsigned char[nBufSize];
while (1)
{
int nReadNum = 0;
int nUsedLen = 0;
fin.read((char *)pBuf + nFlvPos, nBufSize - nFlvPos);
nReadNum = fin.gcount();
if (nReadNum == 0)
break;
nFlvPos += nReadNum;
parser.Parse(pBuf, nFlvPos, nUsedLen);
if (nFlvPos != nUsedLen)
{
memcpy(pBak, pBuf + nUsedLen, nFlvPos - nUsedLen);
memcpy(pBuf, pBak, nFlvPos - nUsedLen);
}
nFlvPos -= nUsedLen;
}
//parser.PrintInfo();
//parser.DumpH264("parser.264");
//parser.DumpAAC("parser.aac");
//dump into flv
parser.DumpFlv(filename);
delete []pBak;
delete []pBuf;
}