In version 26.6 now you can install a custom filter UI into the App Data Directory extensions/filters/<your-filter>. You need to follow the example and structure of one of the installed filters, but here is a zip archive that shows how to use this feature as a way to run a general script. The zip contains extensions/filters/hello-world so extract it to the top of Shotcut’s app data directory.
extensions_filters_hello-world.zip (1.1 KB)
What does it do?
Just what you expect 
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts
import Shotcut.Controls as Shotcut
Item {
function main(argument) {
status.text = "Hello World ";
}
width: 350
height: 50
ColumnLayout {
anchors.fill: parent
anchors.margins: 8
Shotcut.Button {
id: button
Layout.columnSpan: 2
text: 'Start'
onClicked: main()
}
Label {
id: status
}
Item {
Layout.fillHeight: true
}
}
}
P.S. not all of those imports are used, but they give you some common things you can look up how to use.
What could it do? Well, not only what all of the existing filter UIs do, but also Timeline and Keyframes panels are written with the Shotcut QML Scripting API. Now, to fully understand and expand this you need to understand QML script, which is based on JavaScript. Gemini wrote, “The simplest way to describe QML is that it looks like JSON but acts like HTML and JavaScript had a baby.”
I concur. Keep this in mind: the non-JavaScript parts (i.e. Object { … }) map primarily to compiled C++ objects inside the application and its libraries. Not everything, but only what is made available. Then, property values can be JavaScript expressions. In the above, onClicked’s value is a JavaScript expression that calls a JavaScript function defined at the top. It is also possible to write a file with only JavaScript, import it, and invoke functions defined within it. And lastly, the QML object syntax does not only map strictly to C++ objects: You can define your own object with a QML file and include it another QML.
5 Likes
Quick question: could a custom filter iterate through the entire timeline (and then change a clip’s speed)?
I’ve been looking into making a script to change the speed of all the clips in the timeline but from a bit of trial and error (and the free copilot in vscode) it seems the filter panel doesn’t have access to the timeline context.
Yes it can access the timeline object, but AI might need the source code to achieve your particular goal. Not entirety sure that is possible either. It might be easier for it to apply a speed filter rather than the method through Properties.
Here is an editing script I had made previously to create timelines with large numbers of edits to test zoom or undo and redo.
chop-it-up.zip (2.1 KB)
If you want to use the Properties > Speed approach you need to generate XML using the clip’s resourceproperty for the file name, prepend timewarp:with a speed value, and use timeline.replace(). You use selection as my script does, or you can iterate tracks using the timeline.tracksRepeater (see qml/views/timeline/timeline.qml) to get a track object that corresponds to Track.qml inside that is another repeater for the track items, which are either clips, blanks, or transitions. timeline.trackAt()to get a track that has a clipAt()function. That object has the properties you see in MultitrackModel in the docs.
If you want to use the filter approach, by reviewing some code and docs, basically you need to select the clip using timeline.selection= and then attachedfiltersmodel.add(metadatamodel.get(index))where index you need to lookup by iterating the model using metadatamodel.count
1 Like
I don’t think this is possible in the current implementation: I managed to change one clip’s speed using your example by applying the script directly to a clip, but I can’t affect more than one clip this way, timeline.tracksRepeater (and most other functions I see in timeline.qml) is undefined for me in the ui.qml.
I thought I had a good workaround by using timeline.selectAll() then going through timeline.selection array one by one and get producer.resource this way but I can’t get the resource to do the speed change (for the timewarp: variant). I can indeed do a separate timeline.selection to go through every clip but as soon as the selection changes the filter UI is hidden so I get a lot of undefined and null calls and the timer is destroyed (or hidden/stopped, anyway, it doesn’t run even once).
Unless you have another idea (or confirm that timeline.tracksRepeater works and I’m doing something wrong) I’m giving up and next I’ll try adding a button directly into timeline.qml (I think… I’m hoping I don’t have to edit the .cpp so I can use the official release with just a quick edit) and manually edit the qml every time I need to change the speed value.
You are correct that tracksRepeater is locally scoped within timeline.qml and not exposed through TimelineDock. We are still learning how this scripting API can work. But there is a multitrack global singleton registered in the QML engine, and that should expose general Qt model properties and functions. See ListModel QML Type | Qt 6.12 . Now, MultitrackModel is not a ListModel, but both of these inherit from a Qt abstract model that has properties and invokable methods:
ListModel inherits from QAbstractListModel and provides its Q_INVOKABLE methods. You can, for example use QAbstractItemModel::index to retrieve a QModelIndex for a row and column.
The API requires more exploration and examples. Not everything is in our docs because they build on QML’s docs, which builds upon its C++ docs. It is a bit of a puzzle, and if you work with an AI, expect that you need to provide it some hints about this layering. As we try to write scripts, we need to think clearly about the best approach, diligently go in that direction, and make changes to expose things from the C++ level.
“Expose” means adding Q_PROPERTYs and Q_INVOKABLE to certain methods. That is exactly what we did to write the Timeline, Keyframes, and FIlters panels in QML. In addition, signals and slots are already exposed. But it is not prudent to simply expose everything. That would bloat Qt’s meta-object system and disregards information hiding principal.
Expect to make agent instructions or skills to help it. I will not have the time to write scripts on demand to figure out all of these things and make changes accordingly, at least in a short amount of time. It is not the highest priority. So, expect some learning, rough edges, digging, and time to mature.
No worries, I do not expect you to do the script for me, just wanted some quick pointers from experience. The batch speed changing idea is proving quite a bit more difficult that originally imagined but it is something I’ve been needing quite often so I thought it was a good exercise.
I did pivot to adding a small button in the timeline area so I have direct access to everything. And I got to a decent point as in I am now accessing each clip from my selection and replace it with something.
The current issue that I am stuck with is applying the timewarp in a correct way. I did try timewarp:<speed>:<resource> but the timeline.replace call requires a proper xml and so far I haven’t found a way to properly do it, I tried manually making up a basic xml and there is something that resembles a proper clip but after project reload it becomes invalid. I’m now looking into direcltly editing the clip I get from the trackat().clipat(), so yeah, there’s still a bit of work to do.
If I end up making it work properly I’ll go back and try to make it a filter-script and share it on the forum.
Make a project file with one clip with a speed change and view its XML.
1 Like
Yey, I got it working (as a timeline button) - interestingly, this one: <property name="shotcut:producer">avformat</property> was the missing piece (along with some other properties that were obviously containing timewarp in name).