I've been googling around for the past hour but haven't found anything reliable yet.
I am wondering if there is a mac equivalent of the arecord command that would work, for example, in the following example:
sox -t .wav "|arecord -d 2" -n stat
You can natively use the utility afplay to play audio files from command line...
afplay sound.wav
You can use sox to record (avalable from macports and probably from Homebrew)
sox -d recording.wav
Related
I'm trying to execute a script that runs a Handbrake video conversion.
If I run the following command from the terminal, it works fine:
HandbrakeCLI -i inputtestfile.mp4 -o outputtestfile.mp4 -z "Preset"
If I put this into a .sh script (and give the script execution rights using chmod a+x), I get the following error:
HandbrakeCLI: Command not found
If I then put the full path to HandbrakeCLI, it then works, for example:
/usr/local/Cellar/handbrake/1.2.0/bin/HandBrakeCLI -i inputtestfile.mp4 -o outputtestfile.mp4 -z "Preset"
However, the above method is inconvenient because every time I update Handbrake to a new version, I'll have to update the script.
How can I add Path (I think this is right), to the script, so I can just use:
HandbrakeCLI -i inputtestfile.mp4 -o outputtestfile.mp4 -z "Preset"
Thanks
You can begin the .sh script with:
PATH=$PATH:/usr/local/Cellar/handbrake/1.2.0/bin
path is an environment variable that affects where sh would look unqualified files names (commands) from.
And for the changing version you can parse HandBrake --version output and use it as a variable instead of 1.2.0 string in PATH.
I have a large number of photos on my machine where I'd like to parse the standard naming convention I have created for each file, and then pipe it to the touch command.
For example, I have these files:
2016-08-06-00h28m34.jpg
2016-08-06-00h28m35.jpg
2016-08-06-00h28m36.jpg
I would like to generate (and then run) the following commands:
touch -t 201608060028.34 2016-08-06-00h28m34.jpg
touch -t 201608060028.35 2016-08-06-00h28m35.jpg
touch -t 201608060028.36 2016-08-06-00h28m36.jpg
I can do this manually in a text editor, but it's extremely time-consuming, due to the number of files in each directory. I could also do it in C# and run it over my LAN, but that seems like overkill. Heck, I can even do this in SQL Server, but ... it's OS X and I'm sure there's a simple command-line thing I'm missing.
I've looked at Windows version of Unix touch command to modify a file's modification date from filename part, and Split Filename Up to Define Variables, but I can't seem to figure out how to add in the period for the seconds portion of the script, plus I don't want to add the batch script to each of the hundreds of folders I have.
Any assistance will be greatly appreciated.
Simple Option
I presume you are trying to set the filesystem time to match the EXIF capture time of thousands of photos. There is a tool for that, which runs on OSX, Linux (and Windows if you must). It is called jhead and I installed it on OSX using homebrew with:
brew install jhead
There may be other ways to install it - jhead website.
Please make a back up before trying this, or try it out on a small subset of your files, as I may have misunderstood your needs!
Basically the command to set the filesystem timestamp to match the EXIF timestamp on a single file is:
jhead -ft SomeFile.jpg
So, if you wanted to set the timestamps for all files in $HOME/photos/tmp and all subdirectories, you would do:
find $HOME/photos/tmp -iname \*.jpg -exec jhead -ft {} \;
Option not requiring any extra software
Failing that, you could do it with Perl which is installed on OSX by default anyway:
find . -name \*.jpg | perl -lne 'my $a=$_; s/.*(\d{4})-(\d+)-(\d+)-(\d+)h(\d+)m(\d+).*/$1$2$3$4$5.$6/ && print "touch -t $_\ \"$a\"" '
which gives this sort of output on my machine:
touch -t 201608060028.34 "./2016-08-06-00h28m34.jpg"
touch -t 201608060028.35 "./2016-08-06-00h28m35.jpg"
touch -t 201501060028.35 "./tmp/2015-01-06-00h28m35.jpg"
and if that looks good on your machine, you could send those commands into bash to be executed like this:
find . -name \*.jpg | perl -lne 'my $a=$_;s/.*(\d{4})-(\d+)-(\d+)-(\d+)h(\d+)m(\d+).*/$1$2$3$4$5.$6/ && print "touch -t $_\ \"$a\"" ' | bash -x
And, for the Perl purists out there, yes, I know Perl could do the touch itself and save invoking a whole touch process per file, but that would require modules and explanation and a heap of other extraneous stuff that is not really necessary for a one-off, or occasional operation.
I have a Mac computer. Usually all my batch programming is done on my PC. So I tried to create what I assumed would be a simple equivalent using a Mac shell. Obviously as you all know that was foolish of me to think that. After 2 days of scowering the web I found the closest thing I could to what I was looking for. But no, this doesn't work either.
All I'd like to do is throw a multimedia file onto the script, and have the terminal give me the ffmpeg info output. In my searching I did find this "$#" which as far as I can tell is the windows bat equivalent of %*. Meaning you can throw files on the script and the script refers to those files as variables which can be processed. So I believe what I want to do is possible.
Again the code at the bottom is just to look through the current directory of all .mov files and run ffmpeg. It doesn't work. But.. if no one can help me figure out the actual thing I'd like to do then I'd settle with something like below that does actually work.
#!/bin/bash
FFMPEG=/Applications/ffmpeg
FIND=/usr/bin/find
FILES=$(${FIND} . -type f -iname "*.mov")
if [ "$FILES" == "" ]
then
echo "There are no *.mov file in $(pwd) directory"
exit 1
fi
for f in *.mov
do
$FFMPEG -i "$f"
done
If someone can please help me figure this out I'd really appreciate it. Thank you in advance! Jules
I just found this solution from the "similar questions" sidebar, which is similar to the script above, so again, not completely what I wanted but.. didn't matter, didn't work for me. How to batch convert mp4 files to ogg with ffmpeg using a bash command or Ruby
.command files don't receive dropped files as input.
You might just open a Terminal window, type for f in, drop the files on the window, and type ; do ffmpeg -i "$f"; done.
Or save a script like this as an application in AppleScript Editor:
on open argv
set paths to ""
repeat with f in argv
set paths to paths & quoted form of POSIX path of f & " "
end repeat
tell application "Terminal"
do script "for f in " & paths & "; do ffprobe -i \"$f\"; done"
activate
end tell
end open
ffprobe -i is like ffmpeg -i but it doesn't show an error like At least one output file must be specified.
Edit: you could also use Platypus:
Set the script to something like for f; do ffprobe -i "$f"; done.
This might do it:
for FILE in "${#}"
do
/Applications/ffmpeg -i "$FILE"
done
How do I write a batch process on the Mac for pdf2swf, I want to convert all pdfs in a folder into swf. But pdf2swf doesn't have a option to convert a folder of pdfs to swfs, you have to do it one at a time. I'm not sure how if I should use a Apple script or a Shell script, either one I'm not sure how to get or assign a file name variable.
pdf2swf file_name_variable.pdf -o file_name_variable.swf -T 9 -f
Thanks
Open up Terminal and do something like this:
$ for f in `find /path/to/my/pdf/directory -name \*.pdf` ; do
> echo "Processing $f..."
> pdf2swf $f -o ${f/.pdf/.swf} -T 9 -f
> done
The following works very nicely to determine the length of various audio/video files:
mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH
However, I want to kill mplayer's output so I can determine the length of many files more efficiently. How do I do that?
The MPlayer source ships with a sample script called midentify, which looks like this:
#!/bin/sh
#
# This is a wrapper around the -identify functionality.
# It is supposed to escape the output properly, so it can be easily
# used in shellscripts by 'eval'ing the output of this script.
#
# Written by Tobias Diedrich <ranma+mplayer#tdiedrich.de>
# Licensed under GNU GPL.
if [ -z "$1" ]; then
echo "Usage: midentify.sh <file> [<file> ...]"
exit 1
fi
mplayer -vo null -ao null -frames 0 -identify "$#" 2>/dev/null |
sed -ne '/^ID_/ {
s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
}'
The -frames 0 makes mplayer exit immediately, and the -vo null -ao null prevent it from trying to open any video or audio devices. These options are all documented in man mplayer.
FFMPEG can give you the same information in a different format (and doesn't attempt playing the file):
ffmpeg -i <myfile>
There's another FF-way in addition to #codelogic's method, which doesn't exit with an error:
ffprobe <file>
and look for the duration entry.
Or grep for it directly in the error stream:
ffprobe <file> 2> >(grep Duration)
looks like there are a few other libs available, see time length of an mp3 file
Download your .mp3 file, play it with your Player (ex. Windows Media Player) and the player will show the total time at the end of play.