1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-18 16:32:33 +02:00

Add better video preview generation

This commit is contained in:
kelteseth 2018-08-25 00:44:58 +02:00
parent e6d047f4c1
commit 50dc0cddcf
2 changed files with 21 additions and 4 deletions

View File

@ -192,27 +192,37 @@ void Create::importVideo(QString title, QUrl videoPath, int timeStamp, int video
qDebug() << "Start converting video to thumbnail"; qDebug() << "Start converting video to thumbnail";
#ifdef QT_DEBUG #ifdef QT_DEBUG
pro.data()->setProgram("C:/msys64/mingw64/bin/ffmpeg.exe"); pro.data()->setProgram("C:/msys64/mingw64/bin/ffmpeg.exe");
#elif #endif
#ifdef QT_NO_DEBUG
pro.data()->setProgram("ffmpeg.exe"); pro.data()->setProgram("ffmpeg.exe");
#endif #endif
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewImage);
pro.data()->start(); pro.data()->start();
pro.data()->waitForFinished(-1); pro.data()->waitForFinished(-1);
qDebug() << "Done converting video to thumbnail" << pro.data()->readAllStandardOutput(); qDebug() << "Done converting video to thumbnail" << pro.data()->readAllStandardOutput();
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewImageFinished);
pro.data()->close(); pro.data()->close();
}); });
createVideoPreview(tmpPath,((videoDurationInSeconds * videoFrameRate) / 120));
}
void Create::createVideoPreview(QString path, int framesToSkip)
{
QtConcurrent::run([=]() { QtConcurrent::run([=]() {
QStringList args; QStringList args;
args.append("-y"); args.append("-y");
args.append("-i"); args.append("-i");
args.append(tmpPath); args.append(path);
args.append("-speed"); args.append("-speed");
args.append("ultrafast"); args.append("ultrafast");
args.append("-vf"); args.append("-vf");
// We allways want to have a 5 second clip via 24fps -> 120 // We allways want to have a 5 second clip via 24fps -> 120
// Divided by the number of frames we can skip (timeInSeconds * Framrate) // Divided by the number of frames we can skip (timeInSeconds * Framrate)
args.append("select='not(mod(n\\," + QString::number((videoDurationInSeconds * videoFrameRate) / 120) + "))',setpts=N/FRAME_RATE/TB,scale=480:-1"); args.append("select='not(mod(n\\," + QString::number(framesToSkip) + "))',setpts=N/FRAME_RATE/TB,scale=480:-1");
args.append("-an"); args.append("-an");
args.append("preview.mp4"); args.append("preview.mp4");
QScopedPointer<QProcess> pro(new QProcess()); QScopedPointer<QProcess> pro(new QProcess());
@ -221,12 +231,14 @@ void Create::importVideo(QString title, QUrl videoPath, int timeStamp, int video
qDebug() << "Start converting video to preview"; qDebug() << "Start converting video to preview";
#ifdef QT_DEBUG #ifdef QT_DEBUG
pro.data()->setProgram("C:/msys64/mingw64/bin/ffmpeg.exe"); pro.data()->setProgram("C:/msys64/mingw64/bin/ffmpeg.exe");
#elif #else
pro.data()->setProgram("ffmpeg.exe"); pro.data()->setProgram("ffmpeg.exe");
#endif #endif
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewVideo);
pro.data()->start(); pro.data()->start();
pro.data()->waitForFinished(-1); pro.data()->waitForFinished(-1);
qDebug() << "Done converting video to preview" << pro.data()->readAllStandardOutput(); qDebug() << "Done converting video to preview" << pro.data()->readAllStandardOutput();
emit localWorkshopCreationStatusChanged(LocalWorkshopCreationStatus::ConvertingPreviewVideoFinished);
pro.data()->close(); pro.data()->close();
}); });

View File

@ -22,6 +22,10 @@ enum Value {
CopyVideoFinished, CopyVideoFinished,
CopyImageFinished, CopyImageFinished,
CopyConfigFinished, CopyConfigFinished,
ConvertingPreviewImage,
ConvertingPreviewImageFinished,
ConvertingPreviewVideo,
ConvertingPreviewVideoFinished,
Finished, Finished,
ErrorFolder, ErrorFolder,
ErrorFolderCreation, ErrorFolderCreation,
@ -49,6 +53,7 @@ public slots:
void importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration); void importVideo(QString title, QUrl videoPath, QUrl previewPath, int videoDuration);
void importVideo(QString title, QUrl videoPath, int timeStamp, int videoDuration, int videoFrameRate); void importVideo(QString title, QUrl videoPath, int timeStamp, int videoDuration, int videoFrameRate);
void createVideoPreview(QString path, int framesToSkip);
private: private:
Settings* m_settings; Settings* m_settings;