Skip to content

Commit

Permalink
inject environment hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiosnik777 committed Jan 13, 2023
1 parent e2738bd commit 80fecaf
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 31 deletions.
17 changes: 9 additions & 8 deletions src/js/interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Interpolation {

//get trtexec path
function getTrtExecPath() {
return path.join(__dirname, '..', "/python/cudatoolkit/v11.8/bin//trtexec.exe");
return path.join(__dirname, '..', "/python/env/Library/bin/trtexec.exe");
}
let trtexec = getTrtExecPath();

Expand Down Expand Up @@ -131,7 +131,7 @@ class Interpolation {
}

var cainModel = document.getElementById('model-span').innerHTML == 'RVP - v1.0';
var onnx = cainModel ? path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/cain-rvpv1/rvpv1.onnx") : path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/cain-cvpv6/cvpv6.onnx");
var onnx = cainModel ? path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/cain-rvpv1/rvpv1.onnx") : path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/cain-cvpv6/cvpv6.onnx");

// get engine path
function getEnginePath() {
Expand Down Expand Up @@ -179,9 +179,9 @@ class Interpolation {

function getRifeOnnx() {
if (document.getElementById('rife-tta-check').checked) {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/rife-trt/rife46_ensembleTrue.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/rife-trt/rife46_ensembleTrue.onnx");
} else {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/rife-trt/rife46_ensembleFalse.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/rife-trt/rife46_ensembleFalse.onnx");
}
}
let rifeOnnx = getRifeOnnx();
Expand Down Expand Up @@ -367,7 +367,7 @@ class Interpolation {
if (document.getElementById('python-check').checked) {
return "vspipe"
} else {
return path.join(__dirname, '..', "\\python\\bin\\VSPipe.exe")
return path.join(__dirname, '..', "\\python\\env\\VSPipe.exe")
}
}
if (process.platform == "linux") {
Expand All @@ -379,7 +379,8 @@ class Interpolation {
}
let vspipe = pickVspipe();

let cudaToolkit = `set "CUDA_PATH"="${path.join(__dirname, '..', "\\python\\cudatoolkit\\")}"`;
// inject env hook
let inject_env = `${path.join(__dirname, '..', "\\python\\env\\condabin\\conda_hook.bat")} && ${path.join(__dirname, '..', "\\python\\env\\condabin\\conda_auto_activate.bat")}`

let tmpOutPath = path.join(cache, Date.now() + extension);
if (extension != ".mkv" && fse.existsSync(subsPath) == true) {
Expand All @@ -394,9 +395,9 @@ class Interpolation {
return new Promise(function (resolve) {
// if preview is enabled split out 2 streams from output
if (preview.checked == true) {
var cmd = `${cudaToolkit} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} "${tmpOutPath}" -f hls -hls_list_size 0 -hls_flags independent_segments -hls_time 0.5 -hls_segment_type mpegts -hls_segment_filename "${previewDataPath}" -preset veryfast -vf scale=960:-1 "${path.join(previewPath, '/master.m3u8')}"`;
var cmd = `${inject_env} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} "${tmpOutPath}" -f hls -hls_list_size 0 -hls_flags independent_segments -hls_time 0.5 -hls_segment_type mpegts -hls_segment_filename "${previewDataPath}" -preset veryfast -vf scale=960:-1 "${path.join(previewPath, '/master.m3u8')}"`;
} else {
var cmd = `${cudaToolkit} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} "${tmpOutPath}"`;
var cmd = `${inject_env} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} "${tmpOutPath}"`;
}
let term = spawn(cmd, [], {
shell: true,
Expand Down
22 changes: 12 additions & 10 deletions src/js/restoration.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ class Restoration {

//get trtexec path
function getTrtExecPath() {
return path.join(__dirname, '..', "/python/cudatoolkit/v11.8/bin//trtexec.exe");
return path.join(__dirname, '..', "/python/env/Library/bin/trtexec.exe");
}
let trtexec = getTrtExecPath();

//get onnx input path
function getOnnxPath() {
if (engine == 'Restoration - DPIR (TensorRT)' && model == 'Denoise') {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/dpir/dpir_denoise.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/dpir/dpir_denoise.onnx");
} else if (engine == 'Restoration - DPIR (TensorRT)' && model == 'Deblock') {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/dpir/dpir_deblock.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/dpir/dpir_deblock.onnx");
} else if (engine == 'Restoration - AnimeVideo (TensorRT)') {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
} else if (engine == 'Restoration - AnimeVideo (NCNN)') {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
}
}
var onnx = getOnnxPath();
Expand All @@ -133,7 +133,7 @@ class Restoration {
// get engine path
function getEnginePath() {
if (engine == 'Restoration - AnimeVideo (NCNN)') {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
} else {
return path.join(appDataPath, '/.enhancr/models/engine', path.parse(onnx).name + '-' + fp + '_' + shapeDimensionsMax + '.engine');
}
Expand Down Expand Up @@ -287,7 +287,7 @@ class Restoration {
if (document.getElementById('python-check').checked) {
return "vspipe"
} else {
return path.join(__dirname, '..', "\\python\\bin\\VSPipe.exe")
return path.join(__dirname, '..', "\\python\\env\\VSPipe.exe")
}
}
if (process.platform == "linux") {
Expand All @@ -312,8 +312,10 @@ class Restoration {
}
let height = getHeight();

let tmpOutPath = path.join(cache, Date.now() + extension);
// inject env hook
let inject_env = `${path.join(__dirname, '..', "\\python\\env\\condabin\\conda_hook.bat")} && ${path.join(__dirname, '..', "\\python\\env\\condabin\\conda_auto_activate.bat")}`

let tmpOutPath = path.join(cache, Date.now() + extension);
if (extension != ".mkv" && fse.existsSync(subsPath) == true) {
openModal(modal);
terminal.innerHTML += "\r\n[enhancr] Input video contains subtitles, but output container is not .mkv, cancelling.";
Expand All @@ -326,9 +328,9 @@ class Restoration {
return new Promise(function (resolve) {
// if preview is enabled split out 2 streams from output
if (preview.checked == true) {
var cmd = `"${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}" -f hls -hls_list_size 0 -hls_flags independent_segments -hls_time 0.5 -hls_segment_type mpegts -hls_segment_filename "${previewDataPath}" -preset veryfast -vf scale=960:-1 "${path.join(previewPath, '/master.m3u8')}"`;
var cmd = `${inject_env} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}" -f hls -hls_list_size 0 -hls_flags independent_segments -hls_time 0.5 -hls_segment_type mpegts -hls_segment_filename "${previewDataPath}" -preset veryfast -vf scale=960:-1 "${path.join(previewPath, '/master.m3u8')}"`;
} else {
var cmd = `"${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}"`;
var cmd = `${inject_env} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}"`;
}
let term = spawn(cmd, [], { shell: true, stdio: ['inherit', 'pipe', 'pipe'], windowsHide: true });
// merge stdout & stderr & write data to terminal
Expand Down
17 changes: 10 additions & 7 deletions src/js/upscaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ class Upscaling {

//get trtexec path
function getTrtExecPath() {
return path.join(__dirname, '..', "/python/cudatoolkit/v11.8/bin//trtexec.exe");
return path.join(__dirname, '..', "/python/env/Library/bin/trtexec.exe");
}
let trtexec = getTrtExecPath();

//get python path
function getPythonPath() {
return path.join(__dirname, '..', "/python/bin/python.exe");
return path.join(__dirname, '..', "/python/env/python.exe");
}
let python = getPythonPath();

Expand Down Expand Up @@ -146,7 +146,7 @@ class Upscaling {
//get onnx input path
function getOnnxPath() {
if (!(document.getElementById('custom-model-check').checked)) {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
} else {
terminal.innerHTML += '\r\n[enhancr] Using custom model: ' + customModel;
if (path.extname(customModel) == ".pth") {
Expand All @@ -170,7 +170,7 @@ class Upscaling {
function getEnginePath() {
if (engine == "Upscaling - RealESRGAN (NCNN)") {
if (!(document.getElementById('custom-model-check').checked)) {
return path.join(__dirname, '..', "/python/bin/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
return path.join(__dirname, '..', "/python/env/vapoursynth64/plugins/models/esrgan/animevideov3.onnx");
} else {
return path.join(appDataPath, '/.enhancr/models/RealESRGAN', document.getElementById('custom-model-text').innerHTML);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ class Upscaling {
if (document.getElementById('python-check').checked) {
return "vspipe"
} else {
return path.join(__dirname, '..', "\\python\\bin\\VSPipe.exe")
return path.join(__dirname, '..', "\\python\\env\\VSPipe.exe")
}
}
if (process.platform == "linux") {
Expand All @@ -338,6 +338,9 @@ class Upscaling {
}
let height = getHeight();

// inject env hook
let inject_env = `${path.join(__dirname, '..', "\\python\\env\\condabin\\conda_hook.bat")} && ${path.join(__dirname, '..', "\\python\\env\\condabin\\conda_auto_activate.bat")}`

let tmpOutPath = path.join(cache, Date.now() + extension);
if (extension != ".mkv" && fse.existsSync(subsPath) == true) {
openModal(modal);
Expand All @@ -351,9 +354,9 @@ class Upscaling {
return new Promise(function (resolve) {
// if preview is enabled split out 2 streams from output
if (preview.checked == true) {
var cmd = `"${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}" -f hls -hls_list_size 0 -hls_flags independent_segments -hls_time 0.5 -hls_segment_type mpegts -hls_segment_filename "${previewDataPath}" -preset veryfast -vf scale=960:-1 "${path.join(previewPath, '/master.m3u8')}"`;
var cmd = `${inject_env} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}" -f hls -hls_list_size 0 -hls_flags independent_segments -hls_time 0.5 -hls_segment_type mpegts -hls_segment_filename "${previewDataPath}" -preset veryfast -vf scale=960:-1 "${path.join(previewPath, '/master.m3u8')}"`;
} else {
var cmd = `"${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}"`;
var cmd = `${inject_env} && "${vspipe}" --arg "tmp=${path.join(cache, "tmp.json")}" -c y4m "${engine}" - -p | "${ffmpeg}" -y -loglevel error -i pipe: ${params} -s ${width}x${height} "${tmpOutPath}"`;
}
let term = spawn(cmd, [], { shell: true, stdio: ['inherit', 'pipe', 'pipe'], windowsHide: true });
// merge stdout & stderr & write data to terminal
Expand Down
2 changes: 0 additions & 2 deletions src/python/cudatoolkit/.gitignore

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/python/inference/cain_trt.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def execute(n: int, clip1: vs.VideoNode, clip2: vs.VideoNode) -> vs.VideoNode:
ToPadHeight = data['toPadHeight']

cwd = os.getcwd()
vsmlrt_path = os.path.join(cwd, '..', 'cudatoolkit', 'v11.8', 'vstrt.dll')
vsmlrt_path = os.path.join(cwd, '..', 'env', 'Library', 'vstrt.dll')
core.std.LoadPlugin(path=vsmlrt_path)

clip = core.lsmas.LWLibavSource(source=f"{video_path}", cache=0)
Expand Down
2 changes: 1 addition & 1 deletion src/python/inference/dpir.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
strengthParam = data['strength']

cwd = os.getcwd()
vsmlrt_path = os.path.join(cwd, '..', 'cudatoolkit', 'v11.8', 'vstrt.dll')
vsmlrt_path = os.path.join(cwd, '..', 'env', 'Library', 'vstrt.dll')
core.std.LoadPlugin(path=vsmlrt_path)

clip = core.lsmas.LWLibavSource(source=f"{video_path}", cache=0)
Expand Down
2 changes: 1 addition & 1 deletion src/python/inference/esrgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


cwd = os.getcwd()
vsmlrt_path = os.path.join(cwd, '..', 'cudatoolkit', 'v11.8', 'vstrt.dll')
vsmlrt_path = os.path.join(cwd, '..', 'env', 'Library', 'vstrt.dll')
core.std.LoadPlugin(path=vsmlrt_path)

clip = core.lsmas.LWLibavSource(source=f"{video_path}", cache=0)
Expand Down
2 changes: 1 addition & 1 deletion src/python/inference/rife_trt.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def rife_trt(
sensitivityValue = data['sensitivityValue']

cwd = os.getcwd()
vsmlrt_path = os.path.join(cwd, '..', 'cudatoolkit', 'v11.8', 'vstrt.dll')
vsmlrt_path = os.path.join(cwd, '..', 'env', 'Library', 'vstrt.dll')
core.std.LoadPlugin(path=vsmlrt_path)

clip = core.lsmas.LWLibavSource(source=f"{video_path}", cache=0)
Expand Down

0 comments on commit 80fecaf

Please sign in to comment.