Skip to content

Commit

Permalink
VMAF: Fix issues with json file names
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi311 committed Apr 27, 2024
1 parent 8c0f36e commit b3a4dc7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Scripts/Flow/Video/Video - VMAF.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Calculate vmaf score of working file compared to original file
* @author Luigi311
* @revision 1
* @revision 2
* @minimumVersion 1.0.0.0
* @param {int} n_threads Amount of threads to use for calculation, 0 for auto (non windows only)
* @param {string} json_file Json file containing vmaf information, empty for ${Flow.TempPath}/${file.NameNoExtension}.json
Expand Down Expand Up @@ -34,10 +34,9 @@ function Script(n_threads, json_file)
Logger.ILog(`Setting n_threads to ${n_threads}`);
}

if(!json_file || String(json_file).trim().length === 0) {
Logger.ILog(`Setting json_file to ${Flow.TempPath}/${Variables.file.NameNoExtension}.json`)
json_file = `${Flow.TempPath}/${Variables.file.NameNoExtension}.json`;
}
// Set the default json file to a random guid to avoid issues with file names
// and move it to the correct name at the end
let temp_json_file = `${Flow.TempPath}/${Flow.NewGuid()}.json`;

let ffmpeg = Flow.GetToolPath('ffmpeg');
let vmaf_process = Flow.Execute({
Expand All @@ -56,7 +55,7 @@ function Script(n_threads, json_file)
'-i',
Variables.file.Orig.FullName,
'-lavfi',
`libvmaf=n_threads=${n_threads}:log_fmt=json:log_path='${json_file}'`,
`libvmaf=n_threads=${n_threads}:log_fmt=json:log_path='${temp_json_file}'`,
'-f',
'null',
'-'
Expand Down Expand Up @@ -90,5 +89,12 @@ function Script(n_threads, json_file)
Logger.ILog("VMAF Score: " + vmaf);
Variables.VMAF = parseFloat(vmaf);

if(!json_file || String(json_file).trim().length === 0) {
Logger.ILog(`Setting json_file to ${Flow.TempPath}/${Variables.file.NameNoExtension}.json`)
json_file = `${Flow.TempPath}/${Variables.file.NameNoExtension}.json`;
}

System.IO.File.Move(temp_json_file, json_file);

return 1;
}

0 comments on commit b3a4dc7

Please sign in to comment.