Re: do shell script quoting help
Re: do shell script quoting help
- Subject: Re: do shell script quoting help
- From: Christopher Nebel <email@hidden>
- Date: Tue, 02 Sep 2014 12:13:06 -0700
> On Sep 2, 2014, at 11:25 AM, Terry Barnum <email@hidden> wrote:
>
> I've written a small droplet that takes a Prores QT movie and converts it to an mp4 using do shell script and ffmpeg and it works great. I'm now trying to overlay timecode with ffmpeg's drawtext function but am having trouble escaping characters. It works fine in Terminal and in a shell script but I can't figure it out with do shell script. I know I could instead just call a shell script that calls ffmpeg but I'd like to learn how from do shell script. Here's the terminal line that works (hopefully formatting doesn't get too mangled).
>
> ffmpeg -i /Users/macuser/Desktop/source.mov -threads 0 -s 640x360 -pix_fmt yuv420p -vcodec libx264 -b:v 500k -acodec libfaac -b:a 128k -vf drawtext="fontsize=15:fontfile=/Library/Fonts/Verdana.ttf:timecode='01\:00\:00\:00':rate=23.976:text='TCR:':fontsize=72:fontcolor='white':boxcolor=0x000000AA:box=1:x=30:y=30" -y /Users/macuser/Desktop/out.mp4
>
> Here are the relevant lines in the droplet applescript. I've tried several different ways of escaping quotes and colons but no luck.
>
> set fontfile to quoted form of "fontfile=/Library/Fonts/Verdana.ttf:"
> set rate to quoted form of "rate=23.976:"
> set timecode to quoted form of "timecode='01:00:00:00':"
> set myText to quoted form of "text='TCR ':"
> set fontsize to quoted form of "fontsize=72:"
> set fontcolor to quoted form of "fontcolor='white':"
> set boxcolor to quoted form of "boxcolor=0x000000AA:"
> set box to quoted form of "box=1:"
> set xc to quoted form of "x=30:"
> set yc to "y=30"
>
> set myResult to do shell script ("/opt/local/bin/ffmpeg -i " & quoted form of POSIX path of this_item & "-threads 0 -s 640x360 -pix_fmt yuv420p -vcodec libx264 -b:v 500k -acodec libfaac -b:a 128k -vf drawtext=" & fontfile & rate & myText & timecode & fontsize & fontcolor & boxcolor & box & xc & yc & " -y /Users/macuser/Desktop/out.mp4 &> /tmp/out.txt”)
It may just be a copy/paste problem, but I notice that there’s no space before the “-threads” option, which means it will run together with the text of this_item. What happens if you fix that?
Incidentally, you could concatenate all the “drawtext” arguments in AppleScript, and then do “quoted form of” on the result, like this:
set allTheText to "fontfile=/Library/Fonts/Verdana.ttf:rate=23.976:timecode='01:00:00:00':…"
do shell script "… drawtext=" & quoted form of allTheText & " -y …"
It works the same either way, but this way is a bit shorter, and IMO easier to read.
—Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden