If input file is not seekable, reopen instead of seeking back to start on clipping

This commit is contained in:
Chris Cannam
2022-02-09 10:37:04 +00:00
parent c7eefe9e8d
commit 30e63d33ac

View File

@@ -590,8 +590,6 @@ int main(int argc, char **argv)
int frame = 0;
int percent = 0;
sf_seek(sndfile, 0, SEEK_SET);
if (!realtime) {
if (!quiet) {
@@ -818,8 +816,31 @@ int main(int argc, char **argv)
}
if (!successful) {
sf_seek(sndfile, 0, SEEK_SET);
sf_seek(sndfileOut, 0, SEEK_SET);
if (sf_seek(sndfile, 0, SEEK_SET) < 0) {
if (debug > 0) {
cerr << "input file is not seekable: reopening" << endl;
}
sf_close(sndfile);
sndfile = sf_open(fileName, SFM_READ, &sfinfo);
if (!sndfile) {
cerr << "ERROR: Failed to reopen input file \""
<< fileName << "\": " << sf_strerror(sndfile) << endl;
return 1;
}
}
if (sf_seek(sndfileOut, 0, SEEK_SET) < 0) {
if (debug > 0) {
cerr << "output file is not seekable: reopening" << endl;
}
sf_close(sndfileOut);
sndfileOut = sf_open(fileNameOut, SFM_WRITE, &sfinfoOut);
if (!sndfileOut) {
cerr << "ERROR: Failed to reopen output file \""
<< fileNameOut << "\": "
<< sf_strerror(sndfileOut) << endl;
return 1;
}
}
continue;
}