Problem with media clip using script

I have not been able to extract any media clips from ELAN using the media clip using script feature. Every time I try, nothing happens. I currently use the ELAN 5.0.0-alpha and beta versions for MacOS Sierra and have looked through the forum. I wonder if I need to edit the clip media text file. Would someone take the time to look at it? Here it is:

osascript ./scripts/qtp_clip_10_6_export.scpt $in_file $out_file $begin(sec.ms) $end(sec.ms)

M2-edit-cl /in:$begin(fr) /out:$end(fr) $in_file $out_file

ffmpeg.exe -vcodec copy -acodec copy -ss $begin(sec.ms) -t “$duration(sec.ms)” -i $in_file $out_file

Lines starting with a # (dash) are considered to be comment lines.

This is an example media clipping configuration file for use with ELAN.

The configuration consists of the name of an application that can clip

media files and that supports parameterized calls from the command line

followed by a number of parameters for the application.

The actual set of parameters depends on the application of choice.

But most programs will need the path to an input file, the path to an output file,

the begin time of the portion to clip and either the end time or the duration of

the portion to clip.

When creating a clip from within ELAN, it reads the script and fills the

placeholders for the common parameters with the necessary information.

The first part of the script should be the name or the path to the application

to be used for the clipping. If only a name is used the application should be

known to the system, “in the path”. If a path is specified it should be the

absolute path to the application. If the absolute path contains white spaces the

path should be within double quotation marks. If the input file and output file

paths might contain spaces and the clipping application would need them to

be in quotation marks these should be added before and after the placeholders

in the script.in

The placeholders have this form:

$in_file

$out_file

$begin(format)

$end(format)

$duration(format)

where format needs to be replaced by one of the following formats:

hour:min:sec.ms

hour:min:sec:fr

hour:min:sec:fr_NTSC

sec.ms

ms

fr

fr_NTSC

when frames are specified PAL is assumed, for NTSC use hour:min:sec:fr_NTSC or fr_NTSC

Examples:

C:\Program\ffmpeg\bin\ffmpeg.exe -i $in_file -vcodec copy -acodec copy -ss $begin(sec.ms) -t $duration(sec.ms) $out_file

M2-edit-cl /in:$begin(fr) /out:$end(fr) $in_file $out_file

Yes, there are several issues with this functionality on macOS. As of version 10.11 (I believe) all the libraries and resources of an application need to be inside the .app folder. If you right-click e.g. the ELAN_5.0.0-beta(.app) and choose Show Package Contents, you’ll find a lot of files in the Contents/Resources folder. Apart from the ‘clip-media.txt’ file, normally there would also be a file ‘qtp_clip_10_7_export.scpt’ there. But if we do so the .app cannot be digitally signed because the .scpt is detected as ‘junk’. They are now zipped in ‘scripts.zip’.
The best thing to do is maybe look into the ‘Clip_media_osx.pdf’ and follow the steps to copy ‘Clip-media.txt’ to ELAN’s preferences folder.
Then edit it. Either change the relevant line to call ffmpeg or extract the most recent, the 10_7 version, of the scpt archive and save it e.g in the same ELAN preferences folder and modify ‘clip-media’ by setting the absolute path to the .scpt file as the second parameter, after ‘osascript’. After saving clip-media and launching ELAN, clipping media might work.

There are still problems with the .scpt file: the time values for start and end times are read as ‘integer’ and the fractional part is removed (or rounded down to whole seconds). The arguments 3 and 4 in the .scpt file should be read as ‘real’ but then (on the system I tested on) time values in the format sec.ms are not parsed correctly when there are three decimals, as ELAN passes such time values. E.g. 12.333 is apparently not correct, 12.3 is. At this moment I don’t think there is a way to specify such format.
Maybe clipping with ffmpeg is easier now (but I haven’t checked that recently).

-Han

I have now uploaded new versions of the two variants of AppleScript-based clipping, one that calls QuickTime’s export function and one that calls the Save As function. The first one works on a macOS 10.12 machine, the second one results in a “no permission” message at the point of saving the file (maybe someone can try that one too).
In order to use e.g. the “qtp_clip_10_10_export.scpt” version the clip-media.txt has to be modified as mentioned above. If it doesn’t work from within the ELAN .app folder, it can be tried from the ELAN Preferences folder.
The new scripts can be downloaded here.

I really couldn’t solve the issue. Where should I copy 'qtp_clip_10_10_export.scpt’and how ‘clip-media.txt’ has to be modified?
I tried this ‘The best thing to do is maybe look into the ‘Clip_media_osx.pdf’ and follow the steps to copy ‘Clip-media.txt’ to ELAN’s preferences folder.’, but not able to. Maybe a tutorial with the steps within MacOs (High Sierra)?
Many Thanks

Dear Giorgina,
The “Clip_media_osx.pdf” is intended to be a kind of tutorial or macOS users, but it still has to be updated. We have limited resources so it is not easy to keep everything up to date. It’s not quite clear to me whether you didn’t find the “Clip_media_osx.pdf” file at all or whether you were not able to follow the steps. In the latter case it would be helpful which steps you were not able to follow.

Summarizing: assume your login name is “giocan”, your “home” folder will be /Users/giocan/ If you go to this folder in the Finder you probably won’t see a subfolder “Library” but it is there. Press the Alt/Option key and click the Go menu in the main menu bar and you’ll see a Library menu item. Select this item and that folder will open in the Finder. Then go to subfolders like this;
/Users/giocan/Library/Preferences/ELAN/
into that folder copy “clip-media.txt” and “qtp_clip_10_10_export.scpt”
open “clip-media.txt” and modify the first line such that it is like this:
osascript /Users/giocan/Library/Preferences/ELAN/qtp_clip_10_10_export.scpt $in_file $out_file $begin(sec.ms) $end(sec.ms)
Save the file, launch ELAN and try to clip a selection via Export As - Media Clip using script… etc. Does it work?

