From c100acaaa1b9559a1aea14516c02ef002a77e216 Mon Sep 17 00:00:00 2001 From: andreasGBL <29144928+andreasGBL@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:43:22 +0100 Subject: [PATCH] Video Slider bugfix, architecture restructured, thumbnail feature added --- CMakeLists.txt | 33 ++- Structs.h | 99 ------- VideoCutWindow/videocutwindow.cpp | 240 ----------------- VideoCutWindow/videocutwindow.h | 70 ----- VideoCutWindow/videoplayerwidget.h | 17 -- ffmpegwrapper.h | 32 --- filedropwidget.cpp | 133 ---------- filedropwidget.h | 39 --- include/VideoCutWindow/videocutwindow.h | 70 +++++ include/VideoCutWindow/videoplayerwidget.h | 18 ++ include/ffmpegwrapper.h | 32 +++ include/filedropwidget.h | 51 ++++ include/filepreviewwidget.h | 50 ++++ include/structs.h | 99 +++++++ include/videolowwindow.h | 55 ++++ src/VideoCutWindow/videocutwindow.cpp | 241 ++++++++++++++++++ .../VideoCutWindow}/videocutwindow.ui | 2 +- ffmpegwrapper.cpp => src/ffmpegwrapper.cpp | 10 +- src/filedropwidget.cpp | 159 ++++++++++++ main.cpp => src/main.cpp | 2 +- videolowwindow.cpp => src/videolowwindow.cpp | 136 +++++----- videolowwindow.ui => src/videolowwindow.ui | 30 ++- videolowwindow.h | 55 ---- 23 files changed, 890 insertions(+), 783 deletions(-) delete mode 100644 Structs.h delete mode 100644 VideoCutWindow/videocutwindow.cpp delete mode 100644 VideoCutWindow/videocutwindow.h delete mode 100644 VideoCutWindow/videoplayerwidget.h delete mode 100644 ffmpegwrapper.h delete mode 100644 filedropwidget.cpp delete mode 100644 filedropwidget.h create mode 100644 include/VideoCutWindow/videocutwindow.h create mode 100644 include/VideoCutWindow/videoplayerwidget.h create mode 100644 include/ffmpegwrapper.h create mode 100644 include/filedropwidget.h create mode 100644 include/filepreviewwidget.h create mode 100644 include/structs.h create mode 100644 include/videolowwindow.h create mode 100644 src/VideoCutWindow/videocutwindow.cpp rename {VideoCutWindow => src/VideoCutWindow}/videocutwindow.ui (99%) rename ffmpegwrapper.cpp => src/ffmpegwrapper.cpp (97%) create mode 100644 src/filedropwidget.cpp rename main.cpp => src/main.cpp (80%) rename videolowwindow.cpp => src/videolowwindow.cpp (58%) rename videolowwindow.ui => src/videolowwindow.ui (97%) delete mode 100644 videolowwindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b751e3..577496a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,28 +19,25 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# QtCreator supports the following variables for Android, which are identical to qmake Android variables. -# Check http://doc.qt.io/qt-5/deployment-android.html for more information. -# They need to be set before the find_package(Qt5 ...) call. - find_package(Qt5 COMPONENTS Widgets Multimedia MultimediaWidgets REQUIRED) - add_executable(${PROJECT_NAME} - main.cpp - videolowwindow.cpp - videolowwindow.h - videolowwindow.ui - filedropwidget.h - filedropwidget.cpp - ffmpegwrapper.h - ffmpegwrapper.cpp - Structs.h - VideoCutWindow/videocutwindow.ui - VideoCutWindow/videocutwindow.h - VideoCutWindow/videocutwindow.cpp - VideoCutWindow/videoplayerwidget.h + include/videolowwindow.h + include/filedropwidget.h + include/filepreviewwidget.h + include/ffmpegwrapper.h + include/structs.h + include/VideoCutWindow/videocutwindow.h + include/VideoCutWindow/videoplayerwidget.h + src/main.cpp + src/filedropwidget.cpp + src/ffmpegwrapper.cpp + src/videolowwindow.cpp + src/VideoCutWindow/videocutwindow.cpp + src/videolowwindow.ui + src/VideoCutWindow/videocutwindow.ui ) + if(NOT DEFINED HARDWARE_ACCELERATION_DEFAULT) set(HARDWARE_ACCELERATION_DEFAULT 0) endif() diff --git a/Structs.h b/Structs.h deleted file mode 100644 index e12e598..0000000 --- a/Structs.h +++ /dev/null @@ -1,99 +0,0 @@ -#pragma once - -#include -#include -#include - -struct Resolution { -public: - int width; - int height; -}; - -struct Codec { - std::string defaultName; - std::string NVIDIA; - std::string AMD; -}; - -struct Video { - QString filePath; - QTime length; -}; - -struct TrimSettings { - QTime start; - QTime end; - bool trim = false; -}; - -enum RESOLUTION_IDX { - RESOLUTION_AS_INPUT = 0, - K4 = 1, - p1080 = 2, - p720 = 3, - p480 = 4 -}; - -enum HARDWARE_ACCELERATION { - NONE = 0, - NVIDIA = 1, - AMD = 2 -}; - -Resolution const RESOLUTIONS[7] = { - { - 0, - 0 - }, - { - 3840, - 2160 - }, - { - 2560, - 1440 - }, - { - 1920, - 1080 - }, - { - 1280, - 720 - }, - { - 854, - 480 - }, - { - 426, - 240 - } -}; - -int const FRAMERATES[5] = { - 0, - 30, - 60, - 120, - 240 -}; - -enum CODEC_IDX { - H264 = 0, - HEVC = 1 -}; - -Codec const CODECS[2] = { - { - "libx264", - "h264_nvenc", - "h264_amf" - }, - { - "libx265", - "hevc_nvenc", - "hevc_amf" - } -}; diff --git a/VideoCutWindow/videocutwindow.cpp b/VideoCutWindow/videocutwindow.cpp deleted file mode 100644 index e9e1a75..0000000 --- a/VideoCutWindow/videocutwindow.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#include "videocutwindow.h" -#include "./ui_videocutwindow.h" -#include -#include -#include -#include -#include - -VideoCutWindow::VideoCutWindow(QWidget *parent) - : QWidget(parent) - , ui(new Ui::VideoCutWindow) -{ - ui->setupUi(this); - setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint); - mediaPlayer = new QMediaPlayer(this); - mediaPlayer->setVideoOutput(ui->PlayerWidget); - mediaPlayer->setAudioRole(QAudio::VideoRole); - mediaPlayer->setNotifyInterval(10); - ui->VideoSlider->setMaximum(videoSliderMax); - ui->VideoSlider->setTickInterval(0); - ui->VideoSlider->setPageStep(1); - ui->VideoSlider->setSingleStep(1); - ui->VideoSlider->repaint(); - connectSlots(); -} - -VideoCutWindow::~VideoCutWindow() -{ - delete ui; -} - -void VideoCutWindow::resetAll() { - QTime zero(0,0); - ui->CurrentTime->setTime(zero); - ui->EndTimeEdit->setTime(zero); - ui->StartTimeEdit->setTime(zero); - ui->videoLengthTimeEdit->setTime(zero); - ui->VideoSlider->setValue(0); -} - -void VideoCutWindow::loadVideo(Video const &video) -{ - currentVideo = &video; - QUrl url(video.filePath); - QMediaContent content(url); - mediaPlayer->setMedia(content); - ui->videoLengthTimeEdit->setTime(video.length); -} - -void VideoCutWindow::setInitialStartAndEnd(QTime const & start, QTime const & end) -{ - ui->StartTimeEdit->setTime(start); - ui->EndTimeEdit->setTime(end); -} - -void VideoCutWindow::closeWindow(QTime start, QTime end, bool cancelled) -{ - emit newCutInformation(start, end, cancelled); - mediaPlayer->pause(); - this->setVisible(false); -} - -QTime VideoCutWindow::getTimeForVideoPosition(qint64 pos) -{ - return getTimeFromMS(static_cast(pos)); -} - -QTime VideoCutWindow::getTimeFromMS(int ms) -{ - QTime zero(0,0); - QTime time = zero.addMSecs(ms); - return time; -} - -QTime VideoCutWindow::getCurrentPlaybackTime() -{ - return std::min(currentVideo->length, getTimeForVideoPosition(mediaPlayer->position())); -} - -void VideoCutWindow::updateVideoSlider(qint64 playbackMs) -{ - double vidMS = getVidMS(); - playbackMs = std::min(playbackMs, static_cast(vidMS)); - ui->VideoSlider->setValue(static_cast(static_cast(playbackMs)/vidMS * static_cast(videoSliderMax))); -} - -void VideoCutWindow::startTimeChanged(QTime t) -{ - QTime end = ui->EndTimeEdit->time(); - if(end < t){ - ui->EndTimeEdit->setTime(t); - } -} - -void VideoCutWindow::endTimeChanged(QTime t) -{ - QTime start = ui->StartTimeEdit->time(); - if(start > t){ - ui->StartTimeEdit->setTime(t); - } -} - -double VideoCutWindow::getVidMS() -{ - return currentVideo ? static_cast(currentVideo->length.msecsSinceStartOfDay()) : 1e308; -} - -void VideoCutWindow::confirm() -{ - closeWindow(ui->StartTimeEdit->time(), ui->EndTimeEdit->time(), false); -} - -void VideoCutWindow::cancel() -{ - closeWindow(ui->StartTimeEdit->time(), ui->EndTimeEdit->time(), true); -} - -void VideoCutWindow::positionUpdated(qint64 pos) -{ - pos = std::min(static_cast(getVidMS()), pos); - updateVideoSlider(pos); - QTime now = getTimeForVideoPosition(pos); - ui->CurrentTime->setTime(now); -} - -void VideoCutWindow::currentTimeEdited() -{ - timeChanged(ui->CurrentTime->time()); -} - -void VideoCutWindow::startTimeEdited() -{ - QTime current = ui->StartTimeEdit->time(); - if (currentVideo) { - if (current > currentVideo->length) - current = currentVideo->length; - } - if (current > ui->EndTimeEdit->time()) - ui->EndTimeEdit->setTime(current); - ui->StartTimeEdit->setTime(current); -} - -void VideoCutWindow::endTimeEdited() -{ - QTime current = ui->EndTimeEdit->time(); - if (currentVideo) { - if (current > currentVideo->length) - current = currentVideo->length; - } - if (current < ui->StartTimeEdit->time()) - ui->StartTimeEdit->setTime(current); - ui->EndTimeEdit->setTime(current); -} - -void VideoCutWindow::sliderReleased() -{ -// sliderPositionChanged(ui->VideoSlider->value()); - if(wasPlayingBeforeSliderWasPressed){ - mediaPlayer->play(); - wasPlayingBeforeSliderWasPressed = false; - } -} - -void VideoCutWindow::sliderPressed() -{ - if(mediaPlayer->state() == QMediaPlayer::PlayingState){ - wasPlayingBeforeSliderWasPressed = true; - } - mediaPlayer->pause(); -} - -void VideoCutWindow::sliderMoved(int pos) -{ - sliderPositionChanged(pos); -} - -void VideoCutWindow::timeChanged(QTime time) -{ - if(!currentVideo) - return; - time = std::min(time, currentVideo->length); - - ui->CurrentTime->setTime(time); - qint64 pos = time.msecsSinceStartOfDay(); - updateVideoSlider(pos); - mediaPlayer->setPosition(pos); -} - -void VideoCutWindow::sliderPositionChanged(int pos) -{ - double ratio = static_cast(pos) / static_cast(videoSliderMax); - double ms = ratio * getVidMS(); - QTime t = getTimeFromMS(static_cast(ms)); - timeChanged(t); -} - -void VideoCutWindow::setStart() -{ - QTime t = getCurrentPlaybackTime(); - ui->StartTimeEdit->setTime(t); - startTimeChanged(t); -} - -void VideoCutWindow::setEnd() -{ - QTime t = getCurrentPlaybackTime(); - ui->EndTimeEdit->setTime(t); - endTimeChanged(t); -} - -void VideoCutWindow::closeEvent(QCloseEvent *event) -{ - event->accept(); - closeWindow(ui->StartTimeEdit->time(),ui->EndTimeEdit->time(), true); -} - -void VideoCutWindow::connectSlots() -{ - QObject::connect(ui->confirmButton, &QPushButton::clicked, this, &VideoCutWindow::confirm); - QObject::connect(ui->cancelButton, &QPushButton::clicked, this, &VideoCutWindow::cancel); - - QObject::connect(ui->PlayButton, &QPushButton::clicked, mediaPlayer, &QMediaPlayer::play); - QObject::connect(ui->PauseButton, &QPushButton::clicked, mediaPlayer, &QMediaPlayer::pause); - - QObject::connect(mediaPlayer, &QMediaPlayer::positionChanged, this, &VideoCutWindow::positionUpdated); - - QObject::connect(ui->StartButton, &QPushButton::clicked, this, &VideoCutWindow::setStart); - QObject::connect(ui->EndButton, &QPushButton::clicked, this, &VideoCutWindow::setEnd); - - QObject::connect(ui->CurrentTime, &QTimeEdit::editingFinished, this, &VideoCutWindow::currentTimeEdited); - - QObject::connect(ui->StartTimeEdit, &QTimeEdit::editingFinished, this, &VideoCutWindow::startTimeEdited); - QObject::connect(ui->EndTimeEdit, &QTimeEdit::editingFinished, this, &VideoCutWindow::endTimeEdited); - - QObject::connect(ui->VideoSlider, &QSlider::sliderReleased, this, &VideoCutWindow::sliderReleased); - QObject::connect(ui->VideoSlider, &QSlider::sliderPressed, this, &VideoCutWindow::sliderPressed); - QObject::connect(ui->VideoSlider, &QSlider::sliderMoved, this, &VideoCutWindow::sliderMoved); - -} - diff --git a/VideoCutWindow/videocutwindow.h b/VideoCutWindow/videocutwindow.h deleted file mode 100644 index 1f93c8c..0000000 --- a/VideoCutWindow/videocutwindow.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef VIDEOCUTWINDOW_H -#define VIDEOCUTWINDOW_H - -#include -#include "Structs.h" -class QMediaPlayer; - -QT_BEGIN_NAMESPACE -namespace Ui { class VideoCutWindow; } -QT_END_NAMESPACE - -class VideoCutWindow : public QWidget -{ - Q_OBJECT - -public: - VideoCutWindow(QWidget *parent = nullptr); - ~VideoCutWindow(); - - void resetAll(); - void loadVideo(Video const & video); - void setInitialStartAndEnd(QTime const & start, QTime const & end); - void closeEvent(QCloseEvent *event) override; - -signals: - void newCutInformation(QTime start, QTime end, bool cancelled); -private slots: - - void confirm(); - void cancel(); - - void positionUpdated(qint64 pos); - void currentTimeEdited(); - void startTimeEdited(); - void endTimeEdited(); - - void sliderReleased(); - void sliderPressed(); - void sliderMoved(int pos); - - void setStart(); - void setEnd(); - - - -private: - void connectSlots(); - void closeWindow(QTime start, QTime end, bool cancelled); - - QTime getTimeForVideoPosition(qint64 pos); - QTime getTimeFromMS(int ms); - QTime getCurrentPlaybackTime(); - - void timeChanged(QTime time); - - void updateVideoSlider(qint64 playbackMs); - void sliderPositionChanged(int pos); - - void startTimeChanged(QTime t); - void endTimeChanged(QTime t); - - double getVidMS(); - - Ui::VideoCutWindow *ui; - QMediaPlayer *mediaPlayer; - Video const * currentVideo; - const int videoSliderMax = 1000; - bool wasPlayingBeforeSliderWasPressed = false; -}; -#endif // VIDEOCUTWINDOW_H diff --git a/VideoCutWindow/videoplayerwidget.h b/VideoCutWindow/videoplayerwidget.h deleted file mode 100644 index cb4b539..0000000 --- a/VideoCutWindow/videoplayerwidget.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -class QMimeData; - -class VideoPlayerWidget : public QVideoWidget -{ - Q_OBJECT -public: - VideoPlayerWidget(QWidget* parent = nullptr) - : QVideoWidget(parent){ - QPalette p = palette(); - p.setColor(QPalette::Window, Qt::black); - setPalette(p); - } -}; diff --git a/ffmpegwrapper.h b/ffmpegwrapper.h deleted file mode 100644 index e21f341..0000000 --- a/ffmpegwrapper.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include -class QString; -struct Resolution; -struct Codec; - -class FFMPEGWrapper -{ -public: - FFMPEGWrapper(); - bool exportFile(Video const &video, TrimSettings const & settings, double MBitRate, Resolution const &res, Codec const &codec, int HardwareAccelleration, int Framerate); -private: - QString getFileName(QString const &filePath); - QString getExportFileName(QString const &fileName); - QString getPath(QString const &filePath); - QString getExportFilePath(QString const &filePath); - - QString getTrimString(QTime const & start, QTime const & end, Video const & video); - QString getMBitRateString(double MBitRate); - QString getFramerateFilter(int Framerate); - QString getScaleFilterString(Resolution const &res, int HardwareAcceleration); - - QString getVideoCodecString(Codec const & codec, int HardwareAcceleration); - QString getAudioCodecString(bool canCopy); - QString getHardwareAccelerationString(int HardwareAcceleration, bool usesScaleFilter); - QString getInputFileString(QString const & filePath); - QString getOutputFileString(QString const & filePath); - - QString toTimeString(QTime const& t); - QString toDigits(int number, int digits); -}; - diff --git a/filedropwidget.cpp b/filedropwidget.cpp deleted file mode 100644 index 7074f1e..0000000 --- a/filedropwidget.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "filedropwidget.h" - -#include -#include -#include -#include - -#include -#include - -FileDropWidget::FileDropWidget(QWidget *parent) : QLabel(parent) -{ - setMinimumSize(200, 200); - setFrameStyle(QFrame::Sunken | QFrame::StyledPanel); - setAlignment(Qt::AlignCenter); - setAcceptDrops(true); - clear(); -} - -void FileDropWidget::setVideoLowWindowPointer(const VideoLowWindow *vlw) -{ - videoLowWindow = vlw; - connectSlots(); -} - -void FileDropWidget::connectSlots(){ - QObject::connect(this, &FileDropWidget::newVideoFileDropped, videoLowWindow, &VideoLowWindow::newVideoFile); -} - -void FileDropWidget::clear() -{ - if(!hasDrop) - setText(tr("")); - setBackgroundRole(QPalette::Window); -} - -void FileDropWidget::dragEnterEvent(QDragEnterEvent *event) -{ - if(acceptMimeType(event->mimeData())){ - event->acceptProposedAction(); - if(!hasDrop) - setText(tr("")); - setBackgroundRole(QPalette::Highlight); - } -} - -void FileDropWidget::dragMoveEvent(QDragMoveEvent *event) -{ - if(acceptMimeType(event->mimeData())) - event->acceptProposedAction(); -} - -void FileDropWidget::dragLeaveEvent(QDragLeaveEvent *event) -{ - clear(); - event->accept(); -} - -void FileDropWidget::dropEvent(QDropEvent *event) -{ - setBackgroundRole(QPalette::Window); - const QMimeData *mimeData = event->mimeData(); - if(acceptMimeType(mimeData)){ - QString path = mimeData->text().split("file:///")[1]; - std::cout<<"New File: "<&1"; //redirect stderr to stdout - QString probe(""); - int hours = 0, minutes = 0, seconds = 0, milliseconds = 0; - { - FILE * f; - f = _popen(cmd.c_str(), "r"); - char buff[128]; - if(f){ - while(fgets(buff, 128, f)){ - probe.append(buff); - } - } - } - std::cout<<"Probe:"<(timesplit[2].toDouble()); - milliseconds = static_cast((timesplit[2].toDouble() - static_cast(seconds)) * 100.0) * 10; - } - - - Video vid = {path, QTime(hours, minutes, seconds, milliseconds)}; - emit newVideoFileDropped(vid); - hasDrop = true; - } -} - -bool FileDropWidget::acceptMimeType(QMimeData const *mimeData) -{ - if(mimeData->hasText()){ - QString text = mimeData->text(); - if(text.startsWith("file:///")){ - QString filePath = text.split("file:///")[1]; - for (QString ending : acceptedFileTypes::ALL){ - if(text.endsWith("."+ending)) - return true; - } - } - } - return false; -} - -QString FileDropWidget::breakLines(QString str, int maxChars) -{ - if(maxChars < 0) - return str; - if(str.length() <= maxChars){ - return str; - }else{ - int length = str.length(); - QString newS = str; - for(int i = maxChars; i < length ; i+=maxChars){ - newS = newS.insert(i, "\n"); - } - return newS; - } -} diff --git a/filedropwidget.h b/filedropwidget.h deleted file mode 100644 index b490f52..0000000 --- a/filedropwidget.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -#include -#include "videolowwindow.h" - -class QMimeData; - -namespace acceptedFileTypes { - QString const MP4 = "mp4"; - QString const ALL[1] = {MP4}; -} - -class FileDropWidget : public QLabel -{ - Q_OBJECT -public: - explicit FileDropWidget(QWidget *parent = nullptr); - void setVideoLowWindowPointer(VideoLowWindow const * vlw); -public slots: - void clear(); - -signals: - void newVideoFileDropped(const Video filePath); - -protected: - void dragEnterEvent(QDragEnterEvent *event) override; - void dragMoveEvent(QDragMoveEvent *event) override; - void dragLeaveEvent(QDragLeaveEvent *event) override; - void dropEvent(QDropEvent *event) override; -private: - bool hasDrop = false; - bool acceptMimeType(QMimeData const * mimeData); - QString breakLines(QString str, int maxChars); - - VideoLowWindow const * videoLowWindow; - void connectSlots(); -}; - diff --git a/include/VideoCutWindow/videocutwindow.h b/include/VideoCutWindow/videocutwindow.h new file mode 100644 index 0000000..d2e698f --- /dev/null +++ b/include/VideoCutWindow/videocutwindow.h @@ -0,0 +1,70 @@ +#ifndef VIDEOCUTWINDOW_H +#define VIDEOCUTWINDOW_H + +#include +#include "include/structs.h" +class QMediaPlayer; + +QT_BEGIN_NAMESPACE +namespace Ui { class VideoCutWindow; } +QT_END_NAMESPACE + +class VideoCutWindow : public QWidget +{ + Q_OBJECT + +public: + VideoCutWindow(QWidget * parent = nullptr); + ~VideoCutWindow(); + + void resetAll(); + void loadVideo(Video const & video); + void setInitialStartAndEnd(QTime const & start, QTime const & end); + void closeEvent(QCloseEvent * event) override; + +signals: + void newCutInformation(QTime start, QTime end, bool cancelled); +private slots: + + void confirm(); + void cancel(); + + void positionUpdated(qint64 pos); + void currentTimeEdited(); + void startTimeEdited(); + void endTimeEdited(); + + void sliderReleased(); + void sliderPressed(); + void sliderMoved(int pos); + + void setStart(); + void setEnd(); + + + +private: + void connectSlots(); + void closeWindow(QTime start, QTime end, bool cancelled); + + QTime getTimeForVideoPosition(qint64 pos); + QTime getTimeFromMS(int ms); + QTime getCurrentPlaybackTime(); + + void timeChanged(QTime time); + + void updateVideoSlider(qint64 playbackMs); + void sliderPositionChanged(int pos); + + void startTimeChanged(QTime t); + void endTimeChanged(QTime t); + + double getVidMS(); + + Ui::VideoCutWindow * ui; + QMediaPlayer * mediaPlayer; + Video const * currentVideo; + const int videoSliderMax = 1000; + bool wasPlayingBeforeSliderWasPressed = false; +}; +#endif // VIDEOCUTWINDOW_H diff --git a/include/VideoCutWindow/videoplayerwidget.h b/include/VideoCutWindow/videoplayerwidget.h new file mode 100644 index 0000000..f1da5df --- /dev/null +++ b/include/VideoCutWindow/videoplayerwidget.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +class QMimeData; + +class VideoPlayerWidget : public QVideoWidget +{ + Q_OBJECT +public: + VideoPlayerWidget(QWidget * parent = nullptr) + : QVideoWidget(parent) + { + QPalette p = palette(); + p.setColor(QPalette::Window, Qt::black); + setPalette(p); + } +}; diff --git a/include/ffmpegwrapper.h b/include/ffmpegwrapper.h new file mode 100644 index 0000000..ab331cc --- /dev/null +++ b/include/ffmpegwrapper.h @@ -0,0 +1,32 @@ +#pragma once +#include "structs.h" +class QString; +struct Resolution; +struct Codec; + +class FFMPEGWrapper +{ +public: + FFMPEGWrapper(); + bool exportFile(Video const & video, TrimSettings const & settings, double MBitRate, Resolution const & res, Codec const & codec, int HardwareAccelleration, int Framerate); +private: + QString getFileName(QString const & filePath); + QString getExportFileName(QString const & fileName); + QString getPath(QString const & filePath); + QString getExportFilePath(QString const & filePath); + + QString getTrimString(QTime const & start, QTime const & end, Video const & video); + QString getMBitRateString(double MBitRate); + QString getFramerateFilter(int Framerate); + QString getScaleFilterString(Resolution const & res, int HardwareAcceleration); + + QString getVideoCodecString(Codec const & codec, int HardwareAcceleration); + QString getAudioCodecString(bool canCopy); + QString getHardwareAccelerationString(int HardwareAcceleration, bool usesScaleFilter); + QString getInputFileString(QString const & filePath); + QString getOutputFileString(QString const & filePath); + + QString toTimeString(QTime const & t); + QString toDigits(int number, int digits); +}; + diff --git a/include/filedropwidget.h b/include/filedropwidget.h new file mode 100644 index 0000000..f879973 --- /dev/null +++ b/include/filedropwidget.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include "structs.h" +#include "videolowwindow.h" + + +class QMimeData; + +namespace acceptedFileTypes { + QString const MP4("mp4"); + QString const ALL[1] = { MP4 }; +} + +class FileDropWidget : public QLabel +{ + Q_OBJECT +public: + explicit FileDropWidget(QWidget * parent = nullptr); + void setVideoLowWindowPointer(VideoLowWindow const * vlw); + void setPreviewLabelPointer(QLabel * preview) + { + previewLabel = preview; + } + void passDropEvent(QDropEvent * event) + { + dropEvent(event); + } +public slots: + void clear(); + +signals: + void newVideoFileDropped(const Video filePath); + +protected: + void dragEnterEvent(QDragEnterEvent * event) override; + void dragMoveEvent(QDragMoveEvent * event) override; + void dragLeaveEvent(QDragLeaveEvent * event) override; + void dropEvent(QDropEvent * event) override; + + bool acceptMimeType(QMimeData const * mimeData); + +private: + bool hasDrop = false; + + QString breakLines(QString str, int maxChars); + VideoLowWindow const * videoLowWindow; + QLabel * previewLabel; + void connectSlots(); +}; + diff --git a/include/filepreviewwidget.h b/include/filepreviewwidget.h new file mode 100644 index 0000000..1d4bebd --- /dev/null +++ b/include/filepreviewwidget.h @@ -0,0 +1,50 @@ +#pragma once + +#include "filedropwidget.h" +#include +#include + +class FilePreviewWidget : public FileDropWidget +{ + Q_OBJECT +public: + explicit FilePreviewWidget(QWidget * parent = nullptr) + : FileDropWidget(parent) + { + } + void setVideoLowWindowPointer(VideoLowWindow const * vlw) = delete; + void setPreviewLabelPointer(QLabel * preview) = delete; + + void setDropWidgetPointer(FileDropWidget * drop) + { + dropWidget = drop; + } + + +protected: + void dragEnterEvent(QDragEnterEvent * event) override + { + if (acceptMimeType(event->mimeData())) { + event->acceptProposedAction(); + } + } + void dragMoveEvent(QDragMoveEvent * event) override + { + if (acceptMimeType(event->mimeData())) + event->acceptProposedAction(); + } + void dragLeaveEvent(QDragLeaveEvent * event) override + { + event->accept(); + } + void dropEvent(QDropEvent * event) override + { + if (dropWidget) + dropWidget->passDropEvent(event); + }; + +private: + FileDropWidget * dropWidget = nullptr; + void connectSlots(); +}; + diff --git a/include/structs.h b/include/structs.h new file mode 100644 index 0000000..5a17bd2 --- /dev/null +++ b/include/structs.h @@ -0,0 +1,99 @@ +#pragma once + +#include +#include +#include + +struct Resolution { +public: + int width; + int height; +}; + +struct Codec { + std::string defaultName; + std::string NVIDIA; + std::string AMD; +}; + +struct Video { + QString filePath; + QTime length; +}; + +struct TrimSettings { + QTime start; + QTime end; + bool trim = false; +}; + +enum RESOLUTION_IDX { + RESOLUTION_AS_INPUT = 0, + K4 = 1, + p1080 = 2, + p720 = 3, + p480 = 4 +}; + +enum HARDWARE_ACCELERATION { + NONE = 0, + NVIDIA = 1, + AMD = 2 +}; + +Resolution const RESOLUTIONS[7] = { + { + 0, + 0 + }, + { + 3840, + 2160 + }, + { + 2560, + 1440 + }, + { + 1920, + 1080 + }, + { + 1280, + 720 + }, + { + 854, + 480 + }, + { + 426, + 240 + } +}; + +int const FRAMERATES[5] = { + 0, + 30, + 60, + 120, + 240 +}; + +enum CODEC_IDX { + H264 = 0, + HEVC = 1 +}; + +Codec const CODECS[2] = { + { + "libx264", + "h264_nvenc", + "h264_amf" + }, + { + "libx265", + "hevc_nvenc", + "hevc_amf" + } +}; diff --git a/include/videolowwindow.h b/include/videolowwindow.h new file mode 100644 index 0000000..441bb5b --- /dev/null +++ b/include/videolowwindow.h @@ -0,0 +1,55 @@ +#pragma once + +class QString; +#include "ffmpegwrapper.h" +#include "structs.h" +#include "VideoCutWindow/videocutwindow.h" +#include + + +QT_BEGIN_NAMESPACE +namespace Ui { class VideoLowWindow; } +QT_END_NAMESPACE + + + +class VideoLowWindow : public QMainWindow +{ + Q_OBJECT + +private slots: + void quickH264_2(); + void quickH264_4(); + void quickH264_8(); + void quickH264_16(); + void quickHEVC_2(); + void quickHEVC_4(); + void quickHEVC_8(); + void quickHEVC_16(); + void exportVideo(); + void reviewVideo(); + void gotCutInformation(QTime start, QTime end, bool cancelled); + void startTimeEdited(); + void endTimeEdited(); + +public slots: + void newVideoFile(Video vid); + +public: + VideoLowWindow(QWidget * parent = nullptr); + ~VideoLowWindow(); + void connectSlots(); + +private: + void quickH264(double MBitRate); + void quickHEVC(double MBitRate); + void handleExportExitCode(bool success, bool hardwareAcc); + + TrimSettings getTrimSettings(); + FFMPEGWrapper ffmpeg; + Ui::VideoLowWindow * ui; + VideoCutWindow * cutWindow; + Video * currentVideo = nullptr; +}; + + diff --git a/src/VideoCutWindow/videocutwindow.cpp b/src/VideoCutWindow/videocutwindow.cpp new file mode 100644 index 0000000..c3339c5 --- /dev/null +++ b/src/VideoCutWindow/videocutwindow.cpp @@ -0,0 +1,241 @@ +#include "include/VideoCutWindow/videocutwindow.h" +#include "./ui_videocutwindow.h" +#include +#include +#include +#include +#include + +VideoCutWindow::VideoCutWindow(QWidget * parent) + : QWidget(parent) + , ui(new Ui::VideoCutWindow) +{ + ui->setupUi(this); + setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint); + mediaPlayer = new QMediaPlayer(this); + mediaPlayer->setVideoOutput(ui->PlayerWidget); + mediaPlayer->setAudioRole(QAudio::VideoRole); + mediaPlayer->setNotifyInterval(10); + ui->VideoSlider->setMaximum(videoSliderMax); + ui->VideoSlider->setTickInterval(0); + ui->VideoSlider->setPageStep(1); + ui->VideoSlider->setSingleStep(1); + ui->VideoSlider->repaint(); + connectSlots(); +} + +VideoCutWindow::~VideoCutWindow() +{ + delete ui; +} + +void VideoCutWindow::resetAll() +{ + QTime zero(0, 0); + ui->CurrentTime->setTime(zero); + ui->EndTimeEdit->setTime(zero); + ui->StartTimeEdit->setTime(zero); + ui->videoLengthTimeEdit->setTime(zero); + ui->VideoSlider->setValue(0); +} + +void VideoCutWindow::loadVideo(Video const & video) +{ + currentVideo = &video; + QUrl url(video.filePath); + QMediaContent content(url); + mediaPlayer->setMedia(content); + ui->videoLengthTimeEdit->setTime(video.length); +} + +void VideoCutWindow::setInitialStartAndEnd(QTime const & start, QTime const & end) +{ + ui->StartTimeEdit->setTime(start); + ui->EndTimeEdit->setTime(end); +} + +void VideoCutWindow::closeWindow(QTime start, QTime end, bool cancelled) +{ + emit newCutInformation(start, end, cancelled); + mediaPlayer->pause(); + this->setVisible(false); +} + +QTime VideoCutWindow::getTimeForVideoPosition(qint64 pos) +{ + return getTimeFromMS(static_cast(pos)); +} + +QTime VideoCutWindow::getTimeFromMS(int ms) +{ + QTime zero(0, 0); + QTime time = zero.addMSecs(ms); + return time; +} + +QTime VideoCutWindow::getCurrentPlaybackTime() +{ + return std::min(currentVideo->length, getTimeForVideoPosition(mediaPlayer->position())); +} + +void VideoCutWindow::updateVideoSlider(qint64 playbackMs) +{ + double vidMS = getVidMS(); + playbackMs = std::min(playbackMs, static_cast(vidMS)); + ui->VideoSlider->setValue(static_cast(static_cast(playbackMs) / vidMS * static_cast(videoSliderMax))); +} + +void VideoCutWindow::startTimeChanged(QTime t) +{ + QTime end = ui->EndTimeEdit->time(); + if (end < t) { + ui->EndTimeEdit->setTime(t); + } +} + +void VideoCutWindow::endTimeChanged(QTime t) +{ + QTime start = ui->StartTimeEdit->time(); + if (start > t) { + ui->StartTimeEdit->setTime(t); + } +} + +double VideoCutWindow::getVidMS() +{ + return currentVideo ? static_cast(currentVideo->length.msecsSinceStartOfDay()) : 1e308; +} + +void VideoCutWindow::confirm() +{ + closeWindow(ui->StartTimeEdit->time(), ui->EndTimeEdit->time(), false); +} + +void VideoCutWindow::cancel() +{ + closeWindow(ui->StartTimeEdit->time(), ui->EndTimeEdit->time(), true); +} + +void VideoCutWindow::positionUpdated(qint64 pos) +{ + pos = std::min(static_cast(getVidMS()), pos); + updateVideoSlider(pos); + QTime now = getTimeForVideoPosition(pos); + ui->CurrentTime->setTime(now); +} + +void VideoCutWindow::currentTimeEdited() +{ + timeChanged(ui->CurrentTime->time()); +} + +void VideoCutWindow::startTimeEdited() +{ + QTime current = ui->StartTimeEdit->time(); + if (currentVideo) { + if (current > currentVideo->length) + current = currentVideo->length; + } + if (current > ui->EndTimeEdit->time()) + ui->EndTimeEdit->setTime(current); + ui->StartTimeEdit->setTime(current); +} + +void VideoCutWindow::endTimeEdited() +{ + QTime current = ui->EndTimeEdit->time(); + if (currentVideo) { + if (current > currentVideo->length) + current = currentVideo->length; + } + if (current < ui->StartTimeEdit->time()) + ui->StartTimeEdit->setTime(current); + ui->EndTimeEdit->setTime(current); +} + +void VideoCutWindow::sliderReleased() +{ + // sliderPositionChanged(ui->VideoSlider->value()); + if (wasPlayingBeforeSliderWasPressed) { + mediaPlayer->play(); + wasPlayingBeforeSliderWasPressed = false; + } +} + +void VideoCutWindow::sliderPressed() +{ + if (mediaPlayer->state() == QMediaPlayer::PlayingState) { + wasPlayingBeforeSliderWasPressed = true; + } + mediaPlayer->pause(); +} + +void VideoCutWindow::sliderMoved(int pos) +{ + sliderPositionChanged(pos); +} + +void VideoCutWindow::timeChanged(QTime time) +{ + if (!currentVideo) + return; + time = std::min(time, currentVideo->length); + + ui->CurrentTime->setTime(time); + qint64 pos = time.msecsSinceStartOfDay(); + updateVideoSlider(pos); + mediaPlayer->setPosition(pos); +} + +void VideoCutWindow::sliderPositionChanged(int pos) +{ + double ratio = static_cast(pos) / static_cast(videoSliderMax - 1); + double ms = ratio * getVidMS(); + QTime t = getTimeFromMS(static_cast(ms)); + timeChanged(t); +} + +void VideoCutWindow::setStart() +{ + QTime t = getCurrentPlaybackTime(); + ui->StartTimeEdit->setTime(t); + startTimeChanged(t); +} + +void VideoCutWindow::setEnd() +{ + QTime t = getCurrentPlaybackTime(); + ui->EndTimeEdit->setTime(t); + endTimeChanged(t); +} + +void VideoCutWindow::closeEvent(QCloseEvent * event) +{ + event->accept(); + closeWindow(ui->StartTimeEdit->time(), ui->EndTimeEdit->time(), true); +} + +void VideoCutWindow::connectSlots() +{ + QObject::connect(ui->confirmButton, &QPushButton::clicked, this, &VideoCutWindow::confirm); + QObject::connect(ui->cancelButton, &QPushButton::clicked, this, &VideoCutWindow::cancel); + + QObject::connect(ui->PlayButton, &QPushButton::clicked, mediaPlayer, &QMediaPlayer::play); + QObject::connect(ui->PauseButton, &QPushButton::clicked, mediaPlayer, &QMediaPlayer::pause); + + QObject::connect(mediaPlayer, &QMediaPlayer::positionChanged, this, &VideoCutWindow::positionUpdated); + + QObject::connect(ui->StartButton, &QPushButton::clicked, this, &VideoCutWindow::setStart); + QObject::connect(ui->EndButton, &QPushButton::clicked, this, &VideoCutWindow::setEnd); + + QObject::connect(ui->CurrentTime, &QTimeEdit::editingFinished, this, &VideoCutWindow::currentTimeEdited); + + QObject::connect(ui->StartTimeEdit, &QTimeEdit::editingFinished, this, &VideoCutWindow::startTimeEdited); + QObject::connect(ui->EndTimeEdit, &QTimeEdit::editingFinished, this, &VideoCutWindow::endTimeEdited); + + QObject::connect(ui->VideoSlider, &QSlider::sliderReleased, this, &VideoCutWindow::sliderReleased); + QObject::connect(ui->VideoSlider, &QSlider::sliderPressed, this, &VideoCutWindow::sliderPressed); + QObject::connect(ui->VideoSlider, &QSlider::sliderMoved, this, &VideoCutWindow::sliderMoved); + +} + diff --git a/VideoCutWindow/videocutwindow.ui b/src/VideoCutWindow/videocutwindow.ui similarity index 99% rename from VideoCutWindow/videocutwindow.ui rename to src/VideoCutWindow/videocutwindow.ui index bf9b70e..fe272dd 100644 --- a/VideoCutWindow/videocutwindow.ui +++ b/src/VideoCutWindow/videocutwindow.ui @@ -256,7 +256,7 @@ VideoPlayerWidget QWidget -
VideoCutWindow/videoplayerwidget.h
+
include/VideoCutWindow/videoplayerwidget.h
1
diff --git a/ffmpegwrapper.cpp b/src/ffmpegwrapper.cpp similarity index 97% rename from ffmpegwrapper.cpp rename to src/ffmpegwrapper.cpp index 40d5732..2a82bab 100644 --- a/ffmpegwrapper.cpp +++ b/src/ffmpegwrapper.cpp @@ -1,9 +1,9 @@ -#include "ffmpegwrapper.h" +#include "../include/ffmpegwrapper.h" #include #include -#include "Structs.h" +#include "include/structs.h" #include #include @@ -28,7 +28,7 @@ bool FFMPEGWrapper::exportFile(const Video & video, const TrimSettings & setting QString cmd = "ffmpeg -y "; //options part 1 QString trimming = getTrimString(settings.start, settings.end, video); - + QString inputFile = getInputFileString(filePath); //filters @@ -37,7 +37,7 @@ bool FFMPEGWrapper::exportFile(const Video & video, const TrimSettings & setting QString scaleFilter = getScaleFilterString(res, HardwareAccelleration); //options part2 - QString audioCodec = getAudioCodecString(settings.start == QTime(0,0) || !settings.trim); + QString audioCodec = getAudioCodecString(settings.start == QTime(0, 0) || !settings.trim); QString videoCodec = getVideoCodecString(codec, HardwareAccelleration); QString bitrate = getMBitRateString(MBitRate); QString outputFile = getOutputFileString(expFilePath); @@ -197,7 +197,7 @@ QString FFMPEGWrapper::toDigits(int number, int digits) int temp = 10; QString string(""); for (int i = 0; i < digits - 1; i++) { - if(number < temp){ + if (number < temp) { string += "0"; } temp *= 10; diff --git a/src/filedropwidget.cpp b/src/filedropwidget.cpp new file mode 100644 index 0000000..93c066d --- /dev/null +++ b/src/filedropwidget.cpp @@ -0,0 +1,159 @@ +#include "include/filedropwidget.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +FileDropWidget::FileDropWidget(QWidget * parent) : QLabel(parent) +{ + setMinimumSize(200, 200); + setFrameStyle(QFrame::Sunken | QFrame::StyledPanel); + setAlignment(Qt::AlignCenter); + setAcceptDrops(true); + clear(); +} + + + +void FileDropWidget::setVideoLowWindowPointer(const VideoLowWindow * vlw) +{ + videoLowWindow = vlw; + connectSlots(); +} + +void FileDropWidget::connectSlots() +{ + QObject::connect(this, &FileDropWidget::newVideoFileDropped, videoLowWindow, &VideoLowWindow::newVideoFile); +} + +void FileDropWidget::clear() +{ + if (!hasDrop) + setText(tr("")); + setBackgroundRole(QPalette::Window); +} + +void FileDropWidget::dragEnterEvent(QDragEnterEvent * event) +{ + if (acceptMimeType(event->mimeData())) { + event->acceptProposedAction(); + if (!hasDrop) + setText(tr("")); + setBackgroundRole(QPalette::Highlight); + } +} + +void FileDropWidget::dragMoveEvent(QDragMoveEvent * event) +{ + if (acceptMimeType(event->mimeData())) + event->acceptProposedAction(); +} + +void FileDropWidget::dragLeaveEvent(QDragLeaveEvent * event) +{ + clear(); + event->accept(); +} + +void FileDropWidget::dropEvent(QDropEvent * event) +{ + setBackgroundRole(QPalette::Window); + const QMimeData * mimeData = event->mimeData(); + if (acceptMimeType(mimeData)) { + QString path = mimeData->text().split("file:///")[1]; + std::cout << "New File: " << path.toStdString() << std::endl; + setText(tr(breakLines(path, 40).toStdString().c_str())); + std::string cmd = "ffprobe.exe \"" + path.toStdString() + "\" 2>&1"; //redirect stderr to stdout + QString probe(""); + int hours = 0, minutes = 0, seconds = 0, milliseconds = 0; + auto probeCall = std::async(std::launch::async, [&] { + { + FILE * f; + f = _popen(cmd.c_str(), "r"); + char buff[128]; + if (f) { + while (fgets(buff, 128, f)) { + probe.append(buff); + } + } + } + // std::cout<<"Probe:"<(timesplit[2].toDouble()); + milliseconds = static_cast((timesplit[2].toDouble() - static_cast(seconds)) * 100.0) * 10; + } + }); + QString tempFolder("VideoLow.tmp"); + QDir::temp().mkdir(tempFolder); + QString thumbnail = QDir::tempPath()+QString("/"+tempFolder+"/thumb.jpg"); + + cmd = "ffmpeg -y -i \"" + path.toStdString() + "\" -ss 00:00:00.000 -vf \"scale=600:600:force_original_aspect_ratio=decrease\" -vframes 1 \"" + thumbnail.toStdString() + "\" 2>&1"; //redirect stderr to stdout + QString thumb; + { + FILE * f; + f = _popen(cmd.c_str(), "r"); + char buff[128]; + if (f) { + while (fgets(buff, 128, f)) { + thumb.append(buff); + } + } + } + // std::cout<setPixmap(m.scaled(previewLabel->width(), previewLabel->height(), Qt::KeepAspectRatio)); + probeCall.wait(); + Video vid = { path, QTime(hours, minutes, seconds, milliseconds) }; + emit newVideoFileDropped(vid); + hasDrop = true; + } +} + +bool FileDropWidget::acceptMimeType(QMimeData const * mimeData) +{ + if (mimeData->hasText()) { + QString text = mimeData->text(); + if (text.startsWith("file:///")) { + QString filePath = text.split("file:///")[1]; + for (QString ending : acceptedFileTypes::ALL) { + if (text.endsWith("." + ending)) + return true; + } + } + } + return false; +} + +QString FileDropWidget::breakLines(QString str, int maxChars) +{ + if (maxChars < 0) + return str; + if (str.length() <= maxChars) { + return str; + } + else { + int length = str.length(); + QString newS = str; + for (int i = maxChars; i < length; i += maxChars) { + newS = newS.insert(i, "\n"); + } + return newS; + } +} diff --git a/main.cpp b/src/main.cpp similarity index 80% rename from main.cpp rename to src/main.cpp index b510e92..4d098e2 100644 --- a/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "videolowwindow.h" +#include "include/videolowwindow.h" #include diff --git a/videolowwindow.cpp b/src/videolowwindow.cpp similarity index 58% rename from videolowwindow.cpp rename to src/videolowwindow.cpp index 254649d..e059e3f 100644 --- a/videolowwindow.cpp +++ b/src/videolowwindow.cpp @@ -3,7 +3,7 @@ #include -#include "Structs.h" +#include "include/structs.h" #include @@ -14,11 +14,13 @@ VideoLowWindow::VideoLowWindow(QWidget * parent) , ui(new Ui::VideoLowWindow) { ui->setupUi(this); - ui->HardwareAccelerationComboBox->setCurrentIndex(HARDWARE_ACCELERATION_DEFAULT); - ui->HardwareAccelerationQuickComboBox->setCurrentIndex(HARDWARE_ACCELERATION_DEFAULT); + ui->HardwareAccelerationComboBox->setCurrentIndex(HARDWARE_ACCELERATION_DEFAULT); + ui->HardwareAccelerationQuickComboBox->setCurrentIndex(HARDWARE_ACCELERATION_DEFAULT); ui->HardwareAccelerationComboBox->update(); ui->DropWidget->setVideoLowWindowPointer(this); - cutWindow = new VideoCutWindow(this); + ui->DropWidget->setPreviewLabelPointer(ui->PreviewLabel); + ui->PreviewLabel->setDropWidgetPointer(ui->DropWidget); + cutWindow = new VideoCutWindow(this); connectSlots(); setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint); this->statusBar()->setSizeGripEnabled(false); @@ -27,9 +29,9 @@ VideoLowWindow::VideoLowWindow(QWidget * parent) VideoLowWindow::~VideoLowWindow() { delete ui; - if(currentVideo) - delete currentVideo; - delete cutWindow; + if (currentVideo) + delete currentVideo; + delete cutWindow; } void VideoLowWindow::connectSlots() @@ -46,44 +48,44 @@ void VideoLowWindow::connectSlots() QObject::connect(ui->ExportButton, &QPushButton::clicked, this, &VideoLowWindow::exportVideo); - QObject::connect(ui->reviewVideoButton, &QPushButton::clicked, this, &VideoLowWindow::reviewVideo); - QObject::connect(cutWindow, &VideoCutWindow::newCutInformation, this, &VideoLowWindow::gotCutInformation); + QObject::connect(ui->reviewVideoButton, &QPushButton::clicked, this, &VideoLowWindow::reviewVideo); + QObject::connect(cutWindow, &VideoCutWindow::newCutInformation, this, &VideoLowWindow::gotCutInformation); - QObject::connect(ui->startTimeEdit, &QTimeEdit::editingFinished, this, &VideoLowWindow::startTimeEdited); - QObject::connect(ui->EndTimeEdit, &QTimeEdit::editingFinished, this, &VideoLowWindow::endTimeEdited); + QObject::connect(ui->startTimeEdit, &QTimeEdit::editingFinished, this, &VideoLowWindow::startTimeEdited); + QObject::connect(ui->EndTimeEdit, &QTimeEdit::editingFinished, this, &VideoLowWindow::endTimeEdited); } void VideoLowWindow::quickH264(double MBitRate) { - if (currentVideo) + if (currentVideo) handleExportExitCode( ffmpeg.exportFile( - *currentVideo, - getTrimSettings(), - MBitRate, + *currentVideo, + getTrimSettings(), + MBitRate, RESOLUTIONS[RESOLUTION_IDX::RESOLUTION_AS_INPUT], CODECS[CODEC_IDX::H264], ui->HardwareAccelerationQuickComboBox->currentIndex(), - FRAMERATES[ui->FramerateQuickComboBox->currentIndex()] - ), - ui->HardwareAccelerationQuickComboBox->currentIndex() != 0 + FRAMERATES[ui->FramerateQuickComboBox->currentIndex()] + ), + ui->HardwareAccelerationQuickComboBox->currentIndex() != 0 ); } void VideoLowWindow::quickHEVC(double MBitRate) { - if (currentVideo) { + if (currentVideo) { handleExportExitCode( ffmpeg.exportFile( - *currentVideo, - getTrimSettings(), + *currentVideo, + getTrimSettings(), MBitRate, RESOLUTIONS[RESOLUTION_IDX::RESOLUTION_AS_INPUT], CODECS[CODEC_IDX::HEVC], ui->HardwareAccelerationQuickComboBox->currentIndex(), FRAMERATES[ui->FramerateQuickComboBox->currentIndex()] - ), - ui->HardwareAccelerationQuickComboBox->currentIndex() != 0 + ), + ui->HardwareAccelerationQuickComboBox->currentIndex() != 0 ); } @@ -101,15 +103,15 @@ void VideoLowWindow::handleExportExitCode(bool success, bool hardwareAcc) else { std::cout << "Successful export!" << std::endl; ui->ErrorLabel->clear(); - } + } } TrimSettings VideoLowWindow::getTrimSettings() { - QTime start = ui->startTimeEdit->time(); - QTime end = ui->EndTimeEdit->time(); - bool trim = ui->trimVideoCheckBox->isChecked(); - return TrimSettings {start, end, trim}; + QTime start = ui->startTimeEdit->time(); + QTime end = ui->EndTimeEdit->time(); + bool trim = ui->trimVideoCheckBox->isChecked(); + return TrimSettings{ start, end, trim }; } void VideoLowWindow::quickH264_2() @@ -157,75 +159,75 @@ void VideoLowWindow::quickHEVC_16() void VideoLowWindow::exportVideo() { std::cout << "export" << std::endl; - if (currentVideo) { + if (currentVideo) { handleExportExitCode( ffmpeg.exportFile( - *currentVideo, - getTrimSettings(), + *currentVideo, + getTrimSettings(), ui->BitrateDoubleSpinBox->value(), RESOLUTIONS[ui->ResolutionComboBox->currentIndex()], CODECS[ui->CodecComboBox->currentIndex()], ui->HardwareAccelerationComboBox->currentIndex(), FRAMERATES[ui->FramerateComboBox->currentIndex()] - ), - ui->HardwareAccelerationComboBox->currentIndex() != 0 + ), + ui->HardwareAccelerationComboBox->currentIndex() != 0 ); - } + } } void VideoLowWindow::reviewVideo() { - cutWindow->resetAll(); - cutWindow->loadVideo(*this->currentVideo); + cutWindow->resetAll(); + cutWindow->loadVideo(*this->currentVideo); cutWindow->setInitialStartAndEnd(ui->startTimeEdit->time(), ui->EndTimeEdit->time()); - cutWindow->show(); + cutWindow->show(); } void VideoLowWindow::gotCutInformation(QTime start, QTime end, bool cancelled) { - if(!cancelled){ - ui->startTimeEdit->setTime(start); - ui->EndTimeEdit->setTime(end); - ui->trimVideoCheckBox->setChecked(true); - } + if (!cancelled) { + ui->startTimeEdit->setTime(start); + ui->EndTimeEdit->setTime(end); + ui->trimVideoCheckBox->setChecked(true); + } } void VideoLowWindow::startTimeEdited() { - QTime current = ui->startTimeEdit->time(); - if (currentVideo) { - if (current > currentVideo->length) - current = currentVideo->length; - } - if (current > ui->EndTimeEdit->time()) - ui->EndTimeEdit->setTime(current); - ui->startTimeEdit->setTime(current); + QTime current = ui->startTimeEdit->time(); + if (currentVideo) { + if (current > currentVideo->length) + current = currentVideo->length; + } + if (current > ui->EndTimeEdit->time()) + ui->EndTimeEdit->setTime(current); + ui->startTimeEdit->setTime(current); } void VideoLowWindow::endTimeEdited() { - QTime current = ui->EndTimeEdit->time(); - if (currentVideo) { - if (current > currentVideo->length) - current = currentVideo->length; - } - if (current < ui->startTimeEdit->time()) - ui->startTimeEdit->setTime(current); - ui->EndTimeEdit->setTime(current); + QTime current = ui->EndTimeEdit->time(); + if (currentVideo) { + if (current > currentVideo->length) + current = currentVideo->length; + } + if (current < ui->startTimeEdit->time()) + ui->startTimeEdit->setTime(current); + ui->EndTimeEdit->setTime(current); } void VideoLowWindow::newVideoFile(Video vid) { - if (!currentVideo) { - currentVideo = new Video(vid); + if (!currentVideo) { + currentVideo = new Video(vid); } else - *currentVideo = vid; - QTime zero(0,0); - ui->reviewVideoButton->setDisabled(false); - ui->trimVideoCheckBox->setChecked(false); - ui->startTimeEdit->setTime(zero); - ui->EndTimeEdit->setTime(vid.length); - ui->videoLengthTimeEdit->setTime(vid.length); + *currentVideo = vid; + QTime zero(0, 0); + ui->reviewVideoButton->setDisabled(false); + ui->trimVideoCheckBox->setChecked(false); + ui->startTimeEdit->setTime(zero); + ui->EndTimeEdit->setTime(vid.length); + ui->videoLengthTimeEdit->setTime(vid.length); } diff --git a/videolowwindow.ui b/src/videolowwindow.ui similarity index 97% rename from videolowwindow.ui rename to src/videolowwindow.ui index eaebaee..c72a30e 100644 --- a/videolowwindow.ui +++ b/src/videolowwindow.ui @@ -26,7 +26,7 @@ 0 0 771 - 613 + 619 @@ -37,6 +37,9 @@ + + 0 + @@ -47,7 +50,6 @@ - Open Sans 12 @@ -59,6 +61,19 @@ + + + + + 0 + 232 + + + + + + + @@ -107,7 +122,6 @@ - Open Sans 12 @@ -336,7 +350,6 @@ - Open Sans 12 @@ -719,7 +732,7 @@ 0 0 777 - 21 + 22 @@ -729,7 +742,12 @@ FileDropWidget QLabel -
filedropwidget.h
+
include/filedropwidget.h
+
+ + FilePreviewWidget + QLabel +
include/filepreviewwidget.h
diff --git a/videolowwindow.h b/videolowwindow.h deleted file mode 100644 index 09c99f7..0000000 --- a/videolowwindow.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -class QString; -#include "ffmpegwrapper.h" -#include "Structs.h" -#include "VideoCutWindow/videocutwindow.h" -#include - - -QT_BEGIN_NAMESPACE -namespace Ui { class VideoLowWindow; } -QT_END_NAMESPACE - - - -class VideoLowWindow : public QMainWindow -{ - Q_OBJECT - -private slots: - void quickH264_2(); - void quickH264_4(); - void quickH264_8(); - void quickH264_16(); - void quickHEVC_2(); - void quickHEVC_4(); - void quickHEVC_8(); - void quickHEVC_16(); - void exportVideo(); - void reviewVideo(); - void gotCutInformation(QTime start, QTime end, bool cancelled); - void startTimeEdited(); - void endTimeEdited(); - -public slots: - void newVideoFile(Video vid); - -public: - VideoLowWindow(QWidget *parent = nullptr); - ~VideoLowWindow(); - void connectSlots(); - -private: - void quickH264(double MBitRate); - void quickHEVC(double MBitRate); - void handleExportExitCode(bool success, bool hardwareAcc); - - TrimSettings getTrimSettings(); - FFMPEGWrapper ffmpeg; - Ui::VideoLowWindow *ui; - VideoCutWindow *cutWindow; - Video *currentVideo = nullptr; -}; - -