From b9b1e849153d7f4c43c68332c0dc0a5692daeb2f Mon Sep 17 00:00:00 2001
From: ILW8 <daohengliu@gmail.com>
Date: Sat, 11 Jan 2025 03:29:49 +0000
Subject: [PATCH 1/3] add encoder override in config file

---
 config.json  |  3 ++-
 src/index.ts | 30 ++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/config.json b/config.json
index f255592..6b1d438 100644
--- a/config.json
+++ b/config.json
@@ -1,4 +1,5 @@
 {
 	"outputUrlTemplate": "srt://localhost:8890?streamid=publish:webcam_$slot&pkt_size=1316",
-	"ffmpegBin": "ffmpeg"
+	"ffmpegBin": "ffmpeg",
+	"encoderOverride": null
 }
diff --git a/src/index.ts b/src/index.ts
index e259dfb..a0b4d29 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,7 +3,11 @@ import { readFileSync } from 'fs';
 import { platform } from 'os';
 import * as prompt from 'prompts';
 
-const config: { outputUrlTemplate: string; ffmpegBin: string } = JSON.parse(readFileSync('./config.json').toString());
+const encoders = ['libx264', 'h264_nvenc', 'h264_amf', 'h264_qsv', 'h264_vaapi'] as const;
+type Encoder = typeof encoders[number];
+// type EncoderProperties = {encoder: Encoder, renderDevice: string | undefined, preset: string | undefined}
+
+const config: { outputUrlTemplate: string; ffmpegBin: string; encoderOverride: Encoder } = JSON.parse(readFileSync('./config.json').toString());
 
 function getCameras(): { device: string; displayName: string }[] {
     if (platform() === 'linux') {
@@ -259,7 +263,7 @@ function getArgs({ device, slot, encoder, renderDevice, preset }: { device: stri
         });
     }
 
-    const { device, slot, encoder } = await prompt([
+    const { device, slot } = await prompt([
         {
             name: 'device',
             type: 'select',
@@ -278,13 +282,27 @@ function getArgs({ device, slot, encoder, renderDevice, preset }: { device: stri
                 value: slot,
             })),
         },
-        {
-            name: 'encoder',
+        // {
+        //     name: 'encoder',
+        //     type: 'select',
+        //     message: 'Select encoder',
+        //     choices: encoders,
+        // },
+    ]);
+
+    let encoder: Encoder;
+    if (config.encoderOverride != undefined && config.encoderOverride.length > 0) {
+        console.log(`Using encoder '${config.encoderOverride}' from config file.`)
+        encoder = config.encoderOverride
+    } else {
+        const { selectedEncoder } = await prompt({
+            name: 'selectedEncoder',
             type: 'select',
             message: 'Select encoder',
             choices: encoders,
-        },
-    ]);
+        })
+        encoder = selectedEncoder;
+    }
 
     let renderDevice: string | undefined;
     if (encoder === 'h264_amf' || encoder === 'h264_vaapi') {
-- 
GitLab


From 95bc318905893bcd0bc8a4b3eaae48ebf926e6b7 Mon Sep 17 00:00:00 2001
From: ILW8 <daohengliu@gmail.com>
Date: Sat, 11 Jan 2025 03:49:37 +0000
Subject: [PATCH 2/3] add input video options overrides in config file

---
 config.json  |  5 ++++-
 src/index.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/config.json b/config.json
index 6b1d438..d3e8d2a 100644
--- a/config.json
+++ b/config.json
@@ -1,5 +1,8 @@
 {
 	"outputUrlTemplate": "srt://localhost:8890?streamid=publish:webcam_$slot&pkt_size=1316",
 	"ffmpegBin": "ffmpeg",
-	"encoderOverride": null
+	"encoderOverride": null,
+	"rtbufsize": null,
+	"inputVideoSize": null,
+	"inputFormat": null
 }
diff --git a/src/index.ts b/src/index.ts
index a0b4d29..8035224 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -5,9 +5,19 @@ import * as prompt from 'prompts';
 
 const encoders = ['libx264', 'h264_nvenc', 'h264_amf', 'h264_qsv', 'h264_vaapi'] as const;
 type Encoder = typeof encoders[number];
-// type EncoderProperties = {encoder: Encoder, renderDevice: string | undefined, preset: string | undefined}
 
-const config: { outputUrlTemplate: string; ffmpegBin: string; encoderOverride: Encoder } = JSON.parse(readFileSync('./config.json').toString());
+const config: {
+    outputUrlTemplate: string;
+    ffmpegBin: string;
+    encoderOverride: Encoder;
+
+    // setting the following to 'default' will make us use whatever ffmpeg does in the absence of the relevant flags
+    // setting these to null or leaving them out of the config file will use this program's defaults.
+
+    /// real-time buffer size. roughly 12M for 1080p60 is enough to hold just over 2 frames in buffer
+    rtbufsize: string | 'default' | undefined;
+    inputVideoSize: string | 'default' | undefined;
+    inputFormat: string | 'default' | undefined; } = JSON.parse(readFileSync('./config.json').toString());
 
 function getCameras(): { device: string; displayName: string }[] {
     if (platform() === 'linux') {
@@ -192,14 +202,49 @@ function getArgs({ device, slot, encoder, renderDevice, preset }: { device: stri
         args.push('-hwaccel_device', renderDevice);
     }
 
+    if (config.rtbufsize != null && config.rtbufsize !== 'default') {
+        args.push('-rtbufsize', config.rtbufsize);
+    }
+
     if (platform() === 'linux') {
-        args.push('-input_format', 'mjpeg', '-video_size', '1280x720', '-framerate', '30', '-i', device);
+        if (config.inputFormat !== 'default') {
+            if(config.inputFormat != null ) {
+                args.push('-input_format', config.inputFormat);
+            } else {
+                args.push('-input_format', 'mjpeg');
+            }
+        }
+
+        if (config.inputVideoSize !== 'default') {
+            if(config.inputVideoSize != null ) {
+                args.push('-video_size', config.inputVideoSize);
+            } else {
+                args.push('-video_size', '1280x720');
+            }
+        }
+
+        args.push('-framerate', '30', '-i', device);
 
         if (encoder === 'h264_vaapi') {
             args.push('-vf', 'format=nv12,hwupload');
         }
     } else if (platform() === 'win32') {
-        args.push('-f', 'dshow', '-video_size', '1280x720', '-vcodec', 'mjpeg', '-i', `video=${device}`);
+        args.push('-f', 'dshow');
+
+        if (config.inputFormat !== 'default') {
+            if(config.inputFormat != null )
+                args.push('-vcodec', config.inputFormat);
+            else
+                args.push('-vcodec', 'mjpeg');
+        }
+        if (config.inputVideoSize !== 'default') {
+            if(config.inputVideoSize != null )
+                args.push('-video_size', config.inputVideoSize);
+            else
+                args.push('-video_size', '1280x720');
+        }
+
+        args.push('-i', `video=${device}`);
     }
 
     args.push('-c:v', encoder, '-b:v', '2M', '-bufsize', '2M', '-maxrate', '2M', '-g', '60', '-an');
-- 
GitLab


From b58af1df10a47553a56bd85d4e395b851781c111 Mon Sep 17 00:00:00 2001
From: ILW8 <daohengliu@gmail.com>
Date: Sat, 11 Jan 2025 03:55:26 +0000
Subject: [PATCH 3/3] remove leftover commented out code

---
 src/index.ts | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/index.ts b/src/index.ts
index 8035224..32047a4 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -326,13 +326,7 @@ function getArgs({ device, slot, encoder, renderDevice, preset }: { device: stri
                 title: `${slot}`,
                 value: slot,
             })),
-        },
-        // {
-        //     name: 'encoder',
-        //     type: 'select',
-        //     message: 'Select encoder',
-        //     choices: encoders,
-        // },
+        }
     ]);
 
     let encoder: Encoder;
-- 
GitLab