From dda4b0ed06b9078c3f9167905192c66506a612f4 Mon Sep 17 00:00:00 2001 From: Davidson Francis Date: Mon, 19 Feb 2024 05:51:26 -0300 Subject: [PATCH] main : check if input files exist before proceeding (#1872) Until the most recent commit (3d42463), the main.cpp sample file does not check whether the input files exist or not. Consequently, the model is loaded first before reporting whether there was a failure or not when processing a file. In environments with HDD, this can take about 50 seconds or more, depending on the loaded model. This commit addresses this issue by checking in advance whether the input files exist or not. --- examples/main/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 8abb27fc..da4ba6a7 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -10,6 +10,8 @@ #include #include +#include + #if defined(_MSC_VER) #pragma warning(disable: 4244 4267) // possible loss of data #endif @@ -841,6 +843,20 @@ int main(int argc, char ** argv) { return 1; } + // remove non-existent files + for (auto it = params.fname_inp.begin(); it != params.fname_inp.end();) { + struct stat st; + const auto fname_inp = it->c_str(); + + if (stat(fname_inp, &st) == -1) { + fprintf(stderr, "error: input file not found '%s'\n", fname_inp); + it = params.fname_inp.erase(it); + continue; + } + + it++; + } + if (params.fname_inp.empty()) { fprintf(stderr, "error: no input files specified\n"); whisper_print_usage(argc, argv, params);