diff --git a/config.json b/config.json new file mode 100644 index 0000000..c6da316 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "listen_at": "rtmp://192.168.254.146/", + "bitrate": "7M", + "send_to": "https://127.0.0.1:5001/" +} diff --git a/main.cpp b/main.cpp index eae743f..8142423 100644 --- a/main.cpp +++ b/main.cpp @@ -1,23 +1,39 @@ #include +#include +#include #include "dbc.hpp" #define BUF_MAX 1024 * 10 using namespace fmt; +using namespace nlohmann; -const string TWITCH_BR="7M"; +FILE *run_ffmpeg(const string listen_at, const string bitrate, const string send_to) { + string ffmpeg_cmd = format("ffmpeg -listen 1 -i {} -bufsize 3000k -maxrate {} -flags +global_header -c:v libx264 -preset veryfast -tune zerolatency -g:v 60 -vb {} -c:a copy -f flv {}", + listen_at, bitrate, bitrate, send_to); -FILE *run_ffmpeg() { - string ffmpeg_cmd = format("ffmpeg -listen 1 -i rtmp://192.168.254.146/ -bufsize 3000k -maxrate $twitch_br -flags +global_header -c:v libx264 -preset veryfast -tune zerolatency -g:v 60 -vb $twitch_br -c:a copy -f flv $twitch"); + println("RUNNING: {}", ffmpeg_cmd); FILE *handle = popen(ffmpeg_cmd.c_str(), "r"); dbc::check(handle != nullptr, "failed to start ffmpeg"); return handle; } +json load_config(const string file_name) { + std::ifstream infile(file_name); + return json::parse(infile); +} + int main() { - FILE *handle = run_ffmpeg(); + FILE *handle = nullptr; char buffer[BUF_MAX]; char *res = nullptr; + json config = load_config("config.json"); + + const string listen_at = config["listen_at"].template get(); + const string bitrate = config["bitrate"].template get(); + const string send_to = config["send_to"].template get(); + + handle = run_ffmpeg(listen_at, bitrate, send_to); do { res = fgets(buffer, BUF_MAX, handle);