From c5393484c24c4e33e9149d382893378d13cf4e76 Mon Sep 17 00:00:00 2001 From: zii Date: Wed, 3 Apr 2024 17:28:53 -0400 Subject: [PATCH] v3.4.t3 -added aud_codec to the conf file so audio codec is now a configurable option. -renamed stream_codec to vid_codec on the conf file to contrast aud_codec. -rtsp streams now use udp instead of tcp. -updated README with conf file changes. --- README.md | 19 ++++++++++++------- src/common.cpp | 40 +++++++++++++++++++++------------------- src/common.h | 5 +++-- src/services.cpp | 9 +++++---- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 3341bf3..0bafe1d 100644 --- a/README.md +++ b/README.md @@ -78,14 +78,20 @@ img_comp_out = stderr # use to output the comparison score. this can only be stderr or stdout, # any other stream name is considered invalid. # -stream_codec = copy +vid_codec = copy # this is the encoding codec to use when recording footage from the camera. # the list of supported codecs entirely depend on the hosts' ffmpeg # installation. run 'ffmpeg -codecs' to determine this list. if not # defined, 'copy' will be used as in it will just copy the codec format -# from camera itself. +# from the camera itself. # -stream_ext = .avi +aud_codec = copy +# this is the audio encoding codec to use when recording from the camera. +# the list of supported audio codes can be determined by running 'ffmpeg +# -codecs' on the host machine. if not defined, 'copy' will be used as in +# it will directly copy the audio stream from the camera if present. +# +stream_ext = .mkv # this is the file extension that will be used to when recording footage # from the camera in buffer_path. ffmpeg will also use this to determine # what format container to use for the video clips. @@ -94,7 +100,7 @@ thumbnail_ext = .jpg # this the image format that will be used when creating the thumbnails # for the videos clips recorded to rec_path. # -rec_ext = .avi +rec_ext = .mkv # this the the file extension that will be used when storing motion footage # to rec_path. ffmpeg will also use this to determine what format container # to use for the video clips. @@ -121,13 +127,12 @@ post_cmd = move_the_ptz_camera.py # rec_fps = 30 # this sets the recording frames per second for the footage recorded -# from the camera. this has no affect if using 'copy' as the -# stream_codec. +# from the camera. this has no affect if using 'copy' as the vid_codec. # rec_scale = 1280:720 # this sets the pixel scale of the recorded footage from the camera. it # uses width, height numeric strings seperated by a colon, eg W:H. this -# has no affect of using 'copy' as the stream_codec. +# has no affect of using 'copy' as the vid_codec. # img_scale = 320:240 # this sets the pixel size of the thumbnails for recorded stored in diff --git a/src/common.cpp b/src/common.cpp index 3cc5993..31e1470 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -216,24 +216,25 @@ bool rdConf(const QString &filePath, shared_t *share) auto thrCount = QThread::idealThreadCount() / 2; - share->retCode = 0; - share->imgThresh = 8000; - share->maxEvents = 30; - share->skipCmd = false; - share->postSecs = 60; - share->evMaxSecs = 30; - share->conf = filePath; - share->outputType = "stderr"; - share->compCmd = "magick compare -metric FUZZ " + QString(PREV_IMG) + " " + QString(NEXT_IMG) + " /dev/null"; - share->streamCodec = "copy"; - share->streamExt = ".avi"; - share->recExt = ".avi"; - share->thumbExt = ".jpg"; - share->recFps = 30; - share->liveSecs = 80; - share->recScale = "1280:720"; - share->imgScale = "320:240"; - share->servUser = APP_BIN; + share->retCode = 0; + share->imgThresh = 8000; + share->maxEvents = 30; + share->skipCmd = false; + share->postSecs = 60; + share->evMaxSecs = 30; + share->conf = filePath; + share->outputType = "stderr"; + share->compCmd = "magick compare -metric FUZZ " + QString(PREV_IMG) + " " + QString(NEXT_IMG) + " /dev/null"; + share->vidCodec = "copy"; + share->audCodec = "copy"; + share->streamExt = ".mkv"; + share->recExt = ".mkv"; + share->thumbExt = ".jpg"; + share->recFps = 30; + share->liveSecs = 80; + share->recScale = "1280:720"; + share->imgScale = "320:240"; + share->servUser = APP_BIN; QString line; @@ -254,7 +255,8 @@ bool rdConf(const QString &filePath, shared_t *share) rdLine("max_events = ", line, &share->maxEvents); rdLine("img_comp_out = ", line, &share->outputType); rdLine("img_comp_cmd = ", line, &share->compCmd); - rdLine("stream_codec = ", line, &share->streamCodec); + rdLine("vid_codec = ", line, &share->vidCodec); + rdLine("aud_codec = ", line, &share->audCodec); rdLine("stream_ext = ", line, &share->streamExt); rdLine("rec_ext = ", line, &share->recExt); rdLine("thumbnail_ext = ", line, &share->thumbExt); diff --git a/src/common.h b/src/common.h index b5750fd..062a11f 100644 --- a/src/common.h +++ b/src/common.h @@ -30,7 +30,7 @@ using namespace std; -#define APP_VER "3.4.t2" +#define APP_VER "3.4.t3" #define APP_NAME "Motion Watch" #define APP_BIN "mow" #define DATETIME_FMT "yyyyMMddhhmmss" @@ -65,7 +65,8 @@ struct shared_t QString recPath; QString outputType; QString compCmd; - QString streamCodec; + QString vidCodec; + QString audCodec; QString streamExt; QString recExt; QString thumbExt; diff --git a/src/services.cpp b/src/services.cpp index 6674a38..a83282c 100644 --- a/src/services.cpp +++ b/src/services.cpp @@ -46,7 +46,7 @@ int loadService(const QString &desc, const QString &user, const QString &servNam if (servName.contains("vid_loop")) { - file.write("RuntimeMaxSec=62\n"); + file.write("RuntimeMaxSec=61\n"); } file.write("ExecStart=/usr/bin/env " + servName.toUtf8() + "\n\n"); @@ -116,15 +116,16 @@ QString camCmdFromConf(shared_t *conf, CmdExeType type) if (conf->recordUri.contains("rtsp")) { - ret += "-rtsp_transport tcp "; + ret += "-rtsp_transport udp "; } - if (conf->streamCodec != "copy") + if (conf->vidCodec != "copy") { ret += "-vf fps=" + QString::number(conf->recFps) + ",scale=" + conf->recScale + " "; } - ret += "-vcodec " + conf->streamCodec + " "; + ret += "-vcodec " + conf->vidCodec + " "; + ret += "-acodec " + conf->audCodec + " "; ret += "-reset_timestamps 1 -sc_threshold 0 -g 2 -force_key_frames \"expr:gte(t, n_forced * 2)\" -t 60 -segment_time 2 -f segment "; ret += conf->buffPath + "/live/" + QString(STRFTIME_FMT) + conf->streamExt; }