remove windows add restart after save, desktop notifs

This commit is contained in:
creations 2025-06-01 11:46:58 -04:00
parent 41e6c88a78
commit 60d95372cb
Signed by: creations
GPG key ID: 8F553AA4320FC711
2 changed files with 33 additions and 41 deletions

View file

@ -5,6 +5,8 @@ local remux_format_prop_key = "remux_format"
local input_format_prop_key = "input_format"
local delete_original_prop_key = "delete_original"
local ffmpeg_path_prop_key = "ffmpeg_path"
local desktop_notify_prop_key = "desktop_notify"
local restart_replay_prop_key = "restart_replay_buffer"
local REPLAY_EVENT = 0
local RECORDING_EVENT = 1
@ -14,6 +16,8 @@ local remux_format = "mp4"
local input_format = "mkv"
local delete_original = false
local ffmpeg_path = "ffmpeg"
local desktop_notify = false
local restart_replay_buffer = false
function script_description()
return [[
@ -42,6 +46,8 @@ function script_properties()
obslua.obs_properties_add_path(prop, ffmpeg_path_prop_key, "FFmpeg Path:", obslua.OBS_PATH_FILE, nil, nil)
obslua.obs_properties_add_bool(prop, remux_enabled_prop_key, "Enable Remuxing")
obslua.obs_properties_add_bool(prop, delete_original_prop_key, "Delete Original After Remux")
obslua.obs_properties_add_bool(prop, desktop_notify_prop_key, "Enable Desktop Notifications")
obslua.obs_properties_add_bool(prop, restart_replay_prop_key, "Restart Replay Buffer After Save")
local input_format_list = obslua.obs_properties_add_list(
prop, input_format_prop_key, "Input Format", obslua.OBS_COMBO_TYPE_EDITABLE, obslua.OBS_COMBO_FORMAT_STRING
@ -71,14 +77,10 @@ function script_update(settings)
ffmpeg_path = obslua.obs_data_get_string(settings, ffmpeg_path_prop_key)
input_format = obslua.obs_data_get_string(settings, input_format_prop_key)
remux_format = obslua.obs_data_get_string(settings, remux_format_prop_key)
desktop_notify = obslua.obs_data_get_bool(settings, desktop_notify_prop_key)
restart_replay_buffer = obslua.obs_data_get_bool(settings, restart_replay_prop_key)
if ffmpeg_path == "" then ffmpeg_path = "ffmpeg" end
print("Updated output path:", output_path)
print("Remux Enabled:", remux_enabled)
print("Input Format:", input_format)
print("Remux To:", remux_format)
print("Delete Original After Remux:", delete_original)
print("FFmpeg Path:", ffmpeg_path)
end
function script_defaults(settings)
@ -88,6 +90,14 @@ function script_defaults(settings)
obslua.obs_data_set_default_string(settings, remux_format_prop_key, "mp4")
obslua.obs_data_set_default_bool(settings, delete_original_prop_key, false)
obslua.obs_data_set_default_string(settings, ffmpeg_path_prop_key, "ffmpeg")
obslua.obs_data_set_default_bool(settings, desktop_notify_prop_key, false)
obslua.obs_data_set_default_bool(settings, restart_replay_prop_key, false)
end
function notify_desktop(message)
if desktop_notify then
os.execute(('notify-send "OBSReplay" "%s"'):format(message))
end
end
function save(event)
@ -99,29 +109,18 @@ function save(event)
local current_scene_name = get_current_scene_name()
local scene_folder_path = output_path .. "/" .. current_scene_name
if package.config:sub(1, 1) == "\\" then
os.execute(('powershell -Command "if (!(Test-Path \\"%s\\")) { New-Item -ItemType Directory -Path \\"%s\\" }"')
:format(scene_folder_path, scene_folder_path))
else
os.execute(('mkdir -p "%s"'):format(scene_folder_path))
end
os.execute(('mkdir -p "%s"'):format(scene_folder_path))
local file_name = latest_file_path:match("([^/\\]+)$")
local moved_file_path = scene_folder_path .. "/" .. file_name
local move_command
if package.config:sub(1, 1) == "\\" then
move_command = ('powershell -Command "Move-Item -Path \\"%s\\" -Destination \\"%s\\" -Force"')
:format(latest_file_path, moved_file_path)
else
move_command = ('mv "%s" "%s"'):format(latest_file_path, moved_file_path)
end
print("Moving file:", move_command)
local move_command = ('mv "%s" "%s"'):format(latest_file_path, moved_file_path)
os.execute(move_command)
notify_desktop("Moved file to scene folder.")
local file_exists = io.open(moved_file_path, "r")
if not file_exists then
print("Error: Moved file does not exist, remuxing skipped.")
notify_desktop("Move failed: file not found.")
return
else
file_exists:close()
@ -129,7 +128,7 @@ function save(event)
local base_name, ext = file_name:match("(.+)%.([^.]+)$")
if not base_name or not ext then
print("Error: Could not extract base name and extension from '" .. file_name .. "'")
notify_desktop("Remux failed: invalid file name.")
return
end
@ -138,41 +137,36 @@ function save(event)
if remux_enabled and ext == normalized_input_format then
local new_file_path = scene_folder_path .. "/" .. base_name .. "." .. remux_format:lower()
local remux_command = ('%s -y -i "%s" -c:v copy -c:a copy "%s" 2>&1')
:format(ffmpeg_path, moved_file_path, new_file_path)
print("Executing remux command:", remux_command)
local handle = io.popen(remux_command, "r")
local result = handle:read("*a")
handle:close()
print("FFmpeg output:", result)
local remuxed_file_exists = io.open(new_file_path, "r")
if not remuxed_file_exists then
print("Error: Remuxing failed, original file will not be deleted.")
notify_desktop("Remux failed: check FFmpeg.")
return
else
remuxed_file_exists:close()
notify_desktop("Remuxed to " .. remux_format:upper() .. " successfully.")
end
if delete_original then
local delete_command
if package.config:sub(1, 1) == "\\" then
delete_command = ('powershell -Command "Remove-Item -Path \\"%s\\" -Force"'):format(moved_file_path)
else
delete_command = ('rm "%s"'):format(moved_file_path)
end
print("Deleting original:", delete_command)
local delete_command = ('rm "%s"'):format(moved_file_path)
os.execute(delete_command)
notify_desktop("Original file deleted after remux.")
end
else
print("Remuxing skipped: File format '" .. ext .. "' does not match selected input format '" .. normalized_input_format .. "'")
elseif remux_enabled and ext ~= normalized_input_format then
notify_desktop("Remux skipped format mismatch")
end
if re1_replay_buffer and event == REPLAY_EVENT then
obslua.obs_frontend_replay_buffer_start()
end
else
print("No file found to move.")
notify_desktop("No file found to move.")
end
end

View file

@ -1,7 +1,5 @@
# OBSReplay
**Works on linux and windows but windows hasnt been tested all that well**
A lightweight OBS script that automatically organizes recordings, replays, and screenshots into folders named after the current scene.
## Features
@ -31,4 +29,4 @@ A lightweight OBS script that automatically organizes recordings, replays, and s
## License
MIT License
![Code Stats](https://wakapi.creations.works/api/badge/creations/interval:alltime/project:OBSReplay)
![Code Stats](https://wakapi.creations.works/api/badge/creations/interval:alltime/project:OBSReplay)