#include "VideoMoveCaptureElement.h"
|
//#include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp>
|
//#todo
|
#include <basic/pipe_element/ffmpeg/FfmpegElement.cpp>
|
#include <QtCore/QStringList>
|
#include <QtCore/QDateTime>
|
#include <unistd.h>
|
#include <basic/pipe_element/ffmpeg/ffmpegRecoder/FileRecorder.h>
|
|
VideoMoveCaptureElement::VideoMoveCaptureElement(const std::string &path, const std::string &outPath,
|
int fps, int reOpenTime, int gpuIndex) :
|
basic::PipeElement(false), path(path), m_pathOut(outPath), gpuIndex(gpuIndex),
|
reopenTime(reOpenTime), outPutInterval(25), outPutIndex(0), bYoloDetect(false) //TODO25
|
{
|
|
}
|
|
void VideoMoveCaptureElement::threadFunc() {
|
// _timer.reset();
|
usleep(1);
|
u_char *data;
|
int width = 0, height = 0, step = 0, cn = 0;
|
bool ret = capture->grabFrame();
|
if (!ret) {
|
if (reopenTime < 0) {
|
stop();
|
INFO("grabFrame faild, element stopping" << path);
|
//INFO(_timerTotal.tell_ms());
|
return;
|
} else {
|
usleep(reopenTime * 1000);
|
INFO("grabFrame faild, try reopen video: " << path);
|
openVideo();
|
ret = capture->grabFrame();
|
if (!ret)return;
|
}
|
}
|
|
// DBG(_timer.tell_ns());
|
if (outPutInterval > 0 && (outPutIndex++ % outPutInterval != 0)) {
|
return;
|
}
|
|
capture->retrieveFrame(0, &data, &step, &width, &height, &cn);
|
try {
|
cv::Mat img(height, width, CV_8UC3, data, step);
|
cv::resize(img, image, cv::Size(192, 108), 0, 0, cv::INTER_LINEAR);
|
nChangeLevel = videoChangeScore.EvalChange(image);
|
} catch (std::exception ex) {
|
ERR("ex is " << ex.what());
|
}
|
|
|
|
// DBG(nChangeLevel);
|
|
fireConnectors();
|
|
}
|
|
int VideoMoveCaptureElement::getOutPutInterval() const {
|
return outPutInterval;
|
}
|
|
void VideoMoveCaptureElement::setOutPutInterval(int value) {
|
outPutInterval = value;
|
}
|
|
cv::Mat VideoMoveCaptureElement::getImage() const {
|
return image;
|
}
|
|
void VideoMoveCaptureElement::openVideo() {
|
if (gpuIndex >= 0) {
|
setenv("CUDA_VISIBLE_DEVICES", std::to_string(gpuIndex).c_str(), 0);
|
}
|
capture->open(path.c_str(), gpuIndex >= 0);
|
}
|
|
int VideoMoveCaptureElement::getOutPutIndex() const {
|
return outPutIndex;
|
}
|
|
void VideoMoveCaptureElement::startRecord(int startFrame) {
|
m_nFrame = startFrame;
|
}
|
|
void VideoMoveCaptureElement::endRecord(int endFrame) {
|
int startSec = m_nFrame / outPutInterval;
|
int endSec = endFrame / outPutInterval;
|
|
std::string start = std::to_string(startSec);
|
std::string end = std::to_string(endSec);
|
|
QString strPath = QString::fromStdString(path);
|
QStringList list = strPath.split("/");
|
QString fileName;
|
QString time;
|
QString strNewTime;
|
if (list.size() != 0) {
|
fileName = list.last();
|
time = fileName.split(".").first();
|
//#todo
|
// time = fileName.split("_").first();
|
} else {
|
ERR("list.size() == 0)");
|
}
|
|
if (!time.isEmpty()) {
|
QDateTime dt = QDateTime::fromString(time, "yyyy-MM-dd hh:mm:ss");
|
int second = m_nFrame / outPutInterval;
|
qint64 newTime = dt.toMSecsSinceEpoch() + second * 1000;
|
QDateTime newDt = QDateTime::fromMSecsSinceEpoch(newTime);
|
strNewTime = newDt.toString("yyyy-MM-dd hh:mm:ss");
|
}
|
|
//#todo m_pathOut + /
|
QString strNewPath = QString(m_pathOut.c_str()) + "/" + strNewTime + QString(".mp4");
|
|
fileRecord(path.c_str(), start.c_str(), endSec - startSec, strNewPath.toStdString().c_str());
|
}
|
|
bool VideoMoveCaptureElement::getBYoloDetect() const {
|
return bYoloDetect;
|
}
|
|
int VideoMoveCaptureElement::getChangeLevel() const {
|
return nChangeLevel;
|
}
|
|
void VideoMoveCaptureElement::threadInitial() {
|
capture = new CvCapture_FFMPEG;
|
openVideo();
|
//_timerTotal.reset();
|
}
|
|
void VideoMoveCaptureElement::threadClosing() {
|
capture->close();
|
delete capture;
|
capture = nullptr;
|
}
|
|
int VideoMoveCaptureElement::getM_nFrame() const {
|
return m_nFrame;
|
}
|