source:
smplayer/trunk/src/videopreview/async.diff@
113
Last change on this file since 113 was 113, checked in by , 15 years ago | |
---|---|
|
|
File size: 7.6 KB |
-
videopreview/main.cpp
47 47 */ 48 48 //vp.setAspectRatio( 2.35 ); 49 49 50 #if VIDEOPREVIEW_ASYNC 51 if (vp.showConfigDialog()) { 52 vp.createThumbnails(); 53 return a.exec(); 54 } 55 #else 50 56 if ( (vp.showConfigDialog()) && (vp.createThumbnails()) ) { 51 57 vp.show(); 52 58 vp.adjustWindowSize(); 53 59 return a.exec(); 54 60 } 55 61 #endif 56 62 return 0; 57 63 } -
videopreview/videopreview.cpp
105 105 my_layout->addWidget(button_box); 106 106 setLayout(my_layout); 107 107 108 #if VIDEOPREVIEW_ASYNC 109 process = new QProcess(this); 110 connect( process, SIGNAL(finished(int, QProcess::ExitStatus)), 111 this, SLOT(processFinished(int, QProcess::ExitStatus)) ); 108 112 113 connect( this, SIGNAL(finishedOk()), this, SLOT(workFinishedOK()) ); 114 connect( this, SIGNAL(finishedWithError()), this, SLOT(workFinishedWithError()) ); 115 #endif 116 109 117 QList<QByteArray> r_formats = QImageReader::supportedImageFormats(); 110 118 QString read_formats; 111 119 for (int n=0; n < r_formats.count(); n++) { … … 156 164 return "00000005.jpg"; 157 165 } 158 166 167 #if VIDEOPREVIEW_ASYNC 168 void VideoPreview::createThumbnails() { 169 clearThumbnails(); 170 error_message.clear(); 171 172 // Initalization 173 VideoInfo i = getInfo(mplayer_bin, prop.input_video); 174 int length = i.length; 175 176 if (length == 0) { 177 if (error_message.isEmpty()) error_message = tr("The length of the video is 0"); 178 emit finishedWithError(); 179 return; 180 } 181 182 // Create a temporary directory 183 QDir d(QDir::tempPath()); 184 if (!d.exists(output_dir)) { 185 if (!d.mkpath(output_dir)) { 186 qDebug("VideoPreview::extractImages: error: can't create '%s'", full_output_dir.toUtf8().constData()); 187 error_message = tr("The temporary directory (%1) can't be created").arg(full_output_dir); 188 emit finishedWithError(); 189 return; 190 } 191 } 192 193 displayVideoInfo(i); 194 195 // Let's begin 196 run.thumbnail_width = 0; 197 198 run.num_pictures = prop.n_cols * prop.n_rows; 199 length -= prop.initial_step; 200 run.s_step = length / run.num_pictures; 201 202 run.current_time = prop.initial_step; 203 204 canceled = false; 205 progress->setLabelText(tr("Creating thumbnails...")); 206 progress->setRange(0, run.num_pictures-1); 207 208 run.current_picture = 0; 209 progress->setValue( run.current_picture); 210 211 if (!runMplayer(run.current_time)) { 212 emit finishedWithError(); 213 } 214 } 215 216 void VideoPreview::processFinished(int exitCode, QProcess::ExitStatus exitStatus) { 217 qDebug("VideoPreview::processFinished"); 218 219 if (exitStatus != QProcess::NormalExit) { 220 emit finishedWithError(); 221 return; 222 } 223 224 // Continue processing 225 QString frame_picture = full_output_dir + "/" + framePicture(); 226 if (!QFile::exists(frame_picture)) { 227 error_message = tr("The file %1 doesn't exist").arg(frame_picture); 228 emit finishedWithError(); 229 return; 230 } 231 232 #if RENAME_PICTURES 233 QDir d(QDir::tempPath()); 234 QString extension = (extractFormat()==PNG) ? "png" : "jpg"; 235 QString output_file = output_dir + QString("/picture_%1.%2").arg(run.current_time, 8, 10, QLatin1Char('0')).arg(extension); 236 d.rename(output_dir + "/" + framePicture(), output_file); 237 #else 238 QString output_file = output_dir + "/" + framePicture(); 239 #endif 240 241 if (!addPicture(QDir::tempPath() +"/"+ output_file, run.current_picture, run.current_time)) { 242 emit finishedWithError(); 243 return; 244 } 245 246 run.current_time += run.s_step; 247 248 if (canceled) { 249 emit finishedOk(); 250 return; 251 } 252 253 // Next picture 254 run.current_picture++; 255 256 if (run.current_picture >= run.num_pictures) { 257 emit finishedOk(); 258 return; 259 } 260 261 progress->setValue( run.current_picture); 262 263 if (!runMplayer(run.current_time)) { 264 emit finishedWithError(); 265 } 266 } 267 268 void VideoPreview::workFinishedOK() { 269 qDebug("VideoPreview::workFinishedOK"); 270 271 show(); 272 adjustWindowSize(); 273 274 cleanDir(full_output_dir); 275 } 276 277 void VideoPreview::workFinishedWithError() { 278 qDebug("VideoPreview::workFinishedWithError"); 279 280 if (!error_message.isEmpty()) { 281 QMessageBox::critical(this, tr("Error"), 282 tr("The following error has occurred while creating the thumbnails:")+"\n"+ error_message ); 283 } 284 285 cleanDir(full_output_dir); 286 287 close(); 288 } 289 290 291 #else // VIDEOPREVIEW_ASYNC 292 159 293 bool VideoPreview::createThumbnails() { 160 294 clearThumbnails(); 161 295 error_message.clear(); … … 244 378 245 379 return true; 246 380 } 381 #endif // VIDEOPREVIEW_ASYNC 247 382 248 383 bool VideoPreview::runMplayer(int seek) { 249 384 QStringList args; … … 283 418 for (int n = 0; n < args.count(); n++) command = command + args[n] + " "; 284 419 qDebug("VideoPreview::runMplayer: command: %s", command.toUtf8().constData()); 285 420 421 #if VIDEOPREVIEW_ASYNC 422 #ifdef CD_TO_TEMP_DIR 423 process->setWorkingDirectory(full_output_dir); 424 qDebug("VideoPreview::runMplayer: changing working directory of the process to '%s'", full_output_dir.toUtf8().constData()); 425 #endif 426 process->start(mplayer_bin, args); 427 if (!process->waitForStarted()) { 428 qDebug("VideoPreview::runMplayer: error running process"); 429 error_message = tr("The mplayer process didn't run"); 430 return false; 431 } 432 #else // VIDEOPREVIEW_ASYNC 286 433 QProcess p; 287 434 #ifdef CD_TO_TEMP_DIR 288 435 p.setWorkingDirectory(full_output_dir); … … 294 441 error_message = tr("The mplayer process didn't run"); 295 442 return false; 296 443 } 444 #endif // VIDEOPREVIEW_ASYNC 297 445 298 446 return true; 299 447 } -
videopreview/videopreview.h
19 19 #ifndef _VIDEOPREVIEW_H_ 20 20 #define _VIDEOPREVIEW_H_ 21 21 22 #define VIDEOPREVIEW_ASYNC 0 23 22 24 #include <QWidget> 23 25 #include <QString> 24 26 #include <QList> 25 27 28 #if VIDEOPREVIEW_ASYNC 29 #include <QProcess> 30 #endif 31 26 32 class QProgressDialog; 27 33 class QGridLayout; 28 34 class QLabel; … … 90 96 void setExtractFormat( ExtractFormat format ) { prop.extract_format = format; }; 91 97 ExtractFormat extractFormat() { return prop.extract_format; }; 92 98 99 #if VIDEOPREVIEW_ASYNC 100 void createThumbnails(); 101 #else 93 102 bool createThumbnails(); 103 #endif 94 104 95 105 bool showConfigDialog(); 96 106 … … 106 116 void cancelPressed(); 107 117 void saveImage(); 108 118 119 #if VIDEOPREVIEW_ASYNC 120 void processFinished(int exitCode, QProcess::ExitStatus exitStatus); 121 void workFinishedOK(); 122 void workFinishedWithError(); 123 109 124 protected: 125 QProcess * process; 126 127 signals: 128 void finishedOk(); 129 void finishedWithError(); 130 #endif 131 132 protected: 133 #if !VIDEOPREVIEW_ASYNC 110 134 bool extractImages(); 135 #endif 111 136 bool runMplayer(int seek); 112 137 bool addPicture(const QString & filename, int num, int time); 113 138 void displayVideoInfo(const VideoInfo & i); … … 144 169 ExtractFormat extract_format; 145 170 } prop; 146 171 172 #if VIDEOPREVIEW_ASYNC 147 173 struct { 148 174 int thumbnail_width; 175 int num_pictures; 176 int s_step; 177 int current_time; 178 int current_picture; 149 179 } run; 180 #else 181 struct { 182 int thumbnail_width; 183 } run; 184 #endif 150 185 151 186 QString last_directory; 152 187 QString error_message; -
basegui.cpp
4022 4022 4023 4023 video_preview->setMplayerPath(pref->mplayer_bin); 4024 4024 4025 #if VIDEOPREVIEW_ASYNC 4026 if (video_preview->showConfigDialog()) { 4027 video_preview->createThumbnails(); 4028 } 4029 #else 4025 4030 if ( (video_preview->showConfigDialog()) && (video_preview->createThumbnails()) ) { 4026 4031 video_preview->show(); 4027 4032 video_preview->adjustWindowSize(); 4028 4033 } 4034 #endif 4029 4035 } 4030 4036 4031 4037 QNetworkProxy BaseGui::userProxy() {
Note:
See TracBrowser
for help on using the repository browser.