1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/*
* File: KeyFrameExtract.cpp
* Author: xieyi
*
* Created on 2014年9月30日, 下午9:03
*/
#include "KeyFrameExtract.h"
KeyFrameExtract::KeyFrameExtract()
{
widget.setupUi(this);
connect(widget.pushButtonSelectVideo,SIGNAL(clicked()),this,SLOT(selectVideoFile()));
}
KeyFrameExtract::~KeyFrameExtract()
{
}
void KeyFrameExtract::selectVideoFile()
{
QString fileName;
while(1) {
fileName = QFileDialog::getOpenFileName(
this,tr("打开视频文件"),tr("."),tr("视频文件 (*.mp4 *.mpeg *.avi)")
);
if(false == fileName.isEmpty()) break;
}
QStringList args;
QDir output(QFileInfo(fileName).baseName());
if(output.exists()) removeDir(output.path());
QDir().mkdir(output.path());
args<<"-i"<<fileName<<"-vf"<<"select='eq(pict_type\\,I),setpts=N/(25*TB)'"
<<"-q"<<"1"<<output.path() + "/%09d.bmp";
process = QSharedPointer<QProcess>(new QProcess);
connect(process.data(),SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus)));
process->start("avconv",args);
#ifndef NDEBUG
QString cmd;
cmd += "avconv";
for(int i = 0 ; i < args.size() ; i++) cmd += " " + args[i];
qDebug()<<cmd;
#endif
if(false == process->waitForStarted()) {
QMessageBox::critical(this,tr("错误"),tr("无法启动!"));
return;
}
}
void KeyFrameExtract::processFinished(int,QProcess::ExitStatus)
{
QMessageBox::information(this,tr("成功"),tr("关键帧提取完毕!"));
process.clear();
}
bool KeyFrameExtract::removeDir(const QString & dirName)
{
bool result = true;
QDir dir(dirName);
if (dir.exists(dirName)) {
Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
if (info.isDir())
result = removeDir(info.absoluteFilePath());
else
result = QFile::remove(info.absoluteFilePath());
if (!result)
return result;
}
result = dir.rmdir(dirName);
}
return result;
}
|