From 2bbc7df77ee930d58916584499c63a8779cc7896 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Sun, 28 Aug 2022 11:00:55 +0800 Subject: [PATCH] refactor: extract virtcam cache_dir as constant --- gui/virtcam/httpserver.lua | 2 +- gui/virtcam/virtcam.lua | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gui/virtcam/httpserver.lua b/gui/virtcam/httpserver.lua index 95c2697..06fc437 100644 --- a/gui/virtcam/httpserver.lua +++ b/gui/virtcam/httpserver.lua @@ -10,7 +10,7 @@ local http_server = require "http.server" local http_headers = require "http.headers" local json = require "JSON" -function NewHttpServer(host, port, handlers) +local function NewHttpServer(host, port, handlers) local function reply(myserver, stream) -- luacheck: ignore 212 -- Read in headers local req_headers = assert(stream:get_headers()) diff --git a/gui/virtcam/virtcam.lua b/gui/virtcam/virtcam.lua index 6f3288a..5aa4415 100644 --- a/gui/virtcam/virtcam.lua +++ b/gui/virtcam/virtcam.lua @@ -1,4 +1,5 @@ local httpserver = require "httpserver" +local CACHE_DIR = "~/Videos/virtcam" local function run(cmd) print(cmd) @@ -9,6 +10,7 @@ end run("sudo modprobe v4l2loopback -r -f") run("sudo modprobe v4l2loopback video_nr=21 card_label=virtcam exclusive_caps=1") +run("mkdir -p " .. CACHE_DIR) Ffmpeg = { cmd = "", proc = nil, name = "", started = false } @@ -45,12 +47,13 @@ Actualcam = Ffmpeg:new { Recorder = Ffmpeg:new { name = "recorder", - cmd = "ffmpeg -y -i /dev/video21 ~/Video/seq.mp4", + cmd = "ffmpeg -y -i /dev/video21 " .. CACHE_DIR .. "/seq.mp4", } Looper = Ffmpeg:new { name = "looper", - cmd = "ffmpeg -re -stream_loop -1 -i ~/Video/loop.mp4 -f v4l2 -vcodec rawvideo -pix_fmt yuyv422 -framerate 30 /dev/video21 ", + cmd = "ffmpeg -re -stream_loop -1 -i " .. + CACHE_DIR .. "/loop.mp4 -f v4l2 -vcodec rawvideo -pix_fmt yuyv422 -framerate 30 /dev/video21 ", } @@ -70,7 +73,7 @@ end local stage = "stopped" -NewHttpServer("127.0.0.1", 10200, { +httpserver.NewHttpServer("127.0.0.1", 10200, { ["POST /prepare"] = function(_, _) if stage == "stopped" then -- run("pactl set-source-mute @DEFAULT_SOURCE@ 1") @@ -92,8 +95,12 @@ NewHttpServer("127.0.0.1", 10200, { Recorder:start() run("sleep 3") Recorder:stop() - run("ffmpeg -y -i ~/Video/seq.mp4 -vf reverse ~/Video/reversed.mp4") - run("ffmpeg -y -i ~/Video/seq.mp4 -i ~/Video/reversed.mp4 -filter_complex '[0:v] [1:v] concat=n=2:v=1 [v]' -map '[v]' ~/Video/loop.mp4") + run("ffmpeg -y -i " .. CACHE_DIR .. "/seq.mp4 -vf reverse " .. CACHE_DIR .. "/reversed.mp4") + run("ffmpeg -y -i " .. + CACHE_DIR .. + "/seq.mp4 -i " .. + CACHE_DIR .. + "/reversed.mp4 -filter_complex '[0:v] [1:v] concat=n=2:v=1 [v]' -map '[v]' " .. CACHE_DIR .. "/loop.mp4") run_only(Looper) stage = "fake" end