20240203
This commit is contained in:
parent
f0fca0b741
commit
767e14e8d7
|
@ -1,7 +1,6 @@
|
|||
#include "HxDevice.h"
|
||||
|
||||
HxDevice::HxDevice(int millisecond)
|
||||
: HxThread{ millisecond }
|
||||
HxDevice::HxDevice()
|
||||
{
|
||||
type = -1;
|
||||
frame_id = 0;
|
||||
|
@ -36,7 +35,7 @@ void HxDevice::startup(int type, QString url, QString file)
|
|||
{
|
||||
HxTask::run(this, &HxDevice::frame_read_process, 5000, "_frame_read_process");
|
||||
|
||||
this->start();
|
||||
HxTask::run(this, &HxDevice::frame_decode_process, 5, "_frame_decode_process");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +67,8 @@ void HxDevice::frame_read_process(void)
|
|||
mutex.lock();
|
||||
frames.enqueue(mat);
|
||||
mutex.unlock();
|
||||
msleep(10);
|
||||
|
||||
QThread::msleep(10);
|
||||
}
|
||||
|
||||
/* 关闭,释放 */
|
||||
|
@ -77,6 +77,34 @@ void HxDevice::frame_read_process(void)
|
|||
HxTrace::debug_write_line("videolivestream", QString("type=%1, video close").arg(type));
|
||||
}
|
||||
|
||||
void HxDevice::frame_decode_process(void)
|
||||
{
|
||||
if (frames.isEmpty())
|
||||
return;
|
||||
|
||||
mutex.lock();
|
||||
auto frame = frames.dequeue();
|
||||
mutex.unlock();
|
||||
|
||||
if (frame.data != nullptr)
|
||||
{
|
||||
if (car_info.fVelocity >= 10)
|
||||
{
|
||||
bgr_frame_buffer.nFrameId = frame_id; // 帧号
|
||||
bgr_frame_buffer.u64PTS = QDateTime::currentMSecsSinceEpoch(); // 时间戳(毫秒)
|
||||
memcpy(bgr_frame_buffer.pu8VirAddr, frame.data, 1280 * 720 * 3);
|
||||
|
||||
mv_convert_images(&bgr_frame_buffer, &detect_frame_buffer); // bgr->nv16
|
||||
#if USE_ALGORITHM
|
||||
MvObjectEventDetect(type, &detect_frame_buffer, &car_info);
|
||||
|
||||
HxTrace::debug_write_line("device", QString("send frame_id=%1").arg(frame_id + 1));
|
||||
#endif
|
||||
frame_id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int HxDevice::mv_convert_images(VideoFrameDataInfo *src_buffer, VideoFrameDataInfo *dst_buffer)
|
||||
{
|
||||
Q_UNUSED(src_buffer);
|
||||
|
@ -111,36 +139,3 @@ int HxDevice::mv_convert_images(VideoFrameDataInfo *src_buffer, VideoFrameDataIn
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HxDevice::action()
|
||||
{
|
||||
if (frames.isEmpty())
|
||||
return;
|
||||
|
||||
mutex.lock();
|
||||
auto frame = frames.dequeue();
|
||||
mutex.unlock();
|
||||
|
||||
if (frame.data != nullptr)
|
||||
{
|
||||
if (car_info.fVelocity >= 10)
|
||||
{
|
||||
bgr_frame_buffer.nFrameId = frame_id; // 帧号
|
||||
bgr_frame_buffer.u64PTS = QDateTime::currentMSecsSinceEpoch(); // 时间戳(毫秒)
|
||||
memcpy(bgr_frame_buffer.pu8VirAddr, frame.data, 1280 * 720 * 3);
|
||||
|
||||
mv_convert_images(&bgr_frame_buffer, &detect_frame_buffer); // bgr->nv16
|
||||
#if USE_ALGORITHM
|
||||
MvObjectEventDetect(type, &detect_frame_buffer, &car_info);
|
||||
|
||||
// HxTrace::debug_write_line("device", QString("send frame_id=%1").arg(frame_id + 1));
|
||||
#endif
|
||||
frame_id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HxDevice::continue_with()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -9,21 +9,17 @@ typedef enum __CONNECTION_TYPE_
|
|||
Rtsp = 1,
|
||||
}connection_type;
|
||||
|
||||
class HxDevice : public HxThread
|
||||
class HxDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HxDevice(int millisecond = 1);
|
||||
HxDevice();
|
||||
void startup(int type, QString url, QString file = "");
|
||||
|
||||
private:
|
||||
void frame_read_process(void);
|
||||
void frame_decode_process(void);
|
||||
int mv_convert_images(VideoFrameDataInfo *src_buffer, VideoFrameDataInfo *dst_buffer);
|
||||
|
||||
protected:
|
||||
void action() override;
|
||||
void continue_with() override;
|
||||
|
||||
private:
|
||||
int type;
|
||||
int connection_type;
|
||||
|
|
|
@ -54,24 +54,24 @@ unix {
|
|||
}
|
||||
|
||||
|
||||
# LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_linux.a
|
||||
# LIBS += -L/usr/local/lib -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_core
|
||||
# LIBS += -L/usr/local/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswresample -lswscale
|
||||
LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_linux.a
|
||||
LIBS += -L/usr/local/lib -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_core
|
||||
LIBS += -L/usr/local/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswresample -lswscale
|
||||
|
||||
LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_arm64.a
|
||||
LIBS += /usr/lib/libopencv_highgui.so.3.4 \
|
||||
/usr/lib/libopencv_imgproc.so.3.4 \
|
||||
/usr/lib/libopencv_imgcodecs.so.3.4 \
|
||||
/usr/lib/libopencv_videoio.so.3.4 \
|
||||
/usr/lib/libopencv_core.so.3.4 \
|
||||
/usr/lib/libavcodec.so.58 \
|
||||
/usr/lib/libavdevice.so.58 \
|
||||
/usr/lib/libavfilter.so.7 \
|
||||
/usr/lib/libavformat.so.58 \
|
||||
/usr/lib/libavutil.so.56 \
|
||||
/usr/lib/libpostproc.so.55 \
|
||||
/usr/lib/libswresample.so.3 \
|
||||
/usr/lib/libswscale.so.5
|
||||
# LIBS += $$PWD/../resources/libraries/HxUtils/lib/libHxUtils_aarch.a
|
||||
# LIBS += /usr/lib/libopencv_highgui.so.3.4 \
|
||||
# /usr/lib/libopencv_imgproc.so.3.4 \
|
||||
# /usr/lib/libopencv_imgcodecs.so.3.4 \
|
||||
# /usr/lib/libopencv_videoio.so.3.4 \
|
||||
# /usr/lib/libopencv_core.so.3.4 \
|
||||
# /usr/lib/libavcodec.so.58 \
|
||||
# /usr/lib/libavdevice.so.58 \
|
||||
# /usr/lib/libavfilter.so.7 \
|
||||
# /usr/lib/libavformat.so.58 \
|
||||
# /usr/lib/libavutil.so.56 \
|
||||
# /usr/lib/libpostproc.so.55 \
|
||||
# /usr/lib/libswresample.so.3 \
|
||||
# /usr/lib/libswscale.so.5
|
||||
}
|
||||
|
||||
win32 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "main.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "HxDevice.h"
|
||||
|
||||
|
@ -40,6 +40,13 @@ int main(int argc, char* argv[])
|
|||
|
||||
car_info.fVelocity = 50;
|
||||
|
||||
/* 向服务程序发送 心跳数据 */
|
||||
HxTask::run([=]()
|
||||
{
|
||||
HxBroadcast::publish_json(0, { {"name", "HxIVA"}, {"version", "1.00"} });
|
||||
|
||||
}, 5000, "heart_third");
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -115,7 +116,7 @@ namespace HxServer.Peripheral
|
|||
DataBase.ReplaceIVARecord(data);
|
||||
|
||||
/* 产生预录报警数据 */
|
||||
MonitorServer.SendMessage("HxVideoCaptor", new Model(10, new { timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), uuid = uuid, channel = data.Channel, id = data.EventType }));
|
||||
MonitorServer.SendMessage("HxVideoCaptor", new Model(10, new { timestamp = data.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"), uuid = uuid, channel = data.Channel, id = data.EventType }));
|
||||
|
||||
/* 等待结果 30s超时 */
|
||||
TaskUtils.Wait(() =>
|
||||
|
@ -128,15 +129,40 @@ namespace HxServer.Peripheral
|
|||
{
|
||||
if (result != null)
|
||||
{
|
||||
|
||||
/* 生成图片 */
|
||||
var alarm_recording_prepend_time = DataBase.ReadSettings()["alarm_recording_prepend_time"];
|
||||
System.Diagnostics.Process.Start($"ffmpeg -ss 00:00:{alarm_recording_prepend_time:D2} -i {result.FilePath} test.jpg -r 1 -vframes 1 -an -f mjepg");
|
||||
//data.ImagePath = $"";
|
||||
var settings = DataBase.ReadSettings();
|
||||
var disks = settings["disks"].ToString().Split(";");
|
||||
var drivers = DriveInfo.GetDrives();
|
||||
var alarm_recording_prepend_time = Convert.ToInt32(settings["alarm_recording_prepend_time"]);
|
||||
|
||||
foreach (var driver in drivers)
|
||||
DebugTrace.WriteLine(nameof(HxIVA), $"disk: {driver.Name}");
|
||||
|
||||
string root_path = "";
|
||||
foreach (var disk in disks)
|
||||
{
|
||||
DriveInfo driver;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
driver = drivers.FirstOrDefault(d => d.Name == disk.Replace(":/", ":\\"));
|
||||
else
|
||||
driver = drivers.FirstOrDefault(d => d.Name == disk);
|
||||
|
||||
if (driver != null)
|
||||
root_path = Path.Combine(driver.Name, "HXNVR_IMAGE", $"{DateTime.Now:yyyyMMdd}", $"{data.Channel + 1}:D2");
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(root_path);
|
||||
|
||||
data.ImagePath = Path.Combine(root_path, FileUtils.GetName(result.FilePath).Replace(".avi", ".jpg"));
|
||||
data.RecordPath = result.FilePath;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
System.Diagnostics.Process.Start("D:/Library/ffmpeg/4.0.2/bin/ffmpeg.exe", $"-ss 00:00:{alarm_recording_prepend_time:D2} -i {result.FilePath} {data.ImagePath} -r 1 -vframes 1 -an -f mjepg");
|
||||
else
|
||||
System.Diagnostics.Process.Start("ffmpeg", $"-ss 00:00:{alarm_recording_prepend_time:D2} -i {result.FilePath} test.jpg -r 1 -vframes 1 -an -f mjepg");
|
||||
|
||||
/* 更新数据库 */
|
||||
data.RecordPath = result.FilePath;
|
||||
DataBase.ReplaceIVARecord(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ extern "C"
|
|||
{"name", record.name}, \
|
||||
{"path", record.path}})
|
||||
/* 发送预录视频路径 */
|
||||
#define WRITE_PRE_RECORD_STATUS(uuid, filepath) HxBroadcast::publish_json(10, {{"uuid", uuid}, \
|
||||
{"filepath", filepath}})
|
||||
#define WRITE_PRE_RECORD_STATUS(uuid, filepath) HxBroadcast::publish_json(10, {{"uuid", uuid}, {"filepath", filepath}})
|
||||
|
||||
typedef enum { Null, Recording, Recorded, } RecordStatus;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user