We’ve created an updated version of the media clipping tutorial, it is now available on the ELAN web page. This is the macOS version, hopefully this clarifies the procedure a bit better.

Thank you.

So, I’m working with ELAN 4.9.4.
I did part 1 of the tutorial (where to place the script) and placed the files
but about part 2 that’s what I find in clip-media.text:

ffmpeg.exe -i $in_file -ss $begin(sec.ms) -t $duration(sec.ms) $out_file

ffmpeg.exe -i $in_file -vcodec copy -acodec copy -ss $begin(sec.ms) -t $duration(sec.ms) $out_file

ffmbc.exe -vcodec copy -acodec copy -ss $begin(hour:min:sec.ms) -t $duration(hour:min:sec.ms) -i $in_file $out_file

Lines starting with a # (dash) are considered to be comment lines.

This is an example media clipping configuration file for use with ELAN.

etc

and that’s the kind of error I have when I try to export as ‘media clip using script’:

Error running script: Cannot run program “ffmpeg.exe”: error=2, No such file or directory(1)

Thanks for more help to my dummy questions

One more,
is it regular that ‘qtp_clip_10_10_save.scpt’ downloaded from the link above is actually an empty file (no lines)?

But on macOS the default non-comment line in clip-media.txt starts with osascript …, or doesn’t it?
The line starting with ffmpeg.exe will only work on Windows (if all requirements are met), .exe are Windows executables. (If you want to clip with ffmpeg on macOS name and/or path to it needs to be modified).

The two .scpt files in the mentioned .zip file are not empty (15-17 Kb). If you’ve opened it in Script Editor you might need to resize the Description part of the window or choose View->Hide Description to see the lines.

Hi,
I believe I’m having the same, or a similar issue. (So I’ll add to this thread, but I can start a new one if that’s better.)
OS: OSX El Capitan, 10.11.6
ELAN Version 5.2

I’ve worked through the media clipping tutorial and was able to complete all the steps. Currently, clip-media.txt and qtp_clip_10_10_export.scpt are in …Library/Preferences/ELAN. (And these are not in the Resources folder, although I’ve tried running things from there too, and I’ve tried having them in both places.)

In qtp_clip_10_10_export.scpt I’ve modified the hard drive name to reflect my computer’s hard drive name, and I’ve changed 720p to 480p (in both places in the script where that appears).480 was my only export option in Quicktime.

clip-media.txt is modified to be:
osascript… /Users/emilyrogers/Library/Preferences/ELAN/qtp_clip_10_10_export.scpt $in_file $out_file $begin(sec.ms) $end(sec.ms)

When I make a selection and go to “Export as…” in ELAN, I get the error “cannot run “osascript…”: error=2, No such file or directory(1)”. Oddly, this exact same procedure yesterday did NOT produce the error ; instead, nothing happened at all.

I have tried modifying clip-media.txt to be:
osascript
/Users/emilyrogers/Library/Preferences/ELAN/qtp_clip_10_10_export.scpt $in_file $out_file $begin(sec.ms) $end(sec.ms)
In this case, I get the error “cannot run program “Users/emilyrogers/Library/Preferences/ELAN/qtp_clip_10_10_export.scpt”:Error=13, Permission denied(1)”
(but I have read+write permissions on both of these files).

I have tried running things from the Resources folder too, but no luck. Nothing happens. (I should mention, in case it’s related, that I have another glitch in ELAN: the “save selection as .eaf” function doesn’t work. It saves starting at the beginning of the selection but doesn’t end the new file at the end of the selection, instead saving the entire rest of the video.)

Last thing to note in case it’s relevant is I have Quicktime Player (10.4) and Quicktime Player 7 (7.6.6) on my computer. I downloaded Quicktime Player 7 because it seems like that’s the one compatible with ELAN.

Any help getting the media clipping working would be greatly appreciated! Thank you!
-Emily

Hi Emily,

The first error must be due to the two full stops following the name of the program:
osascript…
The reason for the “Permission denied” error that you get after your correction of clip-media.txt might be the hard return after osascript and before /Users/etc. (if it is indeed a return in clip-media.txt). When I try it with a hard return, so that the entire command is on two lines, I see the same error you report.
The command must be on one, single line, with the name of the application, followed by a white space character ad then the rest of the command.

The save selection as eaf function doesn’t automatically clip the media (this has to be ticked separately), it normally just sets the “offset” of the media to start where the selection starts.

Quick Time Player 7 is useful for checking if a specific file should run in ELAN (is supported or not); the clip function uses QuickTime Player 10, no need to install QTP 7 for that.

-Han

Hi Han,

I’m pleased to say it seems to be working now! Thank you for your help!

clip-media now looks like:
osascript /Users/emilyrogers/Library/Preferences/ELAN/qtp_clip_10_10_export.scpt $in_file $out_file $begin(sec.ms) $end(sec.ms)

You’re right, I did have a hard return after “osascript” before. I realized why I did this (and noting it here for others who may be making the same newbie mistake). I misinterpreted your example of an edited rule found on p. 4 of the clip-media tutorial (https://tla.mpi.nl/wp-content/uploads/2018/04/Clip_media_macOS.pdf). That looks like a hard return, but it is really it’s just a line break.

Anyways, thanks again!

-Emily

Thanks for pointing that out, Emily. I’ll update the clip-media tutorial pdf to make clear that the command must be on one single line.