diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-07-24 10:41:32 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-07-24 10:41:32 -0500 |
commit | c53429a6968563f72f8b334486d6dd1f0de75ecb (patch) | |
tree | 6c6b3c6d09f776dc7a54635584bfa79a3af71ed9 /src | |
download | mplayerthumbs-c53429a6968563f72f8b334486d6dd1f0de75ecb.tar.gz mplayerthumbs-c53429a6968563f72f8b334486d6dd1f0de75ecb.zip |
Initial import of mplayerthumbs 0.5b sources
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 22 | ||||
-rw-r--r-- | src/mplayerthumbs.cpp | 25 | ||||
-rw-r--r-- | src/mplayerthumbs.kcfg | 16 | ||||
-rw-r--r-- | src/mplayerthumbs.kcfgc | 2 | ||||
-rw-r--r-- | src/mplayerthumbsconfig/Makefile.am | 11 | ||||
-rw-r--r-- | src/mplayerthumbsconfig/main.cpp | 69 | ||||
-rw-r--r-- | src/mplayerthumbsconfig/mplayerthumbscfg.cpp | 65 | ||||
-rw-r--r-- | src/mplayerthumbsconfig/mplayerthumbscfg.h | 38 | ||||
-rw-r--r-- | src/sprocket-large.png | bin | 0 -> 731 bytes | |||
-rw-r--r-- | src/sprocket-medium.png | bin | 0 -> 492 bytes | |||
-rw-r--r-- | src/sprocket-small.png | bin | 0 -> 291 bytes | |||
-rw-r--r-- | src/videopreview.cpp | 259 | ||||
-rw-r--r-- | src/videopreview.desktop | 61 | ||||
-rw-r--r-- | src/videopreview.h | 62 | ||||
-rw-r--r-- | src/videopreview.lsm | 16 |
15 files changed, 646 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..4af25eb --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = $(all_includes) +METASOURCES = AUTO + +SUBDIRS = . mplayerthumbsconfig + +kde_module_LTLIBRARIES = videopreview.la + +videopreview_la_SOURCES = videopreview.cpp mplayerthumbs.kcfgc +videopreview_la_LDFLAGS = -avoid-version -module $(all_libraries) $(KDE_PLUGIN) + +protocoldir = $(kde_servicesdir) + +messages: rc.cpp + $(EXTRACTRC) `find . -name \*.ui -o -name \*.rc` > rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/videopreview.pot +protocol_DATA = videopreview.desktop +videopreview_la_LIBADD = $(LIB_KDECORE) + +videothumbnail_DATA = sprocket-small.png sprocket-medium.png sprocket-large.png +videothumbnaildir = $(kde_datadir)/videothumbnail +kde_kcfg_DATA = mplayerthumbs.kcfg + diff --git a/src/mplayerthumbs.cpp b/src/mplayerthumbs.cpp new file mode 100644 index 0000000..12eb3b8 --- /dev/null +++ b/src/mplayerthumbs.cpp @@ -0,0 +1,25 @@ +// This file is generated by kconfig_compiler from mplayerthumbs.kcfg. +// All changes you do to this file will be lost. + +#include "mplayerthumbs.h" + +MPlayerThumbsCfg::MPlayerThumbsCfg( ) + : KConfigSkeleton( QString::fromLatin1( "mplayerthumbs" ) ) +{ + setCurrentGroup( QString::fromLatin1( "MPlayerThumbsCfg" ) ); + + KConfigSkeleton::ItemString *itemMplayerbin; + itemMplayerbin = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "mplayerbin" ), mMplayerbin ); + addItem( itemMplayerbin, QString::fromLatin1( "mplayerbin" ) ); + KConfigSkeleton::ItemStringList *itemNoextensions; + itemNoextensions = new KConfigSkeleton::ItemStringList( currentGroup(), QString::fromLatin1( "noextensions" ), mNoextensions ); + addItem( itemNoextensions, QString::fromLatin1( "noextensions" ) ); + KConfigSkeleton::ItemString *itemCustomargs; + itemCustomargs = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "customargs" ), mCustomargs ); + addItem( itemCustomargs, QString::fromLatin1( "customargs" ) ); +} + +MPlayerThumbsCfg::~MPlayerThumbsCfg() +{ +} + diff --git a/src/mplayerthumbs.kcfg b/src/mplayerthumbs.kcfg new file mode 100644 index 0000000..2208b1c --- /dev/null +++ b/src/mplayerthumbs.kcfg @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd"> +<kcfg> + <kcfgfile name="mplayerthumbs"/> + <group name="MPlayerThumbsCfg"> + <entry name="mplayerbin" type="String"> + <label>Full path of the mplayer binary to use.</label> + </entry> + <entry name="noextensions" type="StringList"> + <label>File extensions that mplayerthumbs should avoid</label> + </entry> + <entry name="customargs" type="String"> + <label>Append custom arguments to mplayer</label> + </entry> + </group> +</kcfg> diff --git a/src/mplayerthumbs.kcfgc b/src/mplayerthumbs.kcfgc new file mode 100644 index 0000000..a4bed80 --- /dev/null +++ b/src/mplayerthumbs.kcfgc @@ -0,0 +1,2 @@ +File=mplayerthumbs.kcfg +ClassName=MPlayerThumbsCfg diff --git a/src/mplayerthumbsconfig/Makefile.am b/src/mplayerthumbsconfig/Makefile.am new file mode 100644 index 0000000..6534793 --- /dev/null +++ b/src/mplayerthumbsconfig/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = -I$(top_builddir)/src $(all_includes) +METASOURCES = AUTO + +messages: rc.cpp + $(EXTRACTRC) `find . -name \*.ui -o -name \*.rc` > rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/videopreview.pot +bin_PROGRAMS = mplayerthumbsconfig +mplayerthumbsconfig_LDFLAGS = $(KDE_RPATH) $(all_libraries) +mplayerthumbsconfig_SOURCES = main.cpp mplayerthumbscfg.cpp +noinst_HEADERS = mplayerthumbscfg.h +mplayerthumbsconfig_LDADD = $(top_builddir)/src/videopreview.la $(LIB_KDEUI) diff --git a/src/mplayerthumbsconfig/main.cpp b/src/mplayerthumbsconfig/main.cpp new file mode 100644 index 0000000..2d1bc6f --- /dev/null +++ b/src/mplayerthumbsconfig/main.cpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2006 by Marco Gulino * + * marco@kmobiletools.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include <kapplication.h> +#include <kaboutdata.h> +#include <kcmdlineargs.h> +#include <klocale.h> + +#include "mplayerthumbscfg.h" +#include "mplayerthumbs.h" + +static const char description[] = + I18N_NOOP("MPlayerThumbs Configuration Utility"); + +static const char version[] = "0.1"; + +static KCmdLineOptions options[] = +{ +// { "+[URL]", I18N_NOOP( "Document to open" ), 0 }, + KCmdLineLastOption +}; + +int main(int argc, char **argv) +{ + KAboutData about("MPlayerThumbsConfig", I18N_NOOP("MPlayerThumbsConfig"), version, description, + KAboutData::License_GPL, "(C) 2006 Marco Gulino", 0, 0, "marco@kmobiletools.org"); + about.addAuthor( "Marco Gulino", 0, "marco@kmobiletools.org" ); + KCmdLineArgs::init(argc, argv, &about); + KCmdLineArgs::addCmdLineOptions( options ); + KApplication app; + MPlayerThumbsConfig *mainWin = 0; + +// if (app.isRestored()) +// { +// RESTORE(MPlayerThumbsConfig); +// } +// else +// { + // no session.. just start up normally + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + /// @todo do something with the command line args here + + mainWin = new MPlayerThumbsConfig(0, "configDialog", new MPlayerThumbsCfg(), KDialogBase::Swallow ); + app.setMainWidget( mainWin ); + mainWin->show(); + + args->clear(); +// } + + // mainWin has WDestructiveClose flag by default, so it will delete itself. + return app.exec(); +} diff --git a/src/mplayerthumbsconfig/mplayerthumbscfg.cpp b/src/mplayerthumbsconfig/mplayerthumbscfg.cpp new file mode 100644 index 0000000..f1fc24a --- /dev/null +++ b/src/mplayerthumbsconfig/mplayerthumbscfg.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2006 by Marco Gulino * + * marco@kmobiletools.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "mplayerthumbscfg.h" +#include <qvbox.h> +#include <klineedit.h> +#include <kpushbutton.h> +#include <qlabel.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kdebug.h> +#include <qtimer.h> +#include <keditlistbox.h> + +MPlayerThumbsConfig::MPlayerThumbsConfig(QWidget *parent, const char *name, MPlayerThumbsCfg *config, DialogType dialogType, int dialogButtons, ButtonCode defaultButton, bool modal) + : KConfigDialog(parent, name, config, dialogType, dialogButtons, defaultButton, modal) +{ + QVBox *vbox=new QVBox(0); + vbox->setSpacing( 5); + new QLabel(i18n("Enter here the path for mplayer executable file."), vbox); + kcfg_mplayerbin=new KLineEdit( vbox, "kcfg_mplayerbin"); + new QLabel(i18n("Custom arguments for mplayer."), vbox); + new KLineEdit( vbox, "kcfg_customargs"); + new KEditListBox( i18n("Blacklisted File Extensions"), + vbox, "kcfg_noextensions", true, KEditListBox::Add | KEditListBox::Remove); + addPage( vbox, i18n("General"), "mplayer" ); + kdDebug() << "config->mplayerbin().isNull()::" << config->mplayerbin().length() << endl; + if(!config->mplayerbin().length() ) + QTimer::singleShot( 100, this, SLOT(autoFindPath())); +} + +MPlayerThumbsConfig::~MPlayerThumbsConfig() +{ +} + +#include "mplayerthumbscfg.moc" + + +/*! + \fn MPlayerThumbsConfig::autoFindPath() + */ +void MPlayerThumbsConfig::autoFindPath() +{ + QString playerPath=KStandardDirs::findExe("mplayer-bin"); + if(playerPath.isNull() ) playerPath=KStandardDirs::findExe("mplayer"); + kdDebug() << "Trying to set player path to " << playerPath << endl; + kcfg_mplayerbin->setText( playerPath ); +} diff --git a/src/mplayerthumbsconfig/mplayerthumbscfg.h b/src/mplayerthumbsconfig/mplayerthumbscfg.h new file mode 100644 index 0000000..6757a4c --- /dev/null +++ b/src/mplayerthumbsconfig/mplayerthumbscfg.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2006 by Marco Gulino * + * marco@kmobiletools.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef _MPLAYERTHUMBSCONFIG_ +#define _MPLAYERTHUMBSCONFIG_ +#include <kconfigdialog.h> +#include "mplayerthumbs.h" + +class KLineEdit; +class MPlayerThumbsConfig : public KConfigDialog +{ + Q_OBJECT + public: + MPlayerThumbsConfig(QWidget *parent, const char *name, MPlayerThumbsCfg *config, DialogType dialogType=IconList, int dialogButtons=Default|Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool modal=false); + ~MPlayerThumbsConfig(); + private: + KLineEdit *kcfg_mplayerbin; +public slots: + void autoFindPath(); +}; + +#endif diff --git a/src/sprocket-large.png b/src/sprocket-large.png Binary files differnew file mode 100644 index 0000000..ce3c6e9 --- /dev/null +++ b/src/sprocket-large.png diff --git a/src/sprocket-medium.png b/src/sprocket-medium.png Binary files differnew file mode 100644 index 0000000..f46f5f9 --- /dev/null +++ b/src/sprocket-medium.png diff --git a/src/sprocket-small.png b/src/sprocket-small.png Binary files differnew file mode 100644 index 0000000..5dfc6d6 --- /dev/null +++ b/src/sprocket-small.png diff --git a/src/videopreview.cpp b/src/videopreview.cpp new file mode 100644 index 0000000..bf779e6 --- /dev/null +++ b/src/videopreview.cpp @@ -0,0 +1,259 @@ +/*************************************************************************** + Copyright (C) 2006 + by Marco Gulino <marco@kmobiletools.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + ***************************************************************************/ + +#include "videopreview.h" + +#include <qfile.h> +#include <qpixmap.h> +#include <qimage.h> + +#include <kstandarddirs.h> +#include <kpixmapsplitter.h> +#include <kmimetype.h> +#include <qpainter.h> +#include <krandomsequence.h> +#include <qdatetime.h> +#include <qregexp.h> +#include "videopreview.h" +#include <qprocess.h> +#include <kdebug.h> +#include <ktempdir.h> +#include <kurl.h> +#include <math.h> +#include <qfileinfo.h> + +#include "mplayerthumbs.h" + +#include "config.h" +extern "C" +{ + KDE_EXPORT ThumbCreator *new_creator() + { + return new VideoPreview; + } +} + +VideoPreview::VideoPreview() + : m_splitter(0), + m_data(0), + m_dataSize(0) +{ +} + +VideoPreview::~VideoPreview() +{ + delete m_splitter; + delete [] m_data; + delete tmpdir; + delete rand; + delete mplayerprocess; +} + +bool VideoPreview::create(const QString &path, int width, int height, QImage &img) +{ + MPlayerThumbsCfg *cfg=new MPlayerThumbsCfg(); + QFileInfo fi(path); + kdDebug() << "videopreview: file extension=\"" << fi.extension().stripWhiteSpace() << "\"\n"; + if( fi.extension().stripWhiteSpace().length() && !cfg->noextensions().grep(fi.extension().stripWhiteSpace(), false) + .isEmpty() ) + { + delete cfg; + kdDebug() << "videopreview: matched extension " << fi.extension().prepend('.') << "; exiting.\n"; + return false; + } + playerBin=cfg->mplayerbin(); + customargs=QStringList::split(" ", cfg->customargs() ); + kdDebug() << "videopreview: customargs=" << cfg->customargs() << " ;;;; " << customargs << endl; + delete cfg; + if(playerBin.length()) kdDebug() << "videopreview: found playerbin from config: " << playerBin << endl; + else + { + playerBin=KStandardDirs::findExe("mplayer-bin"); + if(!playerBin.length()) playerBin=KStandardDirs::findExe("mplayer"); + if(!playerBin.length()) + { + kdDebug() << "videopreview: mplayer not found, exiting. Run mplayerthumbsconfig to setup mplayer path manually.\n"; + return false; + } + kdDebug() << "videopreview: found playerbin from path: " << playerBin << endl; + } + fileinfo.seconds=0; + fileinfo.fps=0; + tmpdir=new KTempDir(); + if(tmpdir->name().isNull() ) return false; + + rand=new KRandomSequence(QDateTime::currentDateTime().toTime_t()); + mplayerprocess=new QProcess(); + int flags=0; + KURL furl(path); + kdDebug() << "videopreview: url=" << furl << "; local:" << furl.isLocalFile() << endl; + fileinfo.towidth=width; + fileinfo.toheight=height; + QPixmap pix; +// if(furl.isLocalFile()) +// { + flags=framerandom; + QStringList args; + args << playerBin << path << "-nocache" << "-identify" << "-vo" << "null" << "-frames" << "0"/* << "-nosound" */<< "-ao" << "null"; + args+= customargs; + mplayerprocess->setArguments(args); + mplayerprocess->setCommunication( QProcess::Stdout ); + mplayerprocess->start(); + QString lineout; + QRegExp findsecs("^ID_LENGTH=([\\d]*)"); + QRegExp findfps("^ID_VIDEO_FPS=([\\d]*)"); + while (mplayerprocess->isRunning() ) usleep (10); + do { + lineout=mplayerprocess->readLineStdout(); + if(findsecs.search( lineout) != -1) + fileinfo.seconds =findsecs.cap(1).toInt(); + if(findfps.search( lineout) != -1) + fileinfo.fps=findfps.cap(1).toInt(); + if( fileinfo.fps!=0 && fileinfo.seconds!=0 ) break; + } while (lineout != QString::null ); + kdDebug() << "videopreview: find length=" << fileinfo.seconds << ", fps=" << fileinfo.fps << endl; +/* } else + { + flags=frameend; + }*/ +#define LASTTRY 3 + for(int i=0; i<=LASTTRY; i++) + { + kdDebug() << "videopreview: try " << i << endl; + pix=getFrame(path, ((i<LASTTRY) ? flags : framestart ) ); + if(!pix.isNull()) { + uint variance=imageVariance(pix.convertToImage()/*.bits(),( (width+ 7) & ~0x7), width, height, 1 */); + kdDebug() << "videopreview: " << QFileInfo(path).fileName() << " frame variance: " << variance << "; " << + ((variance<=40 && ( i!=LASTTRY-1))? "!!!DROPPING!!!" : "GOOD :-)" ) << endl; + if(variance>40 || i==LASTTRY-1 ) break; + } + } + if(pix.isNull() ) + { + if(tmpdir) tmpdir->unlink(); + return false; + } + /** From videocreator.cpp - xine_artsplugin + Copyright (C) 2002 Simon MacMullen + Copyright (C) 2003 Ewald Snel <ewald@rambo.its.tudelft.nl> + * */ +// QPixmap pix( createThumbnail( &frame, width, height ) ); +#ifdef STRIPS_SUPPORT + QPainter painter( &pix ); + QPixmap sprocket; + + if (pix.height() < 60) + sprocket = QPixmap(locate( "data", "videothumbnail/sprocket-small.png" )); + else if (pix.height() < 90) + sprocket = QPixmap(locate( "data", "videothumbnail/sprocket-medium.png" )); + else + sprocket = QPixmap(locate( "data", "videothumbnail/sprocket-large.png" )); + + for (int y = 0; y < pix.height() + sprocket.height(); y += sprocket.height()) { + painter.drawPixmap( 0, y, sprocket ); + } + + // End of xine-artsplugin code +#endif + img = pix.convertToImage(); + + if(tmpdir) tmpdir->unlink(); + return true; +} + +QPixmap VideoPreview::getFrame(const QString &path, int flags) +{ + QStringList args; + kdDebug() << "videopreview: using flags " << flags << endl; +#define START ((fileinfo.seconds*15)/100) +#define END ((fileinfo.seconds*70)/100) + mplayerprocess->setCommunication( 0 ); + mplayerprocess->clearArguments(); + args.clear(); + args << playerBin << path; + if(fileinfo.towidth>fileinfo.toheight) fileinfo.toheight=-2; else fileinfo.towidth=-2; +// switch( flags ){ +// case random +// } + if( flags & framerandom ) + { + kdDebug() << "videopreview: framerandom\n"; + unsigned long start=(unsigned long)(START+(rand->getDouble() * (END - START) ) ); + args << "-ss" << QString::number( start ) + << "-frames" << "4"; + } else if (flags & frameend ) + { + kdDebug() << "videopreview: frameend\n"; + args << "-ss" << QString::number( fileinfo.seconds - 10 ) + << "-frames" << "4"; + } else if (flags & framestart) + { + kdDebug() << "videopreview: framestart\n"; + if(!fileinfo.fps) fileinfo.fps=25; // if we've not autodetected a fps rate, let's assume 25fps.. even if it's wrong it shouldn't hurt. + // If we can't skip to a random frame, let's try playing 10 seconds. + args << "-frames" << QString::number( fileinfo.fps*10 ); + } + args << "-nocache" << "-idx" /*@TODO check if it's too slow..*/ << "-ao" << "null"/*"-nosound" << */<< "-speed" << "99" /*<< "-sstep" << "5"*/ + << "-vo" << QString("jpeg:outdir=%1").arg(tmpdir->name() ) << "-vf" << QString("scale=%1:%2").arg(fileinfo.towidth).arg(fileinfo.toheight); + args+=customargs; + kdDebug() << "videopreview: Starting MPlayer with" << args.join( " ") << endl; +// return false; + mplayerprocess->setArguments( args); + mplayerprocess->start(); + while (mplayerprocess->isRunning() ) usleep (10); + if (tmpdir->qDir()->entryList( "*.jpg" ).isEmpty() ) return false; + + QString lastframe=tmpdir->qDir()->entryList( "*.jpg" ).last(); + kdDebug() << "videopreview: LastFrame==" << lastframe << endl; + QPixmap retpix(tmpdir->name().append( lastframe )); + return retpix; +} + +ThumbCreator::Flags VideoPreview::flags() const +{ + return (Flags)(DrawFrame); +} + + +uint VideoPreview::imageVariance(QImage image ) +{ + uint delta=0; + uint avg=0; + uint bytes=image.numBytes(); + uint STEPS=bytes/2; + uchar pivot[STEPS]; + kdDebug() << "Using " << STEPS << " steps\n"; + uchar *bits=image.bits(); + // First pass: get pivots and taking average + for( uint i=0; i<STEPS ; i++ ){ + pivot[i]=bits[i*(bytes/STEPS)]; + avg+=pivot[i]; + } + avg=avg/STEPS; + // Second Step: calculate delta (average?) + for (uint i=0; i<STEPS; i++) + { + int curdelta=abs(int(avg-pivot[i])); + delta+=curdelta; + } + return delta/STEPS; +} +#include "videopreview.moc" + diff --git a/src/videopreview.desktop b/src/videopreview.desktop new file mode 100644 index 0000000..b423473 --- /dev/null +++ b/src/videopreview.desktop @@ -0,0 +1,61 @@ +[Desktop Entry] +Type=Service +Name=Video Files (MPlayerThumbs) +Name[af]=Video Lêers (MPlayerThumbs) +Name[bg]=Видео файлове (MPlayerThumbs) +Name[bn]=ভিডিও ফাইল (MPlayerThumbs) +Name[br]=Restroù Video (MPlayerThumbs) +Name[bs]=Video datoteke (MPlayerThumbs) +Name[ca]=Fitxers de vídeo (MPlayerThumbs) +Name[cs]=Video soubory (MPlayerThumbs) +Name[cy]=Ffeiliau Fideo (MPlayerThumbs) +Name[da]=Videofiler (MPlayerThumbs) +Name[de]=Video-Dateien (MPlayerThumbs) +Name[el]=Αρχεία βίντεο (MPlayerThumbs) +Name[es]=Archivos de vídeo (MPlayerThumbs) +Name[et]=Videofailid (MPlayerThumbs) +Name[eu]=Bideo fitxategiak (MPlayerThumbs) +Name[fi]=Videotiedostot (MPlayerThumbs) +Name[fr]=Fichiers vidéo (MPlayerThumbs) +Name[ga]=Comhaid Fhíse (MPlayerThumbs) +Name[he]=קבצי וידאו (MPlayerThumbs) +Name[hi]=वीडियो फ़ाइलें (MPlayerThumbs) +Name[hr]=Video datoteke (MPlayerThumbs) +Name[hu]=Videófájlok (MPlayerThumbs) +Name[is]=Kvikmyndaskrár (MPlayerThumbs) +Name[it]=File Video (MPlayerThumbs) +Name[ja]=ビデオファイル (MPlayerThumbs) +Name[km]=ឯកសារវីដេអូ (MPlayerThumbs) +Name[lt]=Video bylos (MPlayerThumbs) +Name[mk]=Видео датотеки (MPlayerThumbs) +Name[nb]=Videofiler (MPlayerThumbs) +Name[nl]=Videobestanden (MPlayerThumbs) +Name[nn]=Videofiler (MPlayerThumbs) +Name[pa]=ਵੀਡਿਓ ਫਾਇਲਾਂ (MPlayerThumbs) +Name[pl]=Pliki wideo (MPlayerThumbs) +Name[pt]=Ficheiros de Vídeo (MPlayerThumbs) +Name[pt_BR]=Arquivos de vídeo (MPlayerThumbs) +Name[ro]=Fişiere video (MPlayerThumbs) +Name[ru]=Видеофайлы (MPlayerThumbs) +Name[sk]=Video súbory (MPlayerThumbs) +Name[sl]=Video datoteke (MPlayerThumbs) +Name[sr]=Видео фајлови (MPlayerThumbs) +Name[sr@Latn]=Video fajlovi (MPlayerThumbs) +Name[sv]=Videofiler (MPlayerThumbs) +Name[ta]=படக்காட்சி கோப்புகள் (MPlayerThumbs) +Name[tg]=Файлҳои Видео (MPlayerThumbs) +Name[tr]=Video Dosyaları (MPlayerThumbs) +Name[uk]=Відео-файли (MPlayerThumbs) +Name[uz]=Видео файллар (MPlayerThumbs) +Name[ven]=Dzifaela dza Video (MPlayerThumbs) +Name[wa]=Fitchîs videyo (MPlayerThumbs) +Name[xh]=Iifayile ze Video (MPlayerThumbs) +Name[zh_CN]=视频文件 (MPlayerThumbs) +Name[zh_HK]=視訊檔案 (MPlayerThumbs) +Name[zh_TW]=視訊檔案 (MPlayerThumbs) +Name[zu]=Amafayela Evidiyo (MPlayerThumbs) +ServiceTypes=ThumbCreator +CacheThumbnail=true +IgnoreMaximumSize=true +MimeTypes=video/*,application/vnd.ms-asf,application/vnd.rn-realmedia +X-KDE-Library=videopreview
\ No newline at end of file diff --git a/src/videopreview.h b/src/videopreview.h new file mode 100644 index 0000000..cb4f255 --- /dev/null +++ b/src/videopreview.h @@ -0,0 +1,62 @@ +/*************************************************************************** + Copyright (C) 2006 + by Marco Gulino <marco@kmobiletools.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + ***************************************************************************/ + +#ifndef _videopreview_H_ +#define _videopreview_H_ + +#include <qstring.h> +#include <qcstring.h> + +#include <qpixmap.h> +#include <kio/thumbcreator.h> + +class QProcess; +class QCString; +class KTempDir; +class KRandomSequence; +class KPixmapSplitter; +#include <qobject.h> + +class VideoPreview : public QObject, public ThumbCreator +{ +Q_OBJECT + public: + VideoPreview(); + virtual ~VideoPreview(); + virtual bool create(const QString &path, int width, int height, QImage &img); + virtual Flags flags() const; + protected: + QPixmap getFrame(const QString &path, int flags); + static uint imageVariance(QImage image ); + private: + KPixmapSplitter *m_splitter; + char *m_data; + int m_dataSize; + QPixmap m_pixmap; + QProcess *mplayerprocess; + QStringList customargs; + KTempDir *tmpdir; + KRandomSequence *rand; + QString playerBin; + enum frameflags { framerandom=0x1, framestart=0x2, frameend=0x4 }; + struct { int towidth; int toheight; int fps; int seconds; } fileinfo; +}; + +#endif diff --git a/src/videopreview.lsm b/src/videopreview.lsm new file mode 100644 index 0000000..7da8aa6 --- /dev/null +++ b/src/videopreview.lsm @@ -0,0 +1,16 @@ +Begin3 +Title: videopreview -- Some description +Version: 0.1 +Entered-date: +Description: +Keywords: KDE Qt +Author: Marco Gulino <marco@kmobiletools.org> +Maintained-by: Marco Gulino <marco@kmobiletools.org> +Home-page: +Alternate-site: +Primary-site: ftp://ftp.kde.org/pub/kde/unstable/apps/utils + xxxxxx videopreview-0.1.tar.gz + xxx videopreview-0.1.lsm +Platform: Linux. Needs KDE +Copying-policy: GPL +End |