Add Python call to import image sequence as animation
ClosedPublic

Authored by scottpetrovic on Oct 20 2018, 3:11 PM.

Details

Reviewers
jounip
rempt
Group Reviewers
Krita
Summary

This adds a Python function to import animation frames. Right now the only way to do this is through the GUI. I am working on a plugin and this is something I don't think Krita can do right now with Python. It would save a step in the process for manually importing things.

This is useful with with plugins that might use ffmpeg or ffprobe to do external video/image related things.

Test Plan

You will need to use ffmpeg to create an image sequence in a folder that will be loaded in. Once you have that, start Krita and create a new document.

See in the below comments for the latest Python script I am running to call this.

Diff Detail

Repository
R37 Krita
Lint
Lint Skipped
Unit
Unit Tests Skipped
scottpetrovic created this revision.Oct 20 2018, 3:11 PM
Restricted Application added a project: Krita. · View Herald TranscriptOct 20 2018, 3:11 PM
scottpetrovic requested review of this revision.Oct 20 2018, 3:11 PM
rempt added a subscriber: rempt.Oct 20 2018, 3:37 PM
rempt added inline comments.
libs/libkis/Krita.cpp
353 ↗(On Diff #43973)

Getting the document that should receive the frames should be handled by the script, not in libkis, so scripts have more flexibility.

367 ↗(On Diff #43973)

Same here: this should also be done in the script.

384 ↗(On Diff #43973)

This should be moved into the Document class.

387 ↗(On Diff #43973)

And the script should check the status and do stuff, not the wrapper api.

I moved the function to the Document class and revised it a bit after talking with @rempt The one thing I wasn't sure with what to do was with the updater. It sounded like that could be extracted or removed somehow. I wasn't sure if that meant it needs a separate API call, or how that needs to be managed.

What I have seems to work though. I moved a lot of logic to the python script and removed quite a bit from this patch. This is the python script I am using now in scripter...

from krita import Extension
from os import listdir
from os.path import isfile, join

#need to put an animation into a document
activeDocument = Application.instance().activeDocument()

image_sequence_directory = "/home/scott/Desktop/art references/images/"

# get list of files in directory
imageFiles = [f for f in listdir(image_sequence_directory) if isfile(join(image_sequence_directory, f))]
imageFiles.sort() # make alphabetical


# get full path + filename of files to load
fullPaths = []
for image in imageFiles:
    fullPaths.append(image_sequence_directory + image)

step = 1
firstFrame = 0

# void importAnimation(const QList<QString> &files, int firstFrame, int stepSize);
activeDocument.importAnimation(fullPaths, firstFrame, step)
scottpetrovic edited the test plan for this revision. (Show Details)Oct 20 2018, 5:59 PM
rempt added inline comments.Oct 20 2018, 7:25 PM
libs/libkis/Document.cpp
849

We probablu need to check here that there's a mainwindow and that there's an active view and otherwise do without an updater: if passing a null pointer for the updater is a problem, we need to fix that inside Krita, too -- or use a dummy updater.

I updated the revision and added a couple null checks at the beginning for main window and the active view.

scottpetrovic marked an inline comment as done.Oct 21 2018, 1:23 PM
scottpetrovic added inline comments.
libs/libkis/Document.cpp
849

I added the null checks

rempt added inline comments.Oct 21 2018, 1:40 PM
libs/libkis/Document.cpp
857

I would pass 0 for the updater argument if there's no active window and view instead of returning 0 before doing the import.

I updated the updater logic a bit so it checks for two things, the active view and the file batch mode. My normal script still seems to work.

scottpetrovic marked an inline comment as done.Oct 21 2018, 3:36 PM
rempt accepted this revision.Oct 21 2018, 4:22 PM
This revision is now accepted and ready to land.Oct 21 2018, 4:22 PM
scottpetrovic closed this revision.Oct 21 2018, 4:46 PM

@rempt thanks for the reviews and help. Pushed out and closing this ticket.