mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-07 03:22:33 +01:00
Fix import of very small videos like 1 second in length. Thanks user Jailbreaker for the feedback!
This commit is contained in:
parent
99fc40a58e
commit
2568abb132
@ -51,7 +51,6 @@ Item {
|
||||
target: ScreenPlay.create
|
||||
|
||||
function onCreateWallpaperStateChanged(state) {
|
||||
|
||||
switch (state) {
|
||||
case CreateImportVideo.ConvertingPreviewImage:
|
||||
txtConvert.text = qsTr("Generating preview image...")
|
||||
@ -98,7 +97,7 @@ Item {
|
||||
break
|
||||
}
|
||||
}
|
||||
onProgressChanged: {
|
||||
function onProgressChanged(progress) {
|
||||
var percentage = Math.floor(progress * 100)
|
||||
|
||||
if (percentage > 100 || progress > 0.95)
|
||||
|
@ -75,6 +75,8 @@ signals:
|
||||
void htmlWallpaperCreatedSuccessful(QString path);
|
||||
|
||||
public slots:
|
||||
void createWallpaperStart(QString videoPath, Create::VideoCodec codec);
|
||||
|
||||
void createWidget(
|
||||
const QString& localStoragePath,
|
||||
const QString& title,
|
||||
@ -91,8 +93,14 @@ public slots:
|
||||
const QString& license,
|
||||
const QVector<QString>& tags);
|
||||
|
||||
void createWallpaperStart(QString videoPath, Create::VideoCodec codec);
|
||||
void saveWallpaper(QString title, QString description, QString filePath, QString previewImagePath, QString youtube, ScreenPlay::Create::VideoCodec codec, QVector<QString> tags);
|
||||
void saveWallpaper(QString title,
|
||||
QString description,
|
||||
QString filePath,
|
||||
QString previewImagePath,
|
||||
QString youtube,
|
||||
ScreenPlay::Create::VideoCodec codec,
|
||||
QVector<QString> tags);
|
||||
|
||||
void abortAndCleanup();
|
||||
|
||||
void setProgress(float progress)
|
||||
|
@ -249,6 +249,10 @@ bool CreateImportVideo::createWallpaperInfo()
|
||||
framerate = qCeil(value1 / value2);
|
||||
m_framerate = framerate;
|
||||
|
||||
// If the video is to short
|
||||
m_smallVideo = m_numberOfFrames < (m_framerate * 3);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -273,6 +277,7 @@ bool CreateImportVideo::createWallpaperInfo()
|
||||
*/
|
||||
bool CreateImportVideo::createWallpaperVideoPreview()
|
||||
{
|
||||
|
||||
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewVideo);
|
||||
|
||||
QStringList args;
|
||||
@ -280,13 +285,15 @@ bool CreateImportVideo::createWallpaperVideoPreview()
|
||||
args.append("-stats");
|
||||
args.append("-i");
|
||||
args.append(m_videoPath);
|
||||
|
||||
args.append("-vf");
|
||||
// We allways want to have a 5 second clip via 24fps -> 120 frames
|
||||
// Divided by the number of frames we can skip (timeInSeconds * Framrate)
|
||||
// scale & crop parameter: https://unix.stackexchange.com/a/284731
|
||||
args.append("select='not(mod(n," + QString::number((m_length / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400");
|
||||
// Disable audio
|
||||
// If the video is shorter than 6 seconds we simply convert the original to webm
|
||||
if (!m_smallVideo) {
|
||||
args.append("-vf");
|
||||
// We allways want to have a 5 second clip via 24fps -> 120 frames
|
||||
// Divided by the number of frames we can skip (timeInSeconds * Framrate)
|
||||
// scale & crop parameter: https://unix.stackexchange.com/a/284731
|
||||
args.append("select='not(mod(n," + QString::number((m_length / 5)) + "))',setpts=N/FRAME_RATE/TB,crop=in_h*16/9:in_h,scale=-2:400");
|
||||
// Disable audio
|
||||
}
|
||||
args.append("-an");
|
||||
args.append(m_exportPath + "/preview.webm");
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
@ -399,16 +406,28 @@ bool CreateImportVideo::createWallpaperImageThumbnailPreview()
|
||||
args.clear();
|
||||
args.append("-y");
|
||||
args.append("-stats");
|
||||
args.append("-ss");
|
||||
args.append("00:00:02");
|
||||
// If the video is shorter than 3 seconds we use the first frame
|
||||
if (!m_smallVideo) {
|
||||
args.append("-ss");
|
||||
args.append("00:00:02");
|
||||
}
|
||||
args.append("-i");
|
||||
args.append(m_videoPath);
|
||||
args.append("-vframes");
|
||||
args.append("1");
|
||||
// Order of arguments is important
|
||||
if(!m_smallVideo){
|
||||
args.append("-vframes");
|
||||
args.append("1");
|
||||
}
|
||||
args.append("-q:v");
|
||||
args.append("2");
|
||||
args.append("-vf");
|
||||
args.append("scale=320:-1");
|
||||
if(m_smallVideo){
|
||||
args.append("-vf");
|
||||
// Select first frame https://stackoverflow.com/a/44073745/12619313
|
||||
args.append("select=eq(n\\,0), scale=320:-1");
|
||||
} else {
|
||||
args.append("-vf");
|
||||
args.append("scale=320:-1");
|
||||
}
|
||||
args.append(m_exportPath + "/previewThumbnail.jpg");
|
||||
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
@ -444,14 +463,20 @@ bool CreateImportVideo::createWallpaperImagePreview()
|
||||
args.clear();
|
||||
args.append("-y");
|
||||
args.append("-stats");
|
||||
args.append("-ss");
|
||||
args.append("00:00:02");
|
||||
// If the video is shorter than 3 seconds we use the first frame
|
||||
if (!m_smallVideo) {
|
||||
args.append("-ss");
|
||||
args.append("00:00:02");
|
||||
}
|
||||
args.append("-i");
|
||||
args.append(m_videoPath);
|
||||
args.append("-vframes");
|
||||
args.append("1");
|
||||
args.append("-q:v");
|
||||
args.append("2");
|
||||
if(m_smallVideo){
|
||||
args.append("-vf");
|
||||
// Select first frame https://stackoverflow.com/a/44073745/12619313
|
||||
args.append("select=eq(n\\,0)");
|
||||
}
|
||||
args.append(m_exportPath + "/preview.jpg");
|
||||
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
@ -504,9 +529,9 @@ bool CreateImportVideo::createWallpaperImagePreview()
|
||||
bool CreateImportVideo::createWallpaperVideo(const QString& codec)
|
||||
{
|
||||
|
||||
// if (m_videoPath.endsWith(".webm")) {
|
||||
// return true;
|
||||
// }
|
||||
// if (m_videoPath.endsWith(".webm")) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
emit createWallpaperStateChanged(ImportVideoState::ConvertingVideo);
|
||||
|
||||
|
@ -25,7 +25,7 @@ class CreateImportVideo : public QObject {
|
||||
Q_PROPERTY(float progress READ progress WRITE setProgress NOTIFY progressChanged)
|
||||
|
||||
public:
|
||||
CreateImportVideo() {}
|
||||
CreateImportVideo() { }
|
||||
~CreateImportVideo()
|
||||
{
|
||||
qDebug() << "CreateImportVideo";
|
||||
@ -33,19 +33,6 @@ public:
|
||||
CreateImportVideo(QObject* parent = nullptr);
|
||||
explicit CreateImportVideo(const QString& videoPath, const QString& exportPath, const QStringList& codecs, QObject* parent = nullptr);
|
||||
|
||||
bool m_skipAudio { false };
|
||||
|
||||
float m_progress { 0.0F };
|
||||
|
||||
QString m_videoPath;
|
||||
QString m_exportPath;
|
||||
QString m_format;
|
||||
QStringList m_codecs;
|
||||
|
||||
int m_numberOfFrames { 0 };
|
||||
int m_length { 0 };
|
||||
int m_framerate { 0 };
|
||||
|
||||
enum class ImportVideoState {
|
||||
Idle,
|
||||
Started,
|
||||
@ -88,6 +75,22 @@ public:
|
||||
return m_progress;
|
||||
}
|
||||
|
||||
bool m_skipAudio { false };
|
||||
|
||||
// If the video is < 1s in duration we cannot create a 5s preview
|
||||
bool m_smallVideo { false };
|
||||
|
||||
float m_progress { 0.0F };
|
||||
|
||||
QString m_videoPath;
|
||||
QString m_exportPath;
|
||||
QString m_format;
|
||||
QStringList m_codecs;
|
||||
|
||||
int m_numberOfFrames { 0 };
|
||||
int m_length { 0 };
|
||||
int m_framerate { 0 };
|
||||
|
||||
signals:
|
||||
void createWallpaperStateChanged(CreateImportVideo::ImportVideoState state);
|
||||
void processOutput(QString text);
|
||||
@ -102,7 +105,7 @@ public slots:
|
||||
bool createWallpaperVideoPreview();
|
||||
bool createWallpaperGifPreview();
|
||||
bool createWallpaperImagePreview();
|
||||
bool createWallpaperVideo(const QString &codec);
|
||||
bool createWallpaperVideo(const QString& codec);
|
||||
bool extractWallpaperAudio();
|
||||
bool createWallpaperImageThumbnailPreview();
|
||||
|
||||
@ -123,6 +126,8 @@ private:
|
||||
|
||||
QString m_ffprobeExecutable;
|
||||
QString m_ffmpegExecutable;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
Q_DECLARE_METATYPE(ScreenPlay::CreateImportVideo::ImportVideoState)
|
||||
|
Loading…
Reference in New Issue
Block a user