-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideoEncoder.cpp
More file actions
64 lines (50 loc) · 1.96 KB
/
videoEncoder.cpp
File metadata and controls
64 lines (50 loc) · 1.96 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
#include "video.h"
using namespace std;
bool setUpOutputStream(Video & video, const string & outputFilePath) {
unique_ptr<ofstream> file = make_unique<ofstream>(outputFilePath,
ios::binary);
if (!file->is_open()) {
return false;
}
// Transfer ownership of the file stream to the Video object
video.outputFile = move(file);
return true;
}
bool writeHeaderToFile(Video & video) {
if (!video.outputFile || !video.outputFile->is_open()) {
cerr << "Error: Output file is not open." << endl;
return false;
}
video.outputFile->write(reinterpret_cast<const char *>(&video.numFrames),
sizeof(video.numFrames));
video.outputFile->write(reinterpret_cast<const char *>(&video.channels),
sizeof(video.channels));
video.outputFile->write(reinterpret_cast<const char *>(&video.height),
sizeof(video.height));
video.outputFile->write(reinterpret_cast<const char *>(&video.width),
sizeof(video.width));
return true;
}
bool writeVideoToFile(Video & video) {
if (!video.outputFile || !video.outputFile->is_open()) {
cerr << "Error: Output file is not open." << endl;
return false;
}
for (int frameIndex = 0; frameIndex < video.numFrames; frameIndex++) {
const Frame & currentFrame = video.frames[frameIndex];
const vector<unsigned char> & pixels = currentFrame.pixels;
video.outputFile->write(reinterpret_cast<const char *>(pixels.data()),
pixels.size());
}
return true;
}
bool writeFrameToFile(Video & video, const Frame & frame) {
if (!video.outputFile || !video.outputFile->is_open()) {
cerr << "Error: Output file is not open." << endl;
return false;
}
const vector<unsigned char> & pixels = frame.pixels;
video.outputFile->write(reinterpret_cast<const char *>(pixels.data()),
pixels.size());
return true;
}