/
macosx.cpp
183 lines (156 loc) · 5.7 KB
/
macosx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Pencil - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation;
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <QString>
#include <QStringList>
#include <QDir>
#include <QProcess>
#include <QProgressDialog>
#include <QSysInfo>
#include "object.h"
#include "editor.h"
#include "pencildef.h"
#include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h>
extern "C" {
// this is not declared in Carbon.h anymore, but it's in the framework
OSStatus
SetMouseCoalescingEnabled(
Boolean inNewState,
Boolean * outOldState);
}
extern "C" {
bool gIsMouseCoalecing = false;
void detectElCapitan()
{
if ( QSysInfo::macVersion() == QSysInfo::MV_10_11 )
{
gIsMouseCoalecing = true;
}
else
{
gIsMouseCoalecing = false;
}
}
void disableCoalescing()
{
SetMouseCoalescingEnabled(gIsMouseCoalecing, NULL);
}
void enableCoalescing()
{
SetMouseCoalescingEnabled(true, NULL);
}
}
bool Object::exportMovie( ExportMovieParameters parameters )
{
/*
if(!filePath.endsWith(".mov", Qt::CaseInsensitive))
{
filePath = filePath + ".mov";
}
qDebug() << "-------QuickTime------" << filePath << QDir::temp().absolutePath();
// --------- Export all the temporary frames ----------
QDir::temp().mkdir("pencil");
QString tempPath = QDir::tempPath()+"pencil/";
QProgressDialog progress("Exporting movie...", "Abort", 0, 100, NULL);
progress.setWindowModality(Qt::WindowModal);
progress.show();
//exportFrames1(startFrame, endFrame, view, currentLayer, exportSize, tempPath+"tmp", "png", 100, true, true, 2,&progress,50,fps,exportFps);
exportFrames1(startFrame, endFrame, view, currentLayer, exportSize, tempPath+"tmp", "jpg", 100, true, true, 2, &progress, 50, fps, exportFps);
qDebug() << "frames exported in temp directory";
// --------- Quicktime assemble call ----------
// --- locate the assembler ---
CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
kCFURLPOSIXPathStyle);
const char* pathPtr = CFStringGetCStringPtr(macPath,
CFStringGetSystemEncoding());
CFRelease(pluginRef);
CFRelease(macPath);
QString appPath = pathPtr;
// --- run the assembler ---
QProcess assemble;
QStringList args;
args << QString::number(endFrame+1) << tempPath+"tmp%03d.jpg" << QString::number(fps) << filePath;
assemble.start(appPath+"/Contents/Resources/assembler2",args);
assemble.waitForStarted();
assemble.waitForFinished();
qDebug() << "exit status " << assemble.exitStatus();
qDebug() << assemble.readAllStandardOutput();
qDebug() << assemble.readAllStandardError();
progress.setValue(100);
qDebug() << "QuickTime export done";
// --------- Clean up temp directory ---------
QDir dir(tempPath);
QStringList filtername("*.*");
QStringList entries = dir.entryList(filtername,QDir::Files,QDir::Type);
for(int i=0; i<entries.size(); i++)
dir.remove(entries[i]);
*/
return false;
}
void Editor::importMovie (QString filePath, int fps)
{
int i;
QSettings settings( PENCIL2D , PENCIL2D );
qDebug() << "-------IMPORT VIDEO------" << filePath;
// --------- Import all the temporary frames ----------
QDir::temp().mkdir("pencil");
QString tempPath = QDir::temp().absolutePath()+"/pencil/";
QProgressDialog progress("Importing movie...", "Abort", 0, 100, NULL);
progress.setWindowModality(Qt::WindowModal);
progress.show();
progress.setValue(10);
QProcess ffmpeg;
qDebug() << "ffmpeg -i \"" << filePath << "\" -r " << QString::number(fps) << " -f image2 \"" << tempPath << "tmp_import%4d.png\"";
ffmpeg.start("ffmpeg -i \"" + filePath + "\" -r " + QString::number(fps) + " -f image2 \"" + tempPath + "tmp_import%4d.png\"");
progress.setValue(20);
if (ffmpeg.waitForStarted() == true)
{
if (ffmpeg.waitForFinished() == true)
{
QByteArray sErr = ffmpeg.readAllStandardError();
if (sErr == "")
{qDebug() << "ERROR: Could not execute FFmpeg.";}
else
{
qDebug() << "stderr: " + ffmpeg.readAllStandardOutput();
qDebug() << "stdout: " << sErr;
}
}
else
{qDebug() << "ERROR: FFmpeg did not finish executing.";}
}
else
{qDebug() << "Please install FFMPEG: sudo apt-get install ffmpeg";}
progress.setValue(50);
QDir dir1(tempPath);
int nFiles = dir1.entryList().count();
i=1;
QString frameNumberString = QString::number(i);
while( frameNumberString.length() < 4) frameNumberString.prepend("0");
while (QFile::exists(tempPath+"tmp_import"+frameNumberString+".png"))
{
progress.setValue(50+i*50/nFiles);
if(i>1) scrubForward();
importImage(tempPath+"tmp_import"+frameNumberString+".png");
i++;
frameNumberString = QString::number(i);
while( frameNumberString.length() < 4) frameNumberString.prepend("0");
}
progress.setValue(100);
// --------- Clean up temp directory ---------
QDir dir(tempPath);
QStringList filtername("*.*");
QStringList entries = dir.entryList(filtername,QDir::Files,QDir::Type);
for(int i=0; i<entries.size(); i++)
dir.remove(entries[i]);
}