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