-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathavisynthwrapper.hpp
170 lines (146 loc) · 3.89 KB
/
avisynthwrapper.hpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef VFG_CORE_AVISYNTHWRAPPER_HPP
#define VFG_CORE_AVISYNTHWRAPPER_HPP
#include <cstddef>
#include <memory>
#include <stdexcept>
#include <string>
#include "avs_internal.c"
#include "ptrutil.hpp"
namespace vfg {
namespace avisynth {
/**
* @brief Avisynth exception error class
*/
struct AvisynthError : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
/**
* @brief Pixel formats as defined by Avisynth
*/
enum class PixelFormat : int {
Unknown = AVS_CS_UNKNOWN,
BGR24 = AVS_CS_BGR24,
BGR32 = AVS_CS_BGR32,
YUY2 = AVS_CS_YUY2,
RAW32 = AVS_CS_RAW32,
YV24 = AVS_CS_YV24,
YV16 = AVS_CS_YV16,
YV12 = AVS_CS_YV12,
I420 = AVS_CS_I420,
IYUV = AVS_CS_IYUV,
YV411 = AVS_CS_YV411,
YUV9 = AVS_CS_YUV9,
Y8 = AVS_CS_Y8
};
/**
* @brief VideoFrame represents a single frame in a video
*
* The class wraps AVS_VideoFrame and provides a few
* required member functions to copy it to another container
*/
class VideoFrame
{
public:
using DataReadPtr = const BYTE*;
using Deleter = decltype(avs_hnd_t::func.avs_release_video_frame);
private:
std::unique_ptr<AVS_VideoFrame, Deleter> videoFrame;
public:
VideoFrame(std::unique_ptr<AVS_VideoFrame, Deleter> frame);
/**
* @brief Check that the object contains valid data
* @return True if valid, otherwise false
*/
bool isValid() const;
/**
* @brief Get frame pitch (stride)
* @return Frame pitch
*/
int pitch() const;
/**
* @brief Get read-only data pointer to the frame data
* @return Read-only data pointer to the frame data
*/
DataReadPtr data() const;
};
/**
* @brief A wrapper for the Avisynth C-library
*/
class AvisynthWrapper
{
private:
avs_hnd_t avsHandle {};
vfg::observer_ptr<const AVS_VideoInfo> info {};
std::string openFilePath {};
public:
/**
* @brief Constructor
* @throws AvisynthError If fails to load avisynth dll
* @throws AvisynthError If fails to create script environment
*/
AvisynthWrapper();
~AvisynthWrapper();
/**
* @brief Load file from path
* @param path Path to file to load
* @throws AvisynthError If error occurs during script import
* @throws AvisynthError If imported script doesn't return clip
* @throws AvisynthError If import script doesn't return video data
*/
void load(const std::string& path);
/**
* @brief Get frame from video
* @pre 0 <= frameNum < numFrames()
* @param frameNum Frame number
* @throws AvisynthError If there is no video
* @throws AvisynthError If frameNum is out of range
* @throws AvisynthError If the C library returns an error
* when getting frame
* @return Captured frame
*/
VideoFrame getFrame(int frameNum) const;
/**
* @brief Check that video has been loaded successfully
* @return True if video is available, otherwise false
*/
bool hasVideo() const;
/**
* @brief Get number of frames in the loaded video
* @return Number of frames or 0 if no video
*/
int numFrames() const;
/**
* @brief Get pixel format for the loaded video
* @return Pixel format, Unknown if no video
*/
PixelFormat pixelFormat() const;
/**
* @brief Check if video is in RGB color format
* @return True if RGB, otherwise false
*/
bool isRGB() const;
/**
* @brief Check if video is in YUV color format
* @return True if YUV, otherwise false
*/
bool isYUV() const;
/**
* @brief Get video width
* @return Video width or 0
*/
int width() const;
/**
* @brief Get video height
* @return Video height or 0
*/
int height() const;
/**
* @brief Get opened filename
* @return Opened filename
*/
std::string fileName() const;
};
} // namespace avisynth
} // namespace vfg
#endif // VFG_CORE_AVISYNTHWRAPPER_HPP