From d153d3bbf7f55a630a2bd2d44a9413acf4154c6b Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Mon, 28 Dec 2020 18:03:57 +0100 Subject: [PATCH] Add quality slider to import convert --- .../ImportVideoAndConvert/CreateWallpaper.qml | 11 ++-- .../CreateWallpaperInit.qml | 15 ++++++ ScreenPlay/src/create.cpp | 19 +++++-- ScreenPlay/src/create.h | 2 +- ScreenPlay/src/createimportvideo.cpp | 52 ++++++++++++------- ScreenPlay/src/createimportvideo.h | 14 ++--- 6 files changed, 77 insertions(+), 36 deletions(-) diff --git a/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaper.qml b/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaper.qml index 275a9029..8d10842c 100644 --- a/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaper.qml +++ b/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaper.qml @@ -21,21 +21,18 @@ Item { clip: true CreateWallpaperInit { - onNext: { + onNext: { root.wizardStarted() swipeView.currentIndex = 1 createWallpaperVideoImportConvert.codec = codec createWallpaperVideoImportConvert.filePath = filePath - ScreenPlay.create.createWallpaperStart(filePath,codec) + ScreenPlay.create.createWallpaperStart(filePath, codec, quality) } } CreateWallpaperVideoImportConvert { - id:createWallpaperVideoImportConvert - onAbort:root.wizardExited() + id: createWallpaperVideoImportConvert + onAbort: root.wizardExited() } CreateWallpaperResult {} } - - - } diff --git a/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaperInit.qml b/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaperInit.qml index 261ef878..df5687d7 100644 --- a/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaperInit.qml +++ b/ScreenPlay/qml/Create/Wizards/ImportVideoAndConvert/CreateWallpaperInit.qml @@ -14,6 +14,7 @@ Item { id: root signal next(var filePath, var codec) + property int quality: sliderQuality.slider.value ColumnLayout { spacing: 40 @@ -71,6 +72,19 @@ Item { } } } + Common.Slider { + id: sliderQuality + iconSource: "qrc:/assets/icons/icon_settings.svg" + headline: qsTr( + "Quality slider. Greater value means better quality.") + slider { + from: 4 + value: 50 + to: 63 + stepSize: 1 + } + Layout.preferredWidth: 400 + } } Button { @@ -89,6 +103,7 @@ Item { margins: 20 } } + Button { text: qsTr("Select file") highlighted: true diff --git a/ScreenPlay/src/create.cpp b/ScreenPlay/src/create.cpp index f4f50379..1f8a9668 100644 --- a/ScreenPlay/src/create.cpp +++ b/ScreenPlay/src/create.cpp @@ -45,7 +45,7 @@ Create::Create() /*! \brief Starts the process. */ -void Create::createWallpaperStart(QString videoPath, Create::VideoCodec codec) +void Create::createWallpaperStart(QString videoPath, Create::VideoCodec codec, const int quality) { clearFfmpegOutput(); videoPath = Util::toLocal(videoPath); @@ -61,11 +61,22 @@ void Create::createWallpaperStart(QString videoPath, Create::VideoCodec codec) return; } setWorkingDir(dir.path() + "/" + folderName); - QStringList codecs; - codecs.append(codec == Create::VideoCodec::VP8 ? "vp8" : "vp9"); + + QString target_codec; + switch (codec) { + case Create::VideoCodec::VP8: + target_codec = "vp8"; + break; + case Create::VideoCodec::VP9: + target_codec = "vp9"; + break; + case Create::VideoCodec::AV1: + target_codec = "av1"; + break; + } m_createImportVideoThread = new QThread(this); - m_createImportVideo = new CreateImportVideo(videoPath, workingDir(), codecs); + m_createImportVideo = new CreateImportVideo(videoPath, workingDir(), target_codec, quality); connect(m_createImportVideo, &CreateImportVideo::processOutput, this, [this](QString text) { appendFfmpegOutput(text + "\n"); }); diff --git a/ScreenPlay/src/create.h b/ScreenPlay/src/create.h index c7b2e15c..80318fd8 100644 --- a/ScreenPlay/src/create.h +++ b/ScreenPlay/src/create.h @@ -109,7 +109,7 @@ signals: public slots: - void createWallpaperStart(QString videoPath, Create::VideoCodec codec); + void createWallpaperStart(QString videoPath, Create::VideoCodec codec, const int quality); void saveWallpaper( QString title, diff --git a/ScreenPlay/src/createimportvideo.cpp b/ScreenPlay/src/createimportvideo.cpp index 0d46fdde..365490f0 100644 --- a/ScreenPlay/src/createimportvideo.cpp +++ b/ScreenPlay/src/createimportvideo.cpp @@ -28,12 +28,14 @@ CreateImportVideo::CreateImportVideo(QObject* parent) \brief Creates a CreateImportVideo object to be used in a different thread. A \a videoPath and a \a exportPath are needed for convertion. */ -CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& exportPath, const QStringList& codecs, QObject* parent) +CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& exportPath, const QString& codec, const int quality, QObject* parent) : QObject(parent) + , m_quality(quality) { + m_videoPath = videoPath; m_exportPath = exportPath; - m_codecs = codecs; + m_codec = codec; m_process = std::make_unique(this); m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + Util::executableEnding(); @@ -99,17 +101,31 @@ void CreateImportVideo::process() return; } - for (const auto& codec : qAsConst(m_codecs)) { - qInfo() << "createWallpaperVideo()"; - if (!createWallpaperVideo(codec) || QThread::currentThread()->isInterruptionRequested()) { - emit abortAndCleanup(); - return; - } + qInfo() << "createWallpaperVideo()"; + if (!createWallpaperVideo() || QThread::currentThread()->isInterruptionRequested()) { + emit abortAndCleanup(); + return; } emit createWallpaperStateChanged(ImportVideoState::Finished); } +void CreateImportVideo::processGif() +{ + qInfo() << "createWallpaperImageThumbnailPreview()"; + if (!createWallpaperImageThumbnailPreview() || QThread::currentThread()->isInterruptionRequested()) { + emit abortAndCleanup(); + return; + } + + qInfo() << "createWallpaperImagePreview()"; + if (!createWallpaperImagePreview() || QThread::currentThread()->isInterruptionRequested()) { + emit abortAndCleanup(); + return; + } + emit createWallpaperStateChanged(ImportVideoState::Finished); +} + /*! \brief Starts ffprobe and tries to parse the resulting json. If the video is a container that not contains the video length like webm or mkv @@ -568,7 +584,7 @@ bool CreateImportVideo::createWallpaperImagePreview() \li Generally broken. \endlist */ -bool CreateImportVideo::createWallpaperVideo(const QString& codec) +bool CreateImportVideo::createWallpaperVideo() { emit createWallpaperStateChanged(ImportVideoState::ConvertingVideo); @@ -601,16 +617,16 @@ bool CreateImportVideo::createWallpaperVideo(const QString& codec) args.append("-i"); args.append(m_videoPath); args.append("-c:v"); - if (codec == "vp8") { + if (m_codec == "vp8") args.append("libvpx"); - } - if (codec == "vp9") { + if (m_codec == "vp9") args.append("libvpx-vp9"); - } + if (m_codec == "av1") + args.append("libaom-av1"); args.append("-b:v"); args.append("0"); args.append("-crf"); - args.append("10"); + args.append(QString::number(m_quality)); args.append("-pass"); args.append("1"); @@ -635,16 +651,16 @@ bool CreateImportVideo::createWallpaperVideo(const QString& codec) args.append("-i"); args.append(m_videoPath); args.append("-c:v"); - if (codec == "vp8") + if (m_codec == "vp8") args.append("libvpx"); - if (codec == "vp9") + if (m_codec == "vp9") args.append("libvpx-vp9"); - if (codec == "av1") + if (m_codec == "av1") args.append("libaom-av1"); args.append("-b:v"); args.append("0"); args.append("-crf"); - args.append("10"); + args.append(QString::number(m_quality)); args.append("-pass"); args.append("2"); const QFileInfo file(m_videoPath); diff --git a/ScreenPlay/src/createimportvideo.h b/ScreenPlay/src/createimportvideo.h index c2d0c16c..00503f2f 100644 --- a/ScreenPlay/src/createimportvideo.h +++ b/ScreenPlay/src/createimportvideo.h @@ -61,7 +61,7 @@ class CreateImportVideo : public QObject { public: CreateImportVideo() { } CreateImportVideo(QObject* parent = nullptr); - explicit CreateImportVideo(const QString& videoPath, const QString& exportPath, const QStringList& codecs, QObject* parent = nullptr); + explicit CreateImportVideo(const QString& videoPath, const QString& exportPath, const QString& codec, const int quality, QObject* parent = nullptr); enum class ImportVideoState { Idle, @@ -118,8 +118,9 @@ public: QString m_videoPath; QString m_exportPath; QString m_format; - QStringList m_codecs; + QString m_codec; + const int m_quality = 50; int m_numberOfFrames { 0 }; int m_length { 0 }; int m_framerate { 0 }; @@ -138,12 +139,13 @@ signals: public slots: void process(); + void processGif(); bool createWallpaperInfo(); bool createWallpaperVideoPreview(); bool createWallpaperGifPreview(); bool createWallpaperImagePreview(); - bool createWallpaperVideo(const QString& codec); + bool createWallpaperVideo(); bool extractWallpaperAudio(); bool createWallpaperImageThumbnailPreview(); @@ -161,9 +163,9 @@ public slots: private: QString waitForFinished( - const QStringList& args, - const QProcess::ProcessChannelMode processChannelMode = QProcess::ProcessChannelMode::SeparateChannels, - const Executable executable = Executable::FFMPEG); + const QStringList& args, + const QProcess::ProcessChannelMode processChannelMode = QProcess::ProcessChannelMode::SeparateChannels, + const Executable executable = Executable::FFMPEG); bool analyzeWebmReadFrames(const QJsonObject& obj); bool analyzeVideo(const QJsonObject& obj);