Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movie import #1258

Merged
merged 20 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2109f8f
Add movie importing features
scribblemaniac Aug 31, 2019
ce079a8
Add ffprobe to CI builds
scribblemaniac Aug 31, 2019
4218c7a
Detect failed movie video import
scribblemaniac Aug 31, 2019
1bb7f1b
Add cancel to movie import and audio mixing step of movie export
scribblemaniac Aug 31, 2019
036bcd3
Add cancel to movie audio import
scribblemaniac Aug 31, 2019
e8593f1
Add progress updates and cancel to numbered image sequence import
scribblemaniac Aug 31, 2019
5aa5fdc
Added support for many new audio formats
scribblemaniac Sep 7, 2019
45aaada
Create a Movies import format that matches all supported extensions
scribblemaniac Sep 14, 2019
52c2fb9
Make ffprobe optional by default and don't include by default
scribblemaniac Sep 14, 2019
3650d8a
Merge branch 'master' into movie-import
scribblemaniac Mar 4, 2020
0dc229c
Write to disk during movie import
scribblemaniac Mar 4, 2020
d458c10
Change ffmpeg-based duration detection
scribblemaniac Mar 4, 2020
3b4aa3a
Add some checks and TODOs to the movie importer
scribblemaniac Mar 4, 2020
055e626
Delete temporary folders on closing without saving
scribblemaniac Mar 4, 2020
9804aec
Merge branch 'master' into pr-1258-changes
MrStevns May 4, 2020
5a7257b
Move MovieImport Logic into MovieImporter class and decouple UI from …
MrStevns May 6, 2020
df12488
Rename verifyFFMPEG -> verifyFFmpegExists
MrStevns May 6, 2020
ea33310
Refactor movie importer...again
scribblemaniac May 7, 2020
1dc3ade
Fix blank dialog when cancelling movie import
scribblemaniac May 7, 2020
514f130
Remove unnecessary QProgressDialog reference in Editor
scribblemaniac May 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Write to disk during movie import
This change is so that all frames that have not been modified since
importing from a movie can be unloaded from memory and the frame
cache. Saving is done by copying files on the disk.

This should prevent out of control memory consumption during movie
import, and should make saving said frames very fast.
  • Loading branch information
scribblemaniac committed Mar 4, 2020
commit 0dc229c2d6a70ba60c52591169a28e67a05db21b
2 changes: 2 additions & 0 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ bool MainWindow2::saveObject(QString strSavedFileName)
mEditor->object()->setFilePath(strSavedFileName);
mEditor->object()->setModified(false);

mEditor->clearTemporary();

QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(LAST_PCLX_PATH, strSavedFileName);

Expand Down
38 changes: 30 additions & 8 deletions core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ void Editor::toogleOnionSkinType()
mPreferenceManager->set(SETTING::ONION_TYPE, newState);
}

void Editor::clearTemporary()
{
while(!mTemporaryDirs.isEmpty()) {
mTemporaryDirs.takeFirst()->remove();
}
}

Status Editor::setObject(Object* newObject)
{
if (newObject == nullptr)
Expand Down Expand Up @@ -926,12 +933,13 @@ bool Editor::importMovieVideo(QString filePath, int fps, QProgressDialog &progre
qDebug() << "-------IMPORT MOVIE VIDEO------" << filePath;

// --------- Import all the temporary frames ----------
QTemporaryDir tempDir;
if (!tempDir.isValid())
QTemporaryDir* tempDir = new QTemporaryDir();
if (!tempDir->isValid())
{
qDebug() << "Could not create a temporary folder";
return false;
}
mTemporaryDirs.append(tempDir);

QString ffmpegPath = ffmpegLocation();
if (!QFile::exists(ffmpegPath))
Expand Down Expand Up @@ -1009,7 +1017,7 @@ bool Editor::importMovieVideo(QString filePath, int fps, QProgressDialog &progre
QString strCmd = QString("\"%1\"").arg(ffmpegPath);
strCmd += QString(" -i \"%1\"").arg(filePath);
strCmd += QString(" -r %1").arg(fps);
strCmd += QString(" \"%1\"").arg(tempDir.filePath("%05d.png"));
strCmd += QString(" \"%1\"").arg(tempDir->filePath("%05d.png"));

Status st = MovieExporter::executeFFMpeg(strCmd, frames, [&progress](float f) {
progress.setValue(qFloor(qMin(f, 1.0f) * 50));
Expand All @@ -1024,19 +1032,33 @@ bool Editor::importMovieVideo(QString filePath, int fps, QProgressDialog &progre
if(progress.wasCanceled()) return true;
progress.setValue(50);
int i = 1;
frames = QDir(tempDir.path()).count();
QString currentFile(tempDir.filePath(QString("%1.png").arg(i, 5, 10, QChar('0'))));
frames = QDir(tempDir->path()).count();
QString currentFile(tempDir->filePath(QString("%1.png").arg(i, 5, 10, QChar('0'))));
QPoint imgTopLeft;
while (QFileInfo::exists(currentFile))
{
importBitmapImage(currentFile);
if(layer->keyExists(currentFrame())) {
importBitmapImage(currentFile);
}
else {
BitmapImage* bitmapImage = new BitmapImage(imgTopLeft, currentFile);
if(imgTopLeft.isNull()) {
imgTopLeft.setX(static_cast<int>(view()->getImportView().dx()) - bitmapImage->image()->width() / 2);
imgTopLeft.setY(static_cast<int>(view()->getImportView().dy()) - bitmapImage->image()->height() / 2);
bitmapImage->moveTopLeft(imgTopLeft);
}
layer->addKeyFrame(currentFrame(), bitmapImage);
layers()->notifyAnimationLengthChanged();
scrubTo(currentFrame() + 1);
}
if (progress.wasCanceled()) return true;
progress.setValue(qFloor(50 + i / static_cast<qreal>(frames) * 50));
QApplication::processEvents();
i++;
currentFile = tempDir.filePath(QString("%1.png").arg(i, 5, 10, QChar('0')));
currentFile = tempDir->filePath(QString("%1.png").arg(i, 5, 10, QChar('0')));
}

return QFileInfo::exists(tempDir.filePath("00001.png"));
return QFileInfo::exists(tempDir->filePath("00001.png"));
}

bool Editor::importMovieAudio(QString filePath, QProgressDialog &progress)
Expand Down
5 changes: 5 additions & 0 deletions core_lib/src/interface/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GNU General Public License for more details.
class QDragEnterEvent;
class QDropEvent;
class QProgressDialog;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too should be removed

class QTemporaryDir;
class Object;
class KeyFrame;
class LayerCamera;
Expand Down Expand Up @@ -173,6 +174,8 @@ class Editor : public QObject

void toogleOnionSkinType();

void clearTemporary();

void settingUpdated(SETTING);

void dontAskAutoSave(bool b) { mAutosaveNeverAskAgain = b; }
Expand Down Expand Up @@ -222,6 +225,8 @@ class Editor : public QObject
void makeConnections();
KeyFrame* addKeyFrame(int layerNumber, int frameNumber);

QList<QTemporaryDir*> mTemporaryDirs;

// backup
void clearUndoStack();
void updateAutoSaveCounter();
Expand Down