OSX terminal script - Try to open all files in directory - macos

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

Related

Script cannot open file which can be opened normally

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?

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

How to open all mp3 files using windows command line?

If I have the following directory:
C:\Users\mkt\Desktop\Music\Tool\Lateralus
and want to open all files contained in the folder using cmd prompt. how could I do that?
I know that the following line will open one of them:
cd C:\Users\mkt\Desktop\Music\Tool\Lateralus\"01 - The Grudge.mp3"
But what about multiple files?
I am a noob at DOS and I really shouldn't be, but without practice you will never get better.
I am wondering, why it is opening your mp3 file with the cd command.
The cd command is used to switch directories, so this is something new for me.
I am a MAC OS user, so I could not test it, but if your given example worked, I think this should work too:
cd C:\Users\mkt\Desktop\Music\Tool\Lateralus\*.mp3
With the "*.mp3" you say, every mp3 file.
I hope this helps.

How to stream all videos in a folder?

Hi i want to stream videos over web using ffserver. i got this link as reference.
Now what i am not able to figure out is how to pass a folder(which content all videos i want to stream) as input to stream all videos. I also want add more videos dynamically to this folder in time to time and streaming should happen(like how it works in Darwin). now i can't use Darwin because it doesn't support for iOS.
please give me a suggestion.
is there any other open source tool by which i can do this?
I wrote a bash script for this, it's working in ubuntu 16
Hopefully someone else can write it up in a less terrible language
Here's the script:
echo -e "HTTPPort 8090\nHTTPBindAddress 0.0.0.0\nMaxHTTPConnections 2000\nMaxClients 1000\nMaxBandwidth 1000\nCustomLog -\n<Stream stat.html>\nFormat status\n</Stream>"
num=1
for i in *.mp3; do
echo -e "<Stream \"$(urlencode $i)\">\nFile \"$(pwd)/$i\"\nFormat mp2\nAudioCodec libmp3lame\nAudioBitRate 64\nAudioChannels 1\nAudioSampleRate 44100\nNoVideo\n</Stream>"
done
save this as a bash script in the folder you want to serve, I'll refer to it as:
./gen_ffserver_conf.sh
it's hard coded for mp3, you'd have to sort through my echos to get it to do another format.
run the server with:
ffserver -f <(bash -e ./gen_ffserver_conf.sh)
I had to install a package for the url encoding:
sudo apt install gridsite-clients
(and of course you need ffserver as well, in the ffmpeg package)
I stream the files by going to:
http://<ip address of streaming server>:8090/stat.html
and clicking on the urlencoded values, (using chromium). This will open the stream and start playing.
Explanation:
ffserver doesn't like wildcards, or at least I never figured that out, so I'm just creating an entry for each file in the server. The urlencoding is annoying but necessary for the stat page links to work properly.

Bash script for taking a screenshot, renaming and moving

First bash script and I'm running into some issues. I want to take a screenshot, then change the name of the .png to a random number (so that pictures don't overwrite). After it's renamed I want to move the picture to my dropbox folder.
This is what I've got:
#!/bin/bash
#Take screenshot
import -window root $HOME/screenshot.png
#Move to dropbox folder
mv $HOME/screenshot.png $HOME/Dropbox/Max-Max/$RANDOM.png
When I run it dropbox is getting some kind of something because my taskbar icon indicates a file transfer. When I open up the folder however, nothing's there.
Thanks for the help.
Instead of $RANDOM use $(date|tr " :" _)
Much more useful
You can do that with scrot like this:
scrot -e 'mv $f ~/Dropbox/Max-Max'
But your script looks fine... Try to create an empty file first to make sure your dropbox functions fine.
echo > ~/Dropbox/Max-Max/testfile
The commands you're using are correct. The only way it could fail is if Max-Max doesn't exist. mv moves and renames files among existing directories -- mv cannot create directories.

Resources