From 5fa2fb92903e1641a64079c2ff73482b646f8390 Mon Sep 17 00:00:00 2001 From: MrDave Date: Sat, 3 Jul 2021 18:04:39 -0600 Subject: [PATCH] Fix movie file names --- src/alg_sec.cpp | 6 +++--- src/event.cpp | 23 +++++++++++++++++++---- src/movie.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index 84376dc6..7baaa90e 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -52,9 +52,9 @@ static void algsec_img_show(ctx_cam *cam, Mat &mat_src std::vector param(2); char wstr[10]; + (void)algmethod; testdir = cam->conf->target_dir; - - imwrite(testdir + "/src_" + algmethod + ".jpg", mat_src); + //imwrite(testdir + "/src_" + algmethod + ".jpg", mat_src); algmdl.isdetected = false; for (indx0=0; indx0conf->movie_retain == "secondary") && (cam->algsec_inuse)) { if (cam->algsec->isdetected == false) { - remove(cam->extpipefilename); + retcd = remove(cam->extpipefilename); + if (retcd != 0) { + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO + , _("Unable to remove file %s"), cam->extpipefilename); + } } else { event(cam, EVENT_FILECLOSE, NULL, cam->extpipefilename, (void *)FTYPE_MPEG, ts1); } @@ -511,7 +516,6 @@ static void event_extpipe_end(struct ctx_cam *cam, motion_event evnt event(cam, EVENT_FILECLOSE, NULL, cam->extpipefilename, (void *)FTYPE_MPEG, ts1); } - } } @@ -742,6 +746,7 @@ static void event_movie_closefile(struct ctx_cam *cam, motion_event evnt ,struct ctx_image_data *img_data, char *fname, void *ftype, struct timespec *ts1) { + int retcd; (void)evnt; (void)img_data; (void)fname; @@ -753,9 +758,14 @@ static void event_movie_closefile(struct ctx_cam *cam, motion_event evnt free(cam->movie_norm); } cam->movie_norm = NULL; + if ((cam->conf->movie_retain == "secondary") && (cam->algsec_inuse)) { if (cam->algsec->isdetected == false) { - remove(cam->newfilename); + retcd = remove(cam->newfilename); + if (retcd != 0) { + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO + , _("Unable to remove file %s"), cam->newfilename); + } } else { event(cam, EVENT_FILECLOSE, NULL, cam->newfilename, (void *)FTYPE_MPEG, ts1); } @@ -769,10 +779,15 @@ static void event_movie_closefile(struct ctx_cam *cam, motion_event evnt if (cam->movie_motion != NULL) { free(cam->movie_motion); } + cam->movie_motion = NULL; if ((cam->conf->movie_retain == "secondary") && (cam->algsec_inuse)) { if (cam->algsec->isdetected == false) { - remove(cam->motionfilename); + retcd = remove(cam->motionfilename); + if (retcd != 0) { + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO + , _("Unable to remove file %s"), cam->motionfilename); + } } else { event(cam, EVENT_FILECLOSE, NULL, cam->motionfilename, (void *)FTYPE_MPEG_MOTION, ts1); } diff --git a/src/movie.cpp b/src/movie.cpp index 1cec367c..e0884a74 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -1746,6 +1746,16 @@ int movie_init_norm(struct ctx_cam *cam, struct timespec *ts1) retcd = movie_open(cam->movie_norm); + if (retcd == 0) { + /* We set this after the movie open so we get the extension */ + retcd = snprintf(cam->newfilename, PATH_MAX, "%s",cam->movie_norm->filename); + if ((retcd < 0) || (retcd >= PATH_MAX)) { + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO + ,_("Error setting file name")); + return -1; + } + } + return retcd; } @@ -1798,6 +1808,15 @@ int movie_init_motion(struct ctx_cam *cam, struct timespec *ts1) retcd = movie_open(cam->movie_motion); + if (retcd == 0) { + retcd = snprintf(cam->motionfilename, PATH_MAX, "%s",cam->movie_motion->filename); + if ((retcd < 0) || (retcd >= PATH_MAX)) { + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO + ,_("Error setting file name")); + return -1; + } + } + return retcd; } @@ -1858,6 +1877,15 @@ int movie_init_timelapse(struct ctx_cam *cam, struct timespec *ts1) retcd = movie_open(cam->movie_timelapse); } + if (retcd == 0) { + retcd = snprintf(cam->timelapsefilename, PATH_MAX, "%s",cam->movie_timelapse->filename); + if ((retcd < 0) || (retcd >= PATH_MAX)) { + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO + ,_("Error setting file name")); + return -1; + } + } + return retcd; }