Theldus commited on
Commit
d625238
·
unverified ·
1 Parent(s): da3cdf4

main : check if input files exist before proceeding (#1872)

Browse files

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.

Files changed (1) hide show
  1. examples/main/main.cpp +16 -0
examples/main/main.cpp CHANGED
@@ -10,6 +10,8 @@
10
  #include <vector>
11
  #include <cstring>
12
 
 
 
13
  #if defined(_MSC_VER)
14
  #pragma warning(disable: 4244 4267) // possible loss of data
15
  #endif
@@ -841,6 +843,20 @@ int main(int argc, char ** argv) {
841
  return 1;
842
  }
843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  if (params.fname_inp.empty()) {
845
  fprintf(stderr, "error: no input files specified\n");
846
  whisper_print_usage(argc, argv, params);
 
10
  #include <vector>
11
  #include <cstring>
12
 
13
+ #include <sys/stat.h>
14
+
15
  #if defined(_MSC_VER)
16
  #pragma warning(disable: 4244 4267) // possible loss of data
17
  #endif
 
843
  return 1;
844
  }
845
 
846
+ // remove non-existent files
847
+ for (auto it = params.fname_inp.begin(); it != params.fname_inp.end();) {
848
+ struct stat st;
849
+ const auto fname_inp = it->c_str();
850
+
851
+ if (stat(fname_inp, &st) == -1) {
852
+ fprintf(stderr, "error: input file not found '%s'\n", fname_inp);
853
+ it = params.fname_inp.erase(it);
854
+ continue;
855
+ }
856
+
857
+ it++;
858
+ }
859
+
860
  if (params.fname_inp.empty()) {
861
  fprintf(stderr, "error: no input files specified\n");
862
  whisper_print_usage(argc, argv, params);