[KPhotoAlbum] patch 4 video length extraction and video thumbnails

Andreas Schleth schleth_es at web.de
Tue Dec 12 18:25:55 GMT 2017


Hi Johannes,

here is another go. The patch should work on 5.2-41 (today's git master).

The changes are less than before (I did not shift the short video 
detection):

1. length is determined from the container as some vstreams do not have 
the attribute duration (as You suggested).

2. verbosity is set to 0 (panic).

3. We just want a number and nothing breaks if there is junk in the 
first line of output (this is caught later on where the cast to double 
is checked). Therefore, the test is: "do we have at least 1 line"

4. For thumbnailextraction I need the analyzeduration parameter, even if 
it slows things down a bit. With some videos we don't get the thumbs 
otherwise.
It would be better to *try* without this parameter first, then *retry 
with* on failure and keep the parameter for this specific file. But I 
did not find an easy way to retrace my steps and try the same file twice 
as these processes run asycronously.

Cheers, Andreas

-------------- next part --------------
diff --git a/ImageManager/ExtractOneVideoFrame.cpp b/ImageManager/ExtractOneVideoFrame.cpp
index d6adb5db..7e7dab50 100644
--- a/ImageManager/ExtractOneVideoFrame.cpp
+++ b/ImageManager/ExtractOneVideoFrame.cpp
@@ -74,10 +74,11 @@ ExtractOneVideoFrame::ExtractOneVideoFrame(const DB::FileName &fileName, double
         m_process->start(MainWindow::FeatureDialog::mplayerBinary(), arguments);
     } else {
         QStringList arguments;
-        arguments << STR("-ss") << QString::number(offset, 'f', 4) << STR("-i") << fileName.absolute()
-                  << STR("-sn") << STR("-an")
-                  << STR("-vframes") << STR("20")
-                  << m_workingDirectory + STR("/000000%02d.png");
+        // analyzeduration is for videos where the videostream starts later than the sound
+        arguments << STR("-ss") << QString::number(offset, 'f', 4) << STR("-analyzeduration")
+                  << STR("200M") << STR("-i") << fileName.absolute() << STR("-vf") << STR("thumbnail")
+                  << STR("-vframes") << STR("20") << m_workingDirectory + STR("/000000%02d.png");
+
         Debug( "%s %s", qPrintable(MainWindow::FeatureDialog::ffmpegBinary()), qPrintable(arguments.join(QString::fromLatin1(" "))));
 
         m_process->start(MainWindow::FeatureDialog::ffmpegBinary(), arguments);
diff --git a/ImageManager/VideoLengthExtractor.cpp b/ImageManager/VideoLengthExtractor.cpp
index 31f475e8..01cd7908 100644
--- a/ImageManager/VideoLengthExtractor.cpp
+++ b/ImageManager/VideoLengthExtractor.cpp
@@ -64,8 +64,8 @@ void ImageManager::VideoLengthExtractor::extract(const DB::FileName &fileName)
         m_process->start(MainWindow::FeatureDialog::mplayerBinary(), arguments);
     } else {
         QStringList arguments;
-        arguments << STR("-v") << STR("error") << STR("-select_streams") << STR("v:0")
-                  << STR("-show_entries") << STR("stream=duration")
+        // Just look at the length of the container. Some videos have streams without duration entry
+        arguments << STR("-v") << STR("0") << STR("-show_entries") << STR("format=duration")
                   << STR("-of") << STR("default=noprint_wrappers=1:nokey=1")
                   <<  fileName.absolute();
 
@@ -104,10 +104,8 @@ void ImageManager::VideoLengthExtractor::processEnded()
         lenStr = regexp.cap(1);
     } else {
         QStringList list = m_process->stdout().split(QChar::fromLatin1('\n'));
-        // one line-break -> 2 parts
-        // some videos with subtitles or other additional streams might have more than one line
-        // in these cases, we just take the first one as both lengths should be the same anyways
-        if ( list.count() < 2 ) {
+        // ffprobe -v 0 just prints one line, except if panicking
+        if ( list.count() < 1 ) {
             qWarning() << "Unable to parse video length from ffprobe output!"
                        << "Output was:\n"
                        << m_process->stdout();


More information about the Kphotoalbum mailing list