mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
310 lines
7.6 KiB
Diff
310 lines
7.6 KiB
Diff
|
Index: videopreview/main.cpp
|
|||
|
===================================================================
|
|||
|
--- videopreview/main.cpp (revisi<73>n: 2543)
|
|||
|
+++ videopreview/main.cpp (copia de trabajo)
|
|||
|
@@ -47,11 +47,17 @@
|
|||
|
*/
|
|||
|
//vp.setAspectRatio( 2.35 );
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+ if (vp.showConfigDialog()) {
|
|||
|
+ vp.createThumbnails();
|
|||
|
+ return a.exec();
|
|||
|
+ }
|
|||
|
+#else
|
|||
|
if ( (vp.showConfigDialog()) && (vp.createThumbnails()) ) {
|
|||
|
vp.show();
|
|||
|
vp.adjustWindowSize();
|
|||
|
return a.exec();
|
|||
|
}
|
|||
|
-
|
|||
|
+#endif
|
|||
|
return 0;
|
|||
|
}
|
|||
|
Index: videopreview/videopreview.cpp
|
|||
|
===================================================================
|
|||
|
--- videopreview/videopreview.cpp (revisi<73>n: 2543)
|
|||
|
+++ videopreview/videopreview.cpp (copia de trabajo)
|
|||
|
@@ -105,7 +105,15 @@
|
|||
|
my_layout->addWidget(button_box);
|
|||
|
setLayout(my_layout);
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+ process = new QProcess(this);
|
|||
|
+ connect( process, SIGNAL(finished(int, QProcess::ExitStatus)),
|
|||
|
+ this, SLOT(processFinished(int, QProcess::ExitStatus)) );
|
|||
|
|
|||
|
+ connect( this, SIGNAL(finishedOk()), this, SLOT(workFinishedOK()) );
|
|||
|
+ connect( this, SIGNAL(finishedWithError()), this, SLOT(workFinishedWithError()) );
|
|||
|
+#endif
|
|||
|
+
|
|||
|
QList<QByteArray> r_formats = QImageReader::supportedImageFormats();
|
|||
|
QString read_formats;
|
|||
|
for (int n=0; n < r_formats.count(); n++) {
|
|||
|
@@ -156,6 +164,132 @@
|
|||
|
return "00000005.jpg";
|
|||
|
}
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+void VideoPreview::createThumbnails() {
|
|||
|
+ clearThumbnails();
|
|||
|
+ error_message.clear();
|
|||
|
+
|
|||
|
+ // Initalization
|
|||
|
+ VideoInfo i = getInfo(mplayer_bin, prop.input_video);
|
|||
|
+ int length = i.length;
|
|||
|
+
|
|||
|
+ if (length == 0) {
|
|||
|
+ if (error_message.isEmpty()) error_message = tr("The length of the video is 0");
|
|||
|
+ emit finishedWithError();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ // Create a temporary directory
|
|||
|
+ QDir d(QDir::tempPath());
|
|||
|
+ if (!d.exists(output_dir)) {
|
|||
|
+ if (!d.mkpath(output_dir)) {
|
|||
|
+ qDebug("VideoPreview::extractImages: error: can't create '%s'", full_output_dir.toUtf8().constData());
|
|||
|
+ error_message = tr("The temporary directory (%1) can't be created").arg(full_output_dir);
|
|||
|
+ emit finishedWithError();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ displayVideoInfo(i);
|
|||
|
+
|
|||
|
+ // Let's begin
|
|||
|
+ run.thumbnail_width = 0;
|
|||
|
+
|
|||
|
+ run.num_pictures = prop.n_cols * prop.n_rows;
|
|||
|
+ length -= prop.initial_step;
|
|||
|
+ run.s_step = length / run.num_pictures;
|
|||
|
+
|
|||
|
+ run.current_time = prop.initial_step;
|
|||
|
+
|
|||
|
+ canceled = false;
|
|||
|
+ progress->setLabelText(tr("Creating thumbnails..."));
|
|||
|
+ progress->setRange(0, run.num_pictures-1);
|
|||
|
+
|
|||
|
+ run.current_picture = 0;
|
|||
|
+ progress->setValue( run.current_picture);
|
|||
|
+
|
|||
|
+ if (!runMplayer(run.current_time)) {
|
|||
|
+ emit finishedWithError();
|
|||
|
+ }
|
|||
|
+}
|
|||
|
+
|
|||
|
+void VideoPreview::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
|
|||
|
+ qDebug("VideoPreview::processFinished");
|
|||
|
+
|
|||
|
+ if (exitStatus != QProcess::NormalExit) {
|
|||
|
+ emit finishedWithError();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ // Continue processing
|
|||
|
+ QString frame_picture = full_output_dir + "/" + framePicture();
|
|||
|
+ if (!QFile::exists(frame_picture)) {
|
|||
|
+ error_message = tr("The file %1 doesn't exist").arg(frame_picture);
|
|||
|
+ emit finishedWithError();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+
|
|||
|
+#if RENAME_PICTURES
|
|||
|
+ QDir d(QDir::tempPath());
|
|||
|
+ QString extension = (extractFormat()==PNG) ? "png" : "jpg";
|
|||
|
+ QString output_file = output_dir + QString("/picture_%1.%2").arg(run.current_time, 8, 10, QLatin1Char('0')).arg(extension);
|
|||
|
+ d.rename(output_dir + "/" + framePicture(), output_file);
|
|||
|
+#else
|
|||
|
+ QString output_file = output_dir + "/" + framePicture();
|
|||
|
+#endif
|
|||
|
+
|
|||
|
+ if (!addPicture(QDir::tempPath() +"/"+ output_file, run.current_picture, run.current_time)) {
|
|||
|
+ emit finishedWithError();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ run.current_time += run.s_step;
|
|||
|
+
|
|||
|
+ if (canceled) {
|
|||
|
+ emit finishedOk();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ // Next picture
|
|||
|
+ run.current_picture++;
|
|||
|
+
|
|||
|
+ if (run.current_picture >= run.num_pictures) {
|
|||
|
+ emit finishedOk();
|
|||
|
+ return;
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ progress->setValue( run.current_picture);
|
|||
|
+
|
|||
|
+ if (!runMplayer(run.current_time)) {
|
|||
|
+ emit finishedWithError();
|
|||
|
+ }
|
|||
|
+}
|
|||
|
+
|
|||
|
+void VideoPreview::workFinishedOK() {
|
|||
|
+ qDebug("VideoPreview::workFinishedOK");
|
|||
|
+
|
|||
|
+ show();
|
|||
|
+ adjustWindowSize();
|
|||
|
+
|
|||
|
+ cleanDir(full_output_dir);
|
|||
|
+}
|
|||
|
+
|
|||
|
+void VideoPreview::workFinishedWithError() {
|
|||
|
+ qDebug("VideoPreview::workFinishedWithError");
|
|||
|
+
|
|||
|
+ if (!error_message.isEmpty()) {
|
|||
|
+ QMessageBox::critical(this, tr("Error"),
|
|||
|
+ tr("The following error has occurred while creating the thumbnails:")+"\n"+ error_message );
|
|||
|
+ }
|
|||
|
+
|
|||
|
+ cleanDir(full_output_dir);
|
|||
|
+
|
|||
|
+ close();
|
|||
|
+}
|
|||
|
+
|
|||
|
+
|
|||
|
+#else // VIDEOPREVIEW_ASYNC
|
|||
|
+
|
|||
|
bool VideoPreview::createThumbnails() {
|
|||
|
clearThumbnails();
|
|||
|
error_message.clear();
|
|||
|
@@ -244,6 +378,7 @@
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
+#endif // VIDEOPREVIEW_ASYNC
|
|||
|
|
|||
|
bool VideoPreview::runMplayer(int seek) {
|
|||
|
QStringList args;
|
|||
|
@@ -283,6 +418,18 @@
|
|||
|
for (int n = 0; n < args.count(); n++) command = command + args[n] + " ";
|
|||
|
qDebug("VideoPreview::runMplayer: command: %s", command.toUtf8().constData());
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+ #ifdef CD_TO_TEMP_DIR
|
|||
|
+ process->setWorkingDirectory(full_output_dir);
|
|||
|
+ qDebug("VideoPreview::runMplayer: changing working directory of the process to '%s'", full_output_dir.toUtf8().constData());
|
|||
|
+ #endif
|
|||
|
+ process->start(mplayer_bin, args);
|
|||
|
+ if (!process->waitForStarted()) {
|
|||
|
+ qDebug("VideoPreview::runMplayer: error running process");
|
|||
|
+ error_message = tr("The mplayer process didn't run");
|
|||
|
+ return false;
|
|||
|
+ }
|
|||
|
+#else // VIDEOPREVIEW_ASYNC
|
|||
|
QProcess p;
|
|||
|
#ifdef CD_TO_TEMP_DIR
|
|||
|
p.setWorkingDirectory(full_output_dir);
|
|||
|
@@ -294,6 +441,7 @@
|
|||
|
error_message = tr("The mplayer process didn't run");
|
|||
|
return false;
|
|||
|
}
|
|||
|
+#endif // VIDEOPREVIEW_ASYNC
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
Index: videopreview/videopreview.h
|
|||
|
===================================================================
|
|||
|
--- videopreview/videopreview.h (revisi<73>n: 2543)
|
|||
|
+++ videopreview/videopreview.h (copia de trabajo)
|
|||
|
@@ -19,10 +19,16 @@
|
|||
|
#ifndef _VIDEOPREVIEW_H_
|
|||
|
#define _VIDEOPREVIEW_H_
|
|||
|
|
|||
|
+#define VIDEOPREVIEW_ASYNC 0
|
|||
|
+
|
|||
|
#include <QWidget>
|
|||
|
#include <QString>
|
|||
|
#include <QList>
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+#include <QProcess>
|
|||
|
+#endif
|
|||
|
+
|
|||
|
class QProgressDialog;
|
|||
|
class QGridLayout;
|
|||
|
class QLabel;
|
|||
|
@@ -90,7 +96,11 @@
|
|||
|
void setExtractFormat( ExtractFormat format ) { prop.extract_format = format; };
|
|||
|
ExtractFormat extractFormat() { return prop.extract_format; };
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+ void createThumbnails();
|
|||
|
+#else
|
|||
|
bool createThumbnails();
|
|||
|
+#endif
|
|||
|
|
|||
|
bool showConfigDialog();
|
|||
|
|
|||
|
@@ -106,8 +116,23 @@
|
|||
|
void cancelPressed();
|
|||
|
void saveImage();
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+ void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
|||
|
+ void workFinishedOK();
|
|||
|
+ void workFinishedWithError();
|
|||
|
+
|
|||
|
protected:
|
|||
|
+ QProcess * process;
|
|||
|
+
|
|||
|
+signals:
|
|||
|
+ void finishedOk();
|
|||
|
+ void finishedWithError();
|
|||
|
+#endif
|
|||
|
+
|
|||
|
+protected:
|
|||
|
+#if !VIDEOPREVIEW_ASYNC
|
|||
|
bool extractImages();
|
|||
|
+#endif
|
|||
|
bool runMplayer(int seek);
|
|||
|
bool addPicture(const QString & filename, int num, int time);
|
|||
|
void displayVideoInfo(const VideoInfo & i);
|
|||
|
@@ -144,9 +169,19 @@
|
|||
|
ExtractFormat extract_format;
|
|||
|
} prop;
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
struct {
|
|||
|
int thumbnail_width;
|
|||
|
+ int num_pictures;
|
|||
|
+ int s_step;
|
|||
|
+ int current_time;
|
|||
|
+ int current_picture;
|
|||
|
} run;
|
|||
|
+#else
|
|||
|
+ struct {
|
|||
|
+ int thumbnail_width;
|
|||
|
+ } run;
|
|||
|
+#endif
|
|||
|
|
|||
|
QString last_directory;
|
|||
|
QString error_message;
|
|||
|
Index: basegui.cpp
|
|||
|
===================================================================
|
|||
|
--- basegui.cpp (revisi<73>n: 2543)
|
|||
|
+++ basegui.cpp (copia de trabajo)
|
|||
|
@@ -4022,10 +4022,16 @@
|
|||
|
|
|||
|
video_preview->setMplayerPath(pref->mplayer_bin);
|
|||
|
|
|||
|
+#if VIDEOPREVIEW_ASYNC
|
|||
|
+ if (video_preview->showConfigDialog()) {
|
|||
|
+ video_preview->createThumbnails();
|
|||
|
+ }
|
|||
|
+#else
|
|||
|
if ( (video_preview->showConfigDialog()) && (video_preview->createThumbnails()) ) {
|
|||
|
video_preview->show();
|
|||
|
video_preview->adjustWindowSize();
|
|||
|
}
|
|||
|
+#endif
|
|||
|
}
|
|||
|
|
|||
|
QNetworkProxy BaseGui::userProxy() {
|