SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
jompegRecord.h
Go to the documentation of this file.
1#ifndef JOMPEGRECORD_H
2#define JOMPEGRECORD_H
3
4#include <stdio.h>
5#include <math.h>
6#include <iostream>
7
8#include <jo_mpeg.h>
9
10#include <record.h>
11
18class JompegRecord : public Record
19{
20public:
21
31 (
32 std::filesystem::path file,
33 glm::ivec2 resolution,
35 )
36 :
38 {
39 bool fpsOk = false;
40 for (const auto & option : {24, 25, 30, 50, 60})
41 {
42 if (fps == option)
43 {
44 fpsOk = true;
45 break;
46 }
47 }
48
49 if (!fpsOk)
50 {
51 uint8_t closest = 0;
52 for (const auto & option : {24, 25, 30, 50, 60})
53 {
54 if (std::abs(int(option)-int(fps)) < std::abs(int(closest)-int(fps)))
55 {
57 }
58 }
59 std::cout << "jo_mpeg recording only supports 24, 25, 30, 50, and 60 fps.\nSelected "+std::to_string(closest)+" fps.\n";
60 }
61 }
62
64
70 void open()
71 {
72 if (fileOpen) { return; }
73 fp = fopen(file.string().c_str(), "wb");
74 fileOpen = true;
75 }
76
82 void close()
83 {
84 if (!fileOpen) { return; }
85 fileOpen = false;
86 fclose(fp);
87 }
88
89private:
90
91 FILE * fp = nullptr;
92
93 void write(const uint8_t * frame)
94 {
95 jo_write_mpeg(fp, frame, resolution.x, resolution.y, fps);
96 }
97};
98
99#endif /* JOMPEGRECORD_H */
An jo_mpeg based Record.
Definition jompegRecord.h:19
JompegRecord(std::filesystem::path file, glm::ivec2 resolution, uint8_t fps)
Construct a new jo_mpeg based Record from a file path, resolution and fps.
Definition jompegRecord.h:31
~JompegRecord()
Definition jompegRecord.h:63
void close()
Close the video file.
Definition jompegRecord.h:82
void open()
Open the video file.
Definition jompegRecord.h:70
An API for recording video.
Definition record.h:15
uint8_t fps
Definition record.h:135
std::filesystem::path file
Definition record.h:133
glm::ivec2 resolution
Definition record.h:134
bool fileOpen
Definition record.h:136
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214