Skip to content

Commit

Permalink
add shims for non-standard paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Nov 1, 2022
1 parent 2b78048 commit 95e526b
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions encoder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local self = {
------------------------------------------------------------
-- utility functions

local pad_timings = function(padding, start_time, end_time)
local function pad_timings(padding, start_time, end_time)
local video_duration = mp.get_property_number('duration')
start_time = start_time - padding
end_time = end_time + padding
Expand All @@ -39,12 +39,32 @@ local pad_timings = function(padding, start_time, end_time)
return start_time, end_time
end

local function alt_path_dirs()
return {
'/opt/homebrew/bin',
'/usr/local/bin',
utils.join_path(os.getenv("HOME") or "~", '.local/bin'),
}
end

local function find_exec(name)
local path, info
for _, alt_dir in pairs(alt_path_dirs()) do
path = utils.join_path(alt_dir, name)
info = utils.file_info(path)
if info and info.is_file then
return path
end
end
return name
end

------------------------------------------------------------
-- ffmpeg encoder

local ffmpeg = {}

ffmpeg.prefix = { "ffmpeg", "-hide_banner", "-nostdin", "-y", "-loglevel", "quiet", "-sn", }
ffmpeg.prefix = { find_exec("ffmpeg"), "-hide_banner", "-nostdin", "-y", "-loglevel", "quiet", "-sn", }

ffmpeg.prepend = function(args)
if next(args) ~= nil then
Expand Down Expand Up @@ -132,7 +152,7 @@ local mpv = {}

mpv.make_static_snapshot_args = function(source_path, output_path, timestamp)
return {
'mpv',
find_exec("mpv"),
source_path,
'--loop-file=no',
'--audio=no',
Expand All @@ -151,7 +171,7 @@ end

mpv.make_animated_snapshot_args = function(source_path, output_path, start_timestamp, end_timestamp)
return {
'mpv',
find_exec("mpv"),
source_path,
'--loop-file=no',
'--ovc=libwebp',
Expand Down Expand Up @@ -181,7 +201,7 @@ mpv.make_audio_args = function(source_path, output_path, start_timestamp, end_ti
end

return {
'mpv',
find_exec("mpv"),
source_path,
'--loop-file=no',
'--video=no',
Expand Down Expand Up @@ -245,7 +265,7 @@ end

local background_play = function(file_path, on_finish)
return h.subprocess(
{ 'mpv', '--audio-display=no', '--force-window=no', '--keep-open=no', '--really-quiet', file_path },
{ find_exec("mpv"), '--audio-display=no', '--force-window=no', '--keep-open=no', '--really-quiet', file_path },
on_finish
)
end
Expand Down

0 comments on commit 95e526b

Please sign in to comment.