0

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

Community
  • 1
  • 1
julesverne
  • 392
  • 1
  • 8
  • 18

2 Answers2

1

.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.

Lri
  • 26,768
  • 8
  • 84
  • 82
  • Thanks Lauri! Yeah, I understand about ffprobe and that is what i use on the windows side, but for some reason the ffmpeg i have on the Mac is only ffmpeg.. doesn't include ffprobe or ffplay. I don't have time to test this till tonight but will let you know how it goes. Thanks again! – julesverne Dec 06 '13 at 18:10
  • Applescript is EXACTLY what I was looking for without really knowing it! I know ffmpeg syntax by now, it was just getting a script to do exactly what I can do on Windows. I can just right click any multimedia files I want now and choose to run this application. I use it so much that it was so frustrating to constantly open up Terminal and type everything out. Thank you @LauriRanta – julesverne Dec 07 '13 at 07:39
  • I feel like I should retitle the question somehow so that anyone looking for this as an applescript would find it. Is that allowed? If so, any suggestions? – julesverne Dec 07 '13 at 07:59
  • @julesverne Yeah, it is definitely allowed. I guess you could rephase the question to be more about how to make something like a .command file that accepts dropped files as input. – Lri Dec 07 '13 at 08:17
  • Thanks again @LauriRanta I've never heard of Platypus. I made the switch to Mac about 10 years ago, but since being able to create bat scripts effectively on Windows over the past couple years, I've paid less and less attention to Mac. I have a feeling I'll be getting back to work on Mac now. Thanks! – julesverne Dec 07 '13 at 21:31
0

This might do it:

for FILE in "${@}"
do

    /Applications/ffmpeg -i "$FILE"

done
chepner
  • 497,756
  • 71
  • 530
  • 681
thom
  • 2,294
  • 12
  • 9
  • This didn't work, but I can't tell if it didn't work or I'm not implementing it correctly. And one thing as far as I can tell, Mac OS won't let me drop files onto the script. BTW.. i save the script as ffmpeg.command and I did chmod command so it would be executable. – julesverne Dec 06 '13 at 07:04
  • Actually this script should run ffmpeg on every commandline argument you give,I only tested this on Linux (I don't have OSX). It might be that I don't understand correctly what you mean by "drop on" and how OSX passes this to the script. Can you try it from the commandline just to eliminate the chance that the error might be somewhere else ? – thom Dec 06 '13 at 19:12
  • I tried your solution again in terminal. I still couldn't figure out how to get files as arguments. @LauriRanta 's answer was really what I was looking for. It allows me to simply right click on any multimedia file and launch the applescript as an application that launches ffmpeg with that file as the argument. Opening up terminal every time and typing everything out is not really what I wanted to do. However, your for loop can definitely come in handy later on as I continue to develop applescripts for Mac if I can figure out how to get for loop to loop through user defined file types. – julesverne Dec 07 '13 at 07:57