Script cannot open file which can be opened normally - bash

I am trying to run a script which finds the pitch of a waveform, however I am getting an error that it cannot open a wav file, and I don't know why this is.
The code is:
../../SPTK-3.11/bin/pitch/pitch -a 0 -s 16.0 -p 80 -t0 0.0 -L 40 -H 150 -o 1 ../wav/*.wav > f0
And the error is:
Cannot open file ../wav/arctic_a0254.wav!
There are around 500 wav files in the folder, so I don't know why it doesn't list the first here if there is a problem with the path or the file
I have already tried doing ls ../wav which shows all the files as being in that directory, and did open ../wav/arctic_a0254.wav which also worked, so I don't know why there is an error here.
EDIT: I tried removing the wav file from the folder, and got the same error with the proceeding wav file (arctic_a0255.wav), so I don't think it is to do with the individual wav file.
EDIT2: The script lists the error as occurring when there is an error seeking the beginning of the audio container, but I'm not sure what this means
EDIT3: Solved! The issue was the file not being a float, so I converted the wav in audacity and the script worked as normal

I believe that the program you are executing, pitch, runs out of file descriptors.
I don't know whether it fails to close already used files, thus leaking file descriptors, or whether it really needs to keep all those files open for performing its task, which would be more difficult to fix.
You can try to strace it and see the exact error you get from the read() system call just before bailing out.
Do you have access to the source?
Can you run it in smaller batches?

Related

Loop Over Files as Input for Program, Rename and Write Output to Different Directory

I have a problem with writing the output of a program to a different directory when I loop different files as variables as inputs. I run this in the command line. The problem is that I do not know how to "tell" the program to put the output with a changed filename into another directory than the input directory.
Here is the command, although it is a bioinformatic tool which requires specific input file formats. I am sorry that I could not give a better example. Nonetheless, the program is called computeMatrix in a software-tool box called deeptools2.
command:
for f in ~/my/path/*spc_files*; do computeMatrix reference-point--referencePoint center --regionsFileName /target/region.bed --binSize 500 --scoreFileName "$f" **--outFileName "$f.matrix"** ; done \
So far, I tried to use the command basename to just get the filename and then change the directory before that. However I could not figure out:
if this is combinable
what is the correct order of the commands (e.g.:
outputFile='basename"$f"', "~/new/targetDir/'basename$f'")
Probably there are other options to solve the problem which I could not think of/ find.

OSX terminal script - Try to open all files in directory

I have some video files in a directory which can't be opened. The problem is that some of them have been wrongly transcoded, so they can't be opened with QuickTime.
What I was wondering is if there is some kind of script I could write that would read through all the files in a directory and try to open them with QuickTime, and if they can't be opened, to move them or do something else.
My actual file directory would be something like this:
--Main folder
---Subfolder
-----video.mov
-----video.mov
------Sub-Subfolder
--------video.mov
--------video.mov
---Subfolder
-----video.mov
-----video.mov
------Sub-Subfolder
--------video.mov
(...) and so on
I hope I've explained it well so you can understand it... If someone could help me, I'd appreciate it so much.
Thanks!
The looping part is pretty easy, and should look like this :
for x in `find <folder> -name "*.mov"`; do <validate movie file command>; done
For the validate file command there's a suitable option in ffmpeg utility which is basically a video converter, but you can convert the input video to NULL and just read input file and report any errors that will appear.
ffmpeg -v error -i ${x} -f null - 2>error.log

How to batch downsample MP3 files using lame?

I found on another question how to do singular files, which worked great.
"lame --mp3input -b birtratenumber input.mp3 output.mp3"
Thing is, I have around 60 files and doing each individually is very time consuing (the total ammount of time does not bother me, it´s more about having to stay there waiting to input the next command).
So, Is there a way to run this command for all files in the folder, telling it to use the same filename as source filename but adding "_48" at the end of it, before the .mp3 part and saving it in the source folder (same folder as original files).
Thanks in advance for any and all help.
Use a shell for loop to process the files in turn:
for i in *.mp3; do
lame --mp3input -b 48 "$i" "${i%%.mp3}_48.mp3"
done

Encoding .wav to .flac through cygwin: error can't open input file: Invalid argument

I'm using bash via cygwin on a windows machine to batch-convert several hundreds of wav-files to flac. I wrote a simple script to read each file from a txt-file containing a directory-print I did earlier, convert the linuxpaths to windowspaths and using FLAC to encode the files.
#!/bin
IFS="$(printf '\n\t')"
(for wav in $(cat path/wavfiles.txt)
do
winwav= $(cygpath -w "$wav")
flac --best --verify "$winwav"
sleep 30
done)
The path conversion seems to be working fine: bash expands out the path correctly to a windows path for FLAC to use, but FLAC keeps spitting out the following error message:
ERROR: can't open input file : inavlid argument
I tried encoding the files with a similar script windows batch file and it worked fine, so the files aren't the problem. I searched a lot of sites, including this one and the FLAC-helppages, but I can't seem to find any information concerning this error message. Probably something silly I overlooked, it usually is.
Any ideas?

Windows: can't get flac.exe error messages into a file

I need to test bunch of FLAC files and get all errors into a txt file. I used the following syntax which is very common and usually works fine with all programs:
c:\temp\FLAC\flac.exe -t myflacfile.flac >> c:\temp\report.txt
But it surprisingly doesn't work! No idea why error messages can't be catched. The report file gots created though. Please share your thoughts, cause' I haven't find a word on the Net about it.
The problem is in syntax. There is extra space in command line before an output filename. Commands like
flac.exe -t 1.flac 2>>a.txt
or
flac.exe -t 1.flac 2>a.txt
are working well.

Resources