File Check-whether-a-frame-could-be-decoded-before-seeking.patch of Package ffmpegthumbs4
From 6fa26cddeff42831a6c6bf885bd8c905a413d3e4 Mon Sep 17 00:00:00 2001
From: Kai Uwe Broulik <kde@privat.broulik.de>
Date: Wed, 26 Sep 2018 10:24:42 +0200
Subject: [PATCH] Check whether a frame could be decoded before seeking
Otherwise crashes when trying to generate thumbnail for a video file without actual video data.
CHANGELOG: Fixed video thumbnailer crashing when trying to decode files without video stream
Differential Revision: https://phabricator.kde.org/D15752
---
ffmpegthumbnailer/moviedecoder.cpp | 5 +++--
ffmpegthumbnailer/moviedecoder.h | 2 +-
ffmpegthumbnailer/videothumbnailer.cpp | 4 +++-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/ffmpegthumbnailer/moviedecoder.cpp b/ffmpegthumbnailer/moviedecoder.cpp
index b2e7551..6d1a79c 100644
--- a/ffmpegthumbnailer/moviedecoder.cpp
+++ b/ffmpegthumbnailer/moviedecoder.cpp
@@ -227,7 +227,7 @@ void MovieDecoder::seek(int timeInSeconds)
}
-void MovieDecoder::decodeVideoFrame()
+bool MovieDecoder::decodeVideoFrame()
{
bool frameFinished = false;
@@ -237,8 +237,9 @@ void MovieDecoder::decodeVideoFrame()
if (!frameFinished) {
kDebug() << "decodeVideoFrame() failed: frame not finished";
- return;
}
+
+ return frameFinished;
}
bool MovieDecoder::decodeVideoPacket()
diff --git a/ffmpegthumbnailer/moviedecoder.h b/ffmpegthumbnailer/moviedecoder.h
index 788ce43..060c02e 100644
--- a/ffmpegthumbnailer/moviedecoder.h
+++ b/ffmpegthumbnailer/moviedecoder.h
@@ -39,7 +39,7 @@ public:
QString getCodec();
void seek(int timeInSeconds);
- void decodeVideoFrame();
+ bool decodeVideoFrame();
void getScaledVideoFrame(int scaledSize, bool maintainAspectRatio, VideoFrame& videoFrame);
int getWidth();
diff --git a/ffmpegthumbnailer/videothumbnailer.cpp b/ffmpegthumbnailer/videothumbnailer.cpp
index 97218c8..c3fd1c4 100644
--- a/ffmpegthumbnailer/videothumbnailer.cpp
+++ b/ffmpegthumbnailer/videothumbnailer.cpp
@@ -98,7 +98,9 @@ void VideoThumbnailer::generateThumbnail(const QString& videoFile, ImageWriter&
{
MovieDecoder movieDecoder(videoFile, NULL);
if (movieDecoder.getInitialized()) {
- movieDecoder.decodeVideoFrame(); //before seeking, a frame has to be decoded
+ if (!movieDecoder.decodeVideoFrame()) { //before seeking, a frame has to be decoded
+ return;
+ }
if ((!m_WorkAroundIssues) || (movieDecoder.getCodec() != QLatin1String("h264"))) { //workaround for bug in older ffmpeg (100% cpu usage when seeking in h264 files)
int secondToSeekTo = m_SeekTime.isEmpty() ? movieDecoder.getDuration() * m_SeekPercentage / 100 : timeToSeconds(m_SeekTime);
--
GitLab