-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
249 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
opencv | ||
ffmpeg | ||
cmake | ||
spdlog | ||
]; | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
#include "FFmpeg.hpp" | ||
#include "Sources/VideoSource.hpp" | ||
#include <unordered_map> | ||
|
||
namespace Hyperwall { | ||
|
||
class HyperFrame { | ||
const int x; | ||
const int y; | ||
const int X; | ||
const int Y; | ||
const int RES_X; | ||
const int RES_Y; | ||
const FFmpeg ffmpeg; | ||
const int x; | ||
const int y; | ||
const int X; | ||
const int Y; | ||
const int RES_X; | ||
const int RES_Y; | ||
const FFmpeg ffmpeg; | ||
public: | ||
HyperFrame(const HyperFrame&); | ||
HyperFrame(const int, const int, std::unordered_map<std::string, std::string>, const FFmpeg&); | ||
void run(const cv::Mat&); | ||
HyperFrame(const HyperFrame&); | ||
HyperFrame(const int, const int, std::unordered_map<std::string, std::string>, const FFmpeg&); | ||
void run(const cv::Mat&); | ||
}; | ||
|
||
class Hyperwall { | ||
std::unique_ptr<VideoSourceT> source; | ||
const int X; | ||
const int Y; | ||
std::unordered_map<int, std::unordered_map<int, HyperFrame>> frames; | ||
std::unique_ptr<VideoSourceT> source; | ||
std::unordered_map<int, std::unordered_map<int, HyperFrame>> frames; | ||
const int X; | ||
const int Y; | ||
public: | ||
Hyperwall(VideoSourceT&, std::unordered_map<std::string, std::string>); | ||
void run(); | ||
Hyperwall(VideoSourceT&, std::unordered_map<std::string, std::string>); | ||
void run(); | ||
}; | ||
|
||
} // Hyperwall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
#pragma once | ||
|
||
#include "Sources/VideoSource.hpp" | ||
#include <opencv2/videoio.hpp> | ||
|
||
namespace Hyperwall { | ||
|
||
class FileSource : public VideoSourceT { | ||
cv::VideoCapture capture; | ||
cv::VideoCapture capture; | ||
|
||
public: | ||
FileSource(std::string); | ||
virtual cv::Mat read() override; | ||
virtual std::unique_ptr<VideoSourceT> clone() const override; | ||
FileSource(std::string); | ||
virtual cv::Mat read() override; | ||
virtual std::unique_ptr<VideoSourceT> clone() const override; | ||
}; | ||
|
||
} // Hyperwall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#pragma once | ||
|
||
#include "Sources/VideoSource.hpp" | ||
|
||
namespace Hyperwall { | ||
|
||
class WebcamSource : public VideoSourceT { | ||
cv::VideoCapture capture; | ||
cv::VideoCapture capture; | ||
public: | ||
WebcamSource(const int); | ||
virtual cv::Mat read() override; | ||
virtual std::unique_ptr<VideoSourceT> clone() const override; | ||
WebcamSource(const int); | ||
virtual cv::Mat read() override; | ||
virtual std::unique_ptr<VideoSourceT> clone() const override; | ||
}; | ||
|
||
} // Hyperwall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
#include <vector> | ||
|
||
namespace Util { | ||
|
||
template<typename T = int> | ||
constexpr std::vector<T> range(const int n) { | ||
std::vector<T> values; | ||
for(auto i = 0; i < n; i++) | ||
values.push_back(i); | ||
return values; | ||
} | ||
|
||
template<typename T = int> | ||
constexpr std::vector<T> range(const int start, const int end) { | ||
std::vector<T> values; | ||
for(auto i = start; i < end; i++) | ||
values.push_back(i); | ||
return values; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,87 @@ | ||
#include <cstdlib> | ||
#include <opencv2/core/mat.hpp> | ||
#include <opencv2/opencv.hpp> | ||
#include <filesystem> | ||
#include <spdlog/common.h> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include <argparse/argparse.hpp> | ||
#include <opencv2/opencv.hpp> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include "Hyperwall.hpp" | ||
#include "Sources/FileSource.hpp" | ||
#include "Sources/WebcamSource.hpp" | ||
|
||
std::string split_res(std::string res, std::string direction) { | ||
if (direction == "x") { | ||
return res.substr(0, res.find("x")); | ||
} | ||
return res.substr(res.find("x")+1, res.size()); | ||
if (direction == "x") { | ||
return res.substr(0, res.find("x")); | ||
} | ||
return res.substr(res.find("x")+1, res.size()); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
argparse::ArgumentParser parser; | ||
parser.add_argument("--dimensions") | ||
.default_value("2x2"); | ||
parser.add_argument("--resolution") | ||
.default_value("1920x1080"); | ||
parser.add_argument("--framerate") | ||
.default_value("60"); | ||
parser.add_argument("--file") | ||
.default_value("file.mp4"); | ||
parser.add_argument("mode") | ||
.default_value("file"); | ||
auto loglevel = (int)spdlog::level::info; | ||
|
||
try { | ||
parser.parse_args(argc, argv); | ||
} catch(std::exception& e) { | ||
std::cerr << "fuck, exiting..." << std::endl; | ||
exit(EXIT_FAILURE); | ||
} | ||
argparse::ArgumentParser parser; | ||
parser.add_argument("--dimensions") | ||
.default_value("2x2"); | ||
parser.add_argument("--resolution") | ||
.default_value("1920x1080"); | ||
parser.add_argument("--framerate") | ||
.default_value("60"); | ||
parser.add_argument("--file") | ||
.default_value("file.mp4"); | ||
parser.add_argument("mode") | ||
.default_value("file"); | ||
parser.add_argument("-v") | ||
.action([&](const auto &){loglevel--;}) | ||
.append() | ||
.default_value(false) | ||
.implicit_value(true) | ||
.nargs(0); | ||
parser.add_argument("-q") | ||
.action([&](const auto &){loglevel++;}) | ||
.append() | ||
.default_value(false) | ||
.implicit_value(true) | ||
.nargs(0); | ||
|
||
std::unordered_map<std::string, std::string> settings({ | ||
{"RES_X", split_res(parser.get<std::string>("--resolution"), "x")}, | ||
{"RES_Y", split_res(parser.get<std::string>("--resolution"), "y")}, | ||
{"X", split_res(parser.get<std::string>("--dimensions"), "x")}, | ||
{"Y", split_res(parser.get<std::string>("--dimensions"), "y")}, | ||
{"FRAMERATE", parser.get<std::string>("--framerate")} | ||
}); | ||
Hyperwall::Hyperwall hyperwall = [&settings, &parser](std::string mode) { | ||
if(mode == "webcam") { | ||
Hyperwall::WebcamSource source(0); | ||
Hyperwall::Hyperwall hyperwall(source, settings); | ||
return hyperwall; | ||
try { | ||
parser.parse_args(argc, argv); | ||
} catch(std::exception& e) { | ||
spdlog::error("Failed to parse arguments, exiting!"); | ||
exit(EXIT_FAILURE); | ||
} | ||
else { | ||
Hyperwall::FileSource source(parser.get<std::string>("--file")); | ||
Hyperwall::Hyperwall hyperwall(source, settings); | ||
return hyperwall; | ||
spdlog::set_level(static_cast<spdlog::level::level_enum>(loglevel)); | ||
spdlog::info("Log level: {}", loglevel); | ||
spdlog::debug("Generating settings"); | ||
std::unordered_map<std::string, std::string> settings({ | ||
{"RES_X", split_res(parser.get<std::string>("--resolution"), "x")}, | ||
{"RES_Y", split_res(parser.get<std::string>("--resolution"), "y")}, | ||
{"X", split_res(parser.get<std::string>("--dimensions"), "x")}, | ||
{"Y", split_res(parser.get<std::string>("--dimensions"), "y")}, | ||
{"FRAMERATE", parser.get<std::string>("--framerate")} | ||
}); | ||
Hyperwall::Hyperwall hyperwall = [&settings, &parser](std::string mode) { | ||
spdlog::info("Chosen mode: {}", mode); | ||
if(mode == "webcam") { | ||
Hyperwall::WebcamSource source(0); | ||
Hyperwall::Hyperwall hyperwall(source, settings); | ||
return hyperwall; | ||
} | ||
else { | ||
auto filename = parser.get<std::string>("--file"); | ||
if(!std::filesystem::exists(std::filesystem::path(filename))){ | ||
spdlog::error("File: {} does not exist!", filename); | ||
exit(EXIT_FAILURE); | ||
} | ||
Hyperwall::FileSource source(filename); | ||
Hyperwall::Hyperwall hyperwall(source, settings); | ||
return hyperwall; | ||
} | ||
}(parser.get<std::string>("mode")); | ||
{ | ||
hyperwall.run(); | ||
} | ||
}(parser.get<std::string>("mode")); | ||
{ | ||
hyperwall.run(); | ||
} | ||
exit(EXIT_SUCCESS); | ||
exit(EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
#include "FFmpeg.hpp" | ||
#include <cstdio> | ||
#include <format> | ||
#include <opencv2/opencv.hpp> | ||
#include <spdlog/spdlog.h> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#include <opencv2/opencv.hpp> | ||
|
||
#include "FFmpeg.hpp" | ||
|
||
Hyperwall::FFmpegBuilder& Hyperwall::FFmpegBuilder::add(const std::string option) { | ||
options.push_back(option); | ||
return *this; | ||
options.push_back(option); | ||
spdlog::debug("Adding option: {}", option); | ||
return *this; | ||
} | ||
|
||
Hyperwall::FFmpegBuilder& Hyperwall::FFmpegBuilder::add(const std::string key, const std::string value) { | ||
options.push_back(std::format("{} {}", key, value)); | ||
return *this; | ||
options.push_back(std::format("{} {}", key, value)); | ||
spdlog::debug("Adding option: {} identified by: {}", value, key); | ||
return *this; | ||
} | ||
|
||
Hyperwall::FFmpegBuilder& Hyperwall::FFmpegBuilder::url(const std::string url) { | ||
this->_url = url; | ||
add(url); | ||
return *this; | ||
this->_url = url; | ||
add(url); | ||
return *this; | ||
} | ||
|
||
const Hyperwall::FFmpeg Hyperwall::FFmpegBuilder::build(std::string logname) { | ||
std::stringstream ss; | ||
ss << "ffmpeg "; | ||
for(auto option : options) { | ||
ss << option << " "; | ||
} | ||
ss << std::format(">> ./logs/stdout-{0} 2> ./logs/stderr-{0}", logname); | ||
return {ss.str(), _url}; | ||
std::stringstream ss; | ||
ss << "ffmpeg "; | ||
for(auto option : options) | ||
ss << option << " "; | ||
ss << std::format(">> ./logs/stdout-{0} 2> ./logs/stderr-{0}", logname); | ||
return {ss.str(), _url}; | ||
} | ||
|
||
Hyperwall::FFmpeg::FFmpeg(const std::string command, const std::string url) : url(url) { | ||
//std::cout << command << std::endl; | ||
buffer = popen(command.c_str(), "w"); | ||
buffer = popen(command.c_str(), "w"); | ||
} | ||
|
||
const void Hyperwall::FFmpeg::write(const cv::Mat& mat) const { | ||
//std::cout << url << std::endl; | ||
fwrite(mat.data, 1, mat.cols * mat.rows * 3, buffer); | ||
fflush(buffer); | ||
//std::cout << url << std::endl; | ||
fwrite(mat.data, 1, mat.cols * mat.rows * 3, buffer); | ||
fflush(buffer); | ||
} | ||
|
Oops, something went wrong.