-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo_encode.cpp
More file actions
63 lines (53 loc) · 1.5 KB
/
video_encode.cpp
File metadata and controls
63 lines (53 loc) · 1.5 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
#include "vlc.hpp"
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
using namespace vlc;
vector<unsigned short> load16bitraw(string fname, int w, int h) {
vector<unsigned short> res;
vector<unsigned short> frame(w*h);
ifstream f(fname, ios::binary);
f.read((char*)(&frame[0]),8); //header
f.read((char*)(&frame[0]),w*h*2);
while (f.good()) {
for (unsigned short a : frame) {
res.push_back(a);
}
f.read((char*)(&frame[0]),w*h*2);
}
return res;
}
int main(int argc, char*argv[]) {
string fname;
if (argc == 2) {
fname = argv[1];
} else {
cerr << "batch mode not implemented yet";
}
map<int, int> hist;
vector<unsigned short> v = load16bitraw(fname, 320, 100);
vector<int> raw;
for (int i=320*100;i<v.size();i++) {
int sample = (int(v[i])-int(v[i-320*100]));
raw.push_back(sample);
hist[sample]++;
}
cout << raw.size() << " samples read, " << raw.size()*2 << " bytes input"<< endl;
vlc::NumericSemiBlockCode<8> nbc;
vlc::chunk c;
nbc.encode(raw, c);
cout <<"Semiblockcode: "<< c.get_size_bits()/8+1<< endl;
ofstream f("hist.txt");
for (pair<int, int> a : hist) {
f <<a.first << " "<< a.second << endl;
}
HuffmanCode hc;
hc.build(raw);
chunk c2;
hc.encode(raw,c2);
cout <<"Huffman: " << c2.get_size_bits()/8+1<< endl;
c.save_file("semiblock.data");
c2.save_file("huffman.data");
return 0;
}