ffmpeg is now configured with a json file.

main
Zed A. Shaw 2 months ago
parent b7c3934771
commit 2f7facc853
  1. 5
      config.json
  2. 24
      main.cpp

@ -0,0 +1,5 @@
{
"listen_at": "rtmp://192.168.254.146/",
"bitrate": "7M",
"send_to": "https://127.0.0.1:5001/"
}

@ -1,23 +1,39 @@
#include <fmt/core.h> #include <fmt/core.h>
#include <nlohmann/json.hpp>
#include <fstream>
#include "dbc.hpp" #include "dbc.hpp"
#define BUF_MAX 1024 * 10 #define BUF_MAX 1024 * 10
using namespace fmt; 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() { println("RUNNING: {}", ffmpeg_cmd);
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");
FILE *handle = popen(ffmpeg_cmd.c_str(), "r"); FILE *handle = popen(ffmpeg_cmd.c_str(), "r");
dbc::check(handle != nullptr, "failed to start ffmpeg"); dbc::check(handle != nullptr, "failed to start ffmpeg");
return handle; return handle;
} }
json load_config(const string file_name) {
std::ifstream infile(file_name);
return json::parse(infile);
}
int main() { int main() {
FILE *handle = run_ffmpeg(); FILE *handle = nullptr;
char buffer[BUF_MAX]; char buffer[BUF_MAX];
char *res = nullptr; char *res = nullptr;
json config = load_config("config.json");
const string listen_at = config["listen_at"].template get<string>();
const string bitrate = config["bitrate"].template get<string>();
const string send_to = config["send_to"].template get<string>();
handle = run_ffmpeg(listen_at, bitrate, send_to);
do { do {
res = fgets(buffer, BUF_MAX, handle); res = fgets(buffer, BUF_MAX, handle);

Loading…
Cancel
Save