DevYK пре 3 година
родитељ
комит
06e6b92160
3 измењених фајлова са 12 додато и 5 уклоњено
  1. 2 1
      src/opencv/image_fingerprint.cpp
  2. 9 4
      src/utils/video_similarity.cpp
  3. 1 0
      src/utils/video_similarity.h

+ 2 - 1
src/opencv/image_fingerprint.cpp

@@ -42,7 +42,8 @@ const char *fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, int *len) {
     if (!frame)return NULL;
 
     if (1) {
-        char *buf = (char *) malloc(sizeof(char) * 8 * 8);
+        char *buf = (char *) av_malloc(sizeof(char) * 8 * 8);
+        memset((void *)buf, '\0',sizeof(char) * 8 * 8);
         for (int i = 0; i < 64; ++i) {
             buf[i] = 0;
         }

+ 9 - 4
src/utils/video_similarity.cpp

@@ -10,6 +10,7 @@
 #include "video_similarity.h"
 
 
+
 const int MAX_STACK_FRAMES = 128;
 
 void sig_crash(int sig) {
@@ -62,7 +63,7 @@ void sig_crash(int sig) {
             size_t pos2 = symbol.find_last_of("]");
             std::string address = symbol.substr(pos1 + 1, pos2 - pos1 -1);
             char cmd[128] = {0, };
-            sprintf(cmd, "addr2line -e video_similarity_comparison %s", address.c_str()); // test为应用程序名称,需要改为用户自己的应用程序名
+            sprintf(cmd, "addr2line -e /home/libpiaoquan_java_opencv.so %s", address.c_str()); // test为应用程序名称,需要改为用户自己的应用程序名
             FILE *fPipe = popen(cmd, "r");
             if(fPipe != NULL){
                 char buff[1024];
@@ -141,7 +142,10 @@ int video_similarity_detection_start(long id, int force_keyframe,
 
         if (len > 0) {
             model->image_hash = static_cast<const char *>(malloc(sizeof(char) * len));
-            memcpy((void *) model->image_hash, image_hash, len);
+            memset((void*)model->image_hash,'\0',sizeof(char) * len);
+            strcpy((char *)model->image_hash,image_hash);
+            if (image_hash)
+                free((void *) image_hash);
         }
 
         if (video_frame->pts >= endTimeMs && (*lists).size() > 1 && index + 1 < (*lists).size()) {
@@ -152,8 +156,8 @@ int video_similarity_detection_start(long id, int force_keyframe,
 //        LOGE("push pts >>>>= %lld \n", model->pts);
         (*lists)[index]->hashs.push_back(model);
         if (ctx->log)fprintf(ctx->log, "image_hash  \n");
-        if (image_hash)
-            free((void *) image_hash);
+
+        image_hash = NULL;
         if (ctx->log) fprintf(ctx->log, "av_frame_free\n");
         av_frame_free(&video_frame);
         if (ctx->log) fprintf(ctx->log, "av_frame_free 2\n");
@@ -240,6 +244,7 @@ const char *videoSimilarity2json(VideoSimilarity *videoSimilarity) {
                 }
                 va["imageHash"] = append_array.c_str();
                 free((void *) item2->image_hash);
+                item2->image_hash = NULL;
             }
             va["hashSize"] = item2->img_len;
             va["pts"] = item2->pts;

+ 1 - 0
src/utils/video_similarity.h

@@ -5,6 +5,7 @@
 #include "../ffmpeg/av_decode.h"
 #include "../opencv/image_fingerprint.h"
 #include "list"
+#include "string.h"
 
 #ifndef BYTESFLOW_OPENCV_MEDIA_VIDEO_SIMILARITY_H
 #define BYTESFLOW_OPENCV_MEDIA_VIDEO_SIMILARITY_H