-
Notifications
You must be signed in to change notification settings - Fork 45
/
vmaf_calculator.h
83 lines (69 loc) · 1.96 KB
/
vmaf_calculator.h
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
#pragma once
#include <iostream>
#include <stdexcept>
#include <string>
extern "C" {
#include <libavfilter/avfilter.h>
#include <libavutil/frame.h>
}
class VMAFCalculator {
private:
bool disabled_{false};
std::string libvmaf_options_;
public:
VMAFCalculator(const VMAFCalculator&) = delete;
VMAFCalculator& operator=(const VMAFCalculator&) = delete;
static VMAFCalculator& instance();
void set_libvmaf_options(const std::string& options);
std::string compute(const AVFrame* distorted_frame, const AVFrame* reference_frame);
private:
VMAFCalculator();
void run_libvmaf_filter(const AVFrame* distorted_frame, const AVFrame* reference_frame);
private:
class AVFilterGraphRAII {
public:
AVFilterGraphRAII() : graph_(avfilter_graph_alloc()) {
if (!graph_) {
throw std::runtime_error("Failed to allocate filter graph");
}
}
~AVFilterGraphRAII() { avfilter_graph_free(&graph_); }
AVFilterGraph* get() { return graph_; }
private:
AVFilterGraph* graph_;
};
class AVFilterInOutRAII {
public:
AVFilterInOutRAII(char* name, AVFilterContext* filter_ctx, AVFilterInOut* next, const bool root = true) : inout_(avfilter_inout_alloc()), root_(root) {
if (!inout_) {
throw std::runtime_error("Failed to allocate filter inout");
}
inout_->name = name;
inout_->pad_idx = 0;
inout_->filter_ctx = filter_ctx;
inout_->next = next;
}
~AVFilterInOutRAII() {
if (root_) {
avfilter_inout_free(&inout_);
}
}
AVFilterInOut** get_pointer() { return &inout_; }
AVFilterInOut* get() { return inout_; }
private:
AVFilterInOut* inout_;
bool root_;
};
class AVFrameRAII {
public:
AVFrameRAII() : frame_(av_frame_alloc()) {
if (!frame_) {
throw std::runtime_error("Failed to allocate frame");
}
}
~AVFrameRAII() { av_frame_free(&frame_); }
AVFrame* get() { return frame_; }
private:
AVFrame* frame_;
};
};