Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
macosx.cpp
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2013-2017 Matt Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #include <QString>
18 #include <QStringList>
19 #include <QDir>
20 #include <QProcess>
21 #include <QProgressDialog>
22 #include <QSysInfo>
23 #include "object.h"
24 #include "editor.h"
25 #include "pencildef.h"
26 
27 #include <CoreFoundation/CoreFoundation.h>
28 #include <Carbon/Carbon.h>
29 
30 extern "C" {
31 // this is not declared in Carbon.h anymore, but it's in the framework
32 OSStatus
33 SetMouseCoalescingEnabled(
34  Boolean inNewState,
35  Boolean * outOldState);
36 }
37 
38 extern "C" {
39 
40 bool gIsMouseCoalecing = false;
41 
42 void detectWhichOSX()
43 {
44  QOperatingSystemVersion current = QOperatingSystemVersion::current();
45  if ( current >= QOperatingSystemVersion::OSXElCapitan )
46  {
47  gIsMouseCoalecing = true;
48  }
49  else
50  {
51  gIsMouseCoalecing = false;
52  }
53 }
54 
55 void disableCoalescing()
56 {
57  SetMouseCoalescingEnabled(gIsMouseCoalecing, NULL);
58 }
59 
60 void enableCoalescing()
61 {
62  SetMouseCoalescingEnabled(true, NULL);
63 }
64 
65 void Editor::importMovie (QString filePath, int fps)
66 {
67 
68  int i;
69  QSettings settings( PENCIL2D , PENCIL2D );
70 
71  qDebug() << "-------IMPORT VIDEO------" << filePath;
72 
73  // --------- Import all the temporary frames ----------
74  QDir::temp().mkdir("pencil");
75  QString tempPath = QDir::temp().absolutePath()+"/pencil/";
76 
77  QProgressDialog progress("Importing movie...", "Abort", 0, 100, NULL);
78  progress.setWindowModality(Qt::WindowModal);
79  progress.show();
80  progress.setValue(10);
81  QProcess ffmpeg;
82  qDebug() << "ffmpeg -i \"" << filePath << "\" -r " << QString::number(fps) << " -f image2 \"" << tempPath << "tmp_import%4d.png\"";
83  ffmpeg.start("ffmpeg -i \"" + filePath + "\" -r " + QString::number(fps) + " -f image2 \"" + tempPath + "tmp_import%4d.png\"");
84  progress.setValue(20);
85  if (ffmpeg.waitForStarted() == true)
86  {
87  if (ffmpeg.waitForFinished() == true)
88  {
89  QByteArray sErr = ffmpeg.readAllStandardError();
90  if (sErr == "")
91  {qDebug() << "ERROR: Could not execute FFmpeg.";}
92  else
93  {
94  qDebug() << "stderr: " + ffmpeg.readAllStandardOutput();
95  qDebug() << "stdout: " << sErr;
96  }
97  }
98  else
99  {qDebug() << "ERROR: FFmpeg did not finish executing.";}
100  }
101  else
102  {qDebug() << "Please install FFMPEG: sudo apt-get install ffmpeg";}
103  progress.setValue(50);
104  QDir dir1(tempPath);
105  int nFiles = dir1.entryList().count();
106  i=1;
107  QString frameNumberString = QString::number(i);
108  while( frameNumberString.length() < 4) frameNumberString.prepend("0");
109  while (QFile::exists(tempPath+"tmp_import"+frameNumberString+".png"))
110  {
111  progress.setValue(50+i*50/nFiles);
112  if(i>1) scrubForward();
113  importImage(tempPath+"tmp_import"+frameNumberString+".png");
114  i++;
115  frameNumberString = QString::number(i);
116  while( frameNumberString.length() < 4) frameNumberString.prepend("0");
117  }
118  progress.setValue(100);
119  // --------- Clean up temp directory ---------
120  QDir dir(tempPath);
121  QStringList filtername("*.*");
122  QStringList entries = dir.entryList(filtername,QDir::Files,QDir::Type);
123  for(int i=0; i<entries.size(); i++)
124  dir.remove(entries[i]);
125 }
126 
127 } // extern "C"