-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranscodeconfig.cpp
More file actions
93 lines (71 loc) · 3.24 KB
/
Copy pathtranscodeconfig.cpp
File metadata and controls
93 lines (71 loc) · 3.24 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
#include "transcodeconfig.h"
std::vector<std::string> strsplit(std::string input, std::string delimiter) {
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
std::string token;
std::vector<std::string> res;
while ((pos_end = input.find(delimiter, pos_start)) != std::string::npos) {
token = input.substr (pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back (token);
}
res.push_back (input.substr (pos_start));
return res;
}
TranscodeConfig::TranscodeConfig() {
ffmpegThread = 0;
}
bool TranscodeConfig::createConfiguration(mINI::INIStructure ini) {
std::string audioCodecCopy = ini["audio"]["codec_copy"];
if (!audioCodecCopy.empty()) {
std::vector<std::string> audioCodecs = strsplit(audioCodecCopy, ",");
allowedAudioCodecs.insert(allowedAudioCodecs.end(), audioCodecs.begin(), audioCodecs.end());
}
std::string audioTranscodeStr = ini["audio"]["transcode"];
if (!audioTranscodeStr.empty() && !allowedAudioCodecs.empty()) {
std::vector<std::string> audioParameter = strsplit(audioTranscodeStr, " ");
audioTranscodeParameter.insert(audioTranscodeParameter.end(), audioParameter.begin(), audioParameter.end());
}
std::string videoCodecCopy = ini["video"]["codec_copy"];
if (!videoCodecCopy.empty()) {
std::vector<std::string> videoCodecs = strsplit(videoCodecCopy, ",");
allowedVideoCodecs.insert(allowedVideoCodecs.end(), videoCodecs.begin(), videoCodecs.end());
}
std::string videoTranscodeStr = ini["video"]["transcode"];
if (!videoTranscodeStr.empty() && !allowedVideoCodecs.empty()) {
std::vector<std::string> videoParameter = strsplit(videoTranscodeStr, " ");
videoTranscodeParameter.insert(videoTranscodeParameter.end(), videoParameter.begin(), videoParameter.end());
}
// some checks
if (videoTranscodeParameter.empty() || allowedVideoCodecs.empty()) {
videoTranscodeParameter.clear();
allowedVideoCodecs.clear();
}
if (audioTranscodeParameter.empty() || allowedAudioCodecs.empty()) {
audioTranscodeParameter.clear();
allowedAudioCodecs.clear();
}
std::string ffmpegThreadStr = ini["ffmpeg"]["threads"];
if (!ffmpegThreadStr.empty()) {
ffmpegThread = std::atoi(ffmpegThreadStr.c_str());
}
return true;
}
bool TranscodeConfig::isCopyAudio(std::string codec, std::string sample_rate) {
if (allowedAudioCodecs.empty()) {
return true;
}
return any_of(allowedAudioCodecs.begin(), allowedAudioCodecs.end(), [&](const std::string& elem) { return elem == codec; }) ||
any_of(allowedAudioCodecs.begin(), allowedAudioCodecs.end(), [&](const std::string& elem) { return elem == codec + "." + sample_rate; });
}
bool TranscodeConfig::isCopyVideo(std::string codec) {
if (allowedVideoCodecs.empty()) {
return true;
}
return any_of(allowedVideoCodecs.begin(), allowedVideoCodecs.end(), [&](const std::string& elem) { return elem == codec; });
}
std::vector<std::string> TranscodeConfig::getAudioTranscodeParameter() {
return audioTranscodeParameter;
}
std::vector<std::string> TranscodeConfig::getVideoTranscodeParameter() {
return videoTranscodeParameter;
}