-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo.h
More file actions
96 lines (84 loc) · 2.29 KB
/
video.h
File metadata and controls
96 lines (84 loc) · 2.29 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
#ifndef VIDEO_HEADER
#define VIDEO_HEADER
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iomanip>
#include <string>
#include <stdexcept>
#include <set>
#include <algorithm>
#include <thread>
#include <sstream>
struct Frame {
std::vector < unsigned char > pixels;
};
struct Video {
int64_t numFrames;
unsigned char channels;
unsigned char height;
unsigned char width;
std::vector < Frame > frames;
std::unique_ptr < std::ifstream > inputFile;
std::unique_ptr < std::ofstream > outputFile;
void checkBounds(const Frame &frame,
const int x,
const int y,
const int channel) {
if (x < 0 || x >= width ||
y < 0 || y >= height ||
channel < 0 || channel >= channels) {
throw std::out_of_range("Pixel coordinates or channel out of bounds.");
}
if (frame.pixels.size() != static_cast<size_t>(width * height * channels)) {
throw std::runtime_error("Frame pixel size mismatch.");
}
}
unsigned char getPixelValue(
const Frame &frame,
const int x,
const int y,
const int channel) {
checkBounds(frame, x, y, channel);
return frame.pixels[((y * width) + x) + ((height * width) * channel)];
}
int64_t getPixelPosition(
const Frame &frame,
const int x,
const int y,
const int channel) {
checkBounds(frame, x, y, channel);
return ((y * width) + x) + ((height * width) * channel);
}
void writePixel(
const unsigned char value,
Frame &frame,
const int x,
const int y,
const int channel) {
checkBounds(frame, x, y, channel);
frame.pixels[((y * width) + x) + ((height * width) * channel)] = value;
}
size_t getFrameSize() {
return (height) * width * channels;
}
size_t getHeaderOffset() {
return
(sizeof(numFrames) + sizeof(channels) + sizeof(height) + sizeof(width));
}
};
// Video Decoder Functions
bool readVideoFromFile(
Video & video,
const std::string & inputFilePath,
const std::string & optimisationFlag);
Frame readFrameFromFile(
Video & video,
const int64_t & frameIndex);
// Video Encoder Functions
bool setUpOutputStream(Video & video, const std::string & outputFilePath);
bool writeVideoToFile(Video & video);
bool writeHeaderToFile(Video & video);
bool writeFrameToFile(Video & video, const Frame & frame);
#endif