Pārlūkot izejas kodu

disable debug log

ehlxr 3 gadi atpakaļ
vecāks
revīzija
3ad2e00c41

+ 5 - 3
CMakeLists.txt

@@ -34,7 +34,7 @@ set(JAVA_HOME $ENV{JAVA_HOME})
 message(JAVA_HOME ${JAVA_HOME})
 if (NOT DEFINED ENV{JAVA_HOME})
     message("not defined environment variable:JAVA_HOME")
-    set(JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home)
+    set(JAVA_HOME /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home)
     set(JNI_PATH ${JAVA_HOME}/include)
 endif ()
 
@@ -61,12 +61,14 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
     set(JNI_PATH ${JAVA_HOME}/include)
     set(JNI_MD_PATH ${JAVA_HOME}/include/darwin)
     include_directories(${JNI_PATH})
-    set(OPENCV_HOME /usr/local/Cellar/opencv/4.5.4_4)
+    set(OPENCV_HOME /opt/homebrew/Cellar/opencv/4.5.5_2)
+    #     set(OPENCV_HOME /usr/opt/Cellar/opencv/4.5.4_4)
     set(OPENCV_INCLUDE ${OPENCV_HOME}/include/opencv4)
     set(OPENCV_LIBS ${OPENCV_HOME}/lib)
 
 
-    set(FFMPEG_PREFIX /usr/local/Cellar/ffmpeg@4/4.4.1)
+    #     set(FFMPEG_PREFIX /usr/local/Cellar/ffmpeg@4/4.4.1)
+    set(FFMPEG_PREFIX /opt/homebrew/Cellar/ffmpeg@4/4.4.2_2)
     set(FFMPEG_INCLUDE_DIRS ${FFMPEG_PREFIX}/include/)
     set(FFMPEG_LIBS ${FFMPEG_PREFIX}/lib/)
     MESSAGE(FFMPEG_PREFIX ${FFMPEG_PREFIX})

+ 1 - 1
build.sh

@@ -3,7 +3,7 @@
 mkdir build && cd build
 
 #Release Debug
-cmake -DCMAKE_BUILD_TYPE=Release ..
+cmake -DCMAKE_BUILD_TYPE=Debug ..
 
 make -j4
 

+ 1 - 1
java/src/com.bytesflow.opencv.media/test/OpenCVImageBlurTest.java

@@ -13,7 +13,7 @@ import java.util.concurrent.Executors;
 
 public class OpenCVImageBlurTest {
     private static String sIMAGE_PATH = "/Users/devyk/Downloads/IMG_3067.PNG";
-    private static String sSO_PATH = "/Users/devyk/Data/Project/piaoquan/OpenCVSample/output/lib/libpiaoquan_java_opencv.dylib";
+    private static String sSO_PATH = "/Users/ehlxr/Workspaces/tzld/PQCVMedia/output/lib/libpiaoquan_java_opencv.dylib";
 
     private static boolean TEST_COMPARE = true;
     private static String[] sVIS = {

+ 13 - 13
jni/ImageBlurDetection.cpp

@@ -11,7 +11,7 @@
 const int MAX_STACK_FRAMES = 128;
 
 void sig_crash(int sig) {
-    printf("crash---->sig=%d \n", sig);
+    // printf("crash---->sig=%d \n", sig);
     FILE *fd;
     struct stat buf;
     const char *crash_path = "./video_similarity_comparison_crash.txt";
@@ -38,7 +38,7 @@ void sig_crash(int sig) {
                             now->tm_min,
                             now->tm_sec,
                             sig);
-        printf("crash---->%s \n", szLine);
+        // printf("crash---->%s \n", szLine);
         fwrite(szLine, 1, strlen(szLine), fd);
 #ifdef __linux
         void* array[MAX_STACK_FRAMES];
@@ -74,12 +74,12 @@ void sig_crash(int sig) {
     } catch (...) {
         //
     }
-    printf("sig_crash fflush  1\n");
+    // printf("sig_crash fflush  1\n");
     fflush(fd);
-    printf("sig_crash fclose  2\n");
+    // printf("sig_crash fclose  2\n");
     fclose(fd);
     fd = NULL;
-    printf("sig_crash exit  3\n");
+    // printf("sig_crash exit  3\n");
     exit(0);
 }
 
@@ -100,17 +100,17 @@ static jfloat Java_JNI_OpenCV_GetVideoSimilarityValue(JNIEnv *env, jobject obj,
 }
 
 static jstring Java_JNI_OpenCV_GetVideoSimilarityLists(JNIEnv *env, jobject obj, jstring filepath) {
-    LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists\n ")
+    // LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists\n ")
     const char *image_path = env->GetStringUTFChars(filepath, 0);
     const char *ret_json = get_video_similarity_list(image_path);
     env->ReleaseStringUTFChars(filepath, image_path);
-    LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists\n")
+    // LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists\n")
     if (ret_json) {
-        LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists NewStringUTF \n")
+        // LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists NewStringUTF \n")
         jstring str = env->NewStringUTF(ret_json);
-        LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists NewStringUTF 1\n")
+        // LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists NewStringUTF 1\n")
         free((void *) ret_json);
-        LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists NewStringUTF out\n")
+        // LOGE("Java_JNI_OpenCV_GetVideoSimilarityLists NewStringUTF out\n")
         ret_json = NULL;
         return str;
     }
@@ -143,16 +143,16 @@ static const JNINativeMethod configMethods[] = {
 int JNI_OnLoad(JavaVM *vm, void *pVoid) {
     JNIEnv *jniEnv;
     if (vm->GetEnv(reinterpret_cast<void **>(&jniEnv), JNI_VERSION_1_6) != JNI_OK) {
-        printf(" JNI_OnLoad  1 error.\n");
+        // printf(" JNI_OnLoad  1 error.\n");
         return JNI_ERR;
     }
     jclass jcls = jniEnv->FindClass(JAVA_JNI_CLASS_PATH);
     if (jniEnv->RegisterNatives(jcls, configMethods, NELEM(configMethods)) != JNI_OK) {
-        printf(" JNI_OnLoad  error.\n");
+        // printf(" JNI_OnLoad  error.\n");
         return JNI_ERR;
     }
 //    signal(SIGABRT, sig_crash);
 //    signal(SIGSEGV, sig_crash);
-    printf(" JNI_OnLoad  ok.\n");
+    // printf(" JNI_OnLoad  ok.\n");
     return JNI_VERSION_1_6;
 };

+ 34 - 31
src/ffmpeg/av_decode.cpp

@@ -16,21 +16,21 @@ openFFmpegDecoderContext(AVFormatContext *fmtCtx, enum AVMediaType type, int *st
     AVCodec *codec = avcodec_find_decoder(codecId);
     if (codec == NULL) {
         if (codecId == AV_CODEC_ID_PNG)
-            LOGE("openFFmpegDecoderContext avcodec_find_decoder png not found. \n");
-        LOGE("openFFmpegDecoderContext avcodec_find_decoder=%d not found. \n", codecId);
+        //     LOGE("openFFmpegDecoderContext avcodec_find_decoder png not found. \n");
+        // LOGE("openFFmpegDecoderContext avcodec_find_decoder=%d not found. \n", codecId);
         return -1;
     }
     ctx = avcodec_alloc_context3(codec);
 
     if (!ctx || !parameters || !codec) {
-        LOGE("openFFmpegDecoderContext init error %d ctx==null=%d  parameters==null=%d  codec==null=%d \n", codecId,
-             ctx == NULL, parameters == NULL, codec == NULL);
+        // LOGE("openFFmpegDecoderContext init error %d ctx==null=%d  parameters==null=%d  codec==null=%d \n", codecId,
+        //      ctx == NULL, parameters == NULL, codec == NULL);
         return -1;
     }
 
 
     if ((ret = avcodec_parameters_to_context(ctx, parameters)) != 0) {
-        Log("Failed to copy %s codec parameters to decoder context.", av_get_media_type_string(type));
+        // Log("Failed to copy %s codec parameters to decoder context.", av_get_media_type_string(type));
         return -1;
     }
 
@@ -46,7 +46,7 @@ openFFmpegDecoderContext(AVFormatContext *fmtCtx, enum AVMediaType type, int *st
     if ((ret = avcodec_open2(ctx, codec, NULL)) != 0) {
         char buf[512];
         av_strerror(ret, buf, 512);
-        LOGE("Failed to open %s codec. error=%s \n", av_get_media_type_string(type), buf);
+        // LOGE("Failed to open %s codec. error=%s \n", av_get_media_type_string(type), buf);
         return -1;
     }
     *decCtx = ctx;
@@ -146,16 +146,16 @@ static int av_decode(struct DecoderContext *pContext, AVPacket *pPacket, enum AV
 
 /**
  * 初始化解码器
- * @param url 
- * @param outVideoFormat 
- * @param force_Iframe 
+ * @param url
+ * @param outVideoFormat
+ * @param force_Iframe
  * @param end_time
- * @return 
+ * @return
  */
 long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMediaType) {
     struct DecoderContext *dctx = (struct DecoderContext *) malloc(sizeof(struct DecoderContext));
     if (!dctx) {
-        LOGE("DecoderContext create fail.");
+        // LOGE("DecoderContext create fail.");
         return -1;
     }
     memset(dctx, 0, sizeof(struct DecoderContext));
@@ -167,11 +167,14 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
     dctx->disableType = disableMediaType;
     char err_info[512] = {0};
     avformat_network_init();
+
+    av_log_set_level(AV_LOG_PANIC);
+
     int ret = avformat_open_input(&(dctx->avformatContext), dctx->url, NULL, NULL);
 
     if (ret != 0) {
         av_strerror(ret, err_info, 512);
-        Log("avformat_open_input failed %d %s. path=%s \n", ret, err_info, dctx->url);
+        // Log("avformat_open_input failed %d %s. path=%s \n", ret, err_info, dctx->url);
         close_decoder((long) dctx);
         return ret;
     }
@@ -179,7 +182,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
     ret = avformat_find_stream_info(dctx->avformatContext, 0);
     if (ret < 0) {
         av_strerror(ret, err_info, 512);
-        Log("Failed to retrieve input stream information msg=%s\n", err_info);
+        // Log("Failed to retrieve input stream information msg=%s\n", err_info);
         close_decoder((long) dctx);
         return ret;
     }
@@ -197,7 +200,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
 
     if (dctx->st_index[AVMEDIA_TYPE_VIDEO] <0)
     {
-        LOGE("video stream not found.");
+        // LOGE("video stream not found.");
 //        return -1;
     }
 
@@ -229,9 +232,9 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
         dctx->fps = av_q2d(as->avg_frame_rate);//拿到视频码率
         dctx->rotate = getVideoRotate(as->metadata);
 
-        LOGE("找到视频流 width=%d height=%d bit_rate=%d fps=%d rotate=%d\n", dctx->width,
-             dctx->height, dctx->v_bit_rate, dctx->fps,
-             dctx->rotate);
+        // LOGE("找到视频流 width=%d height=%d bit_rate=%d fps=%d rotate=%d\n", dctx->width,
+        //      dctx->height, dctx->v_bit_rate, dctx->fps,
+        //      dctx->rotate);
 
     }
     if (dctx->st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
@@ -242,19 +245,19 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
         dctx->a_bit_rate = as->codecpar->bit_rate;
         dctx->aformat = as->codecpar->format;
         dctx->channels_layout = as->codecpar->channel_layout;
-        LOGE("找到音频流 sampleRate=%d channels=%d bit_rate=%d aformat=%d channels_layout=%d\n",
-             dctx->sampleRate, dctx->channels, dctx->a_bit_rate,
-             dctx->aformat, dctx->channels_layout);
+        // LOGE("找到音频流 sampleRate=%d channels=%d bit_rate=%d aformat=%d channels_layout=%d\n",
+        //      dctx->sampleRate, dctx->channels, dctx->a_bit_rate,
+        //      dctx->aformat, dctx->channels_layout);
 
 
     }
     dctx->totalMs = dctx->avformatContext->duration / (AV_TIME_BASE / 1000);
     if (dctx->start_time > dctx->totalMs) {
-        LOGE("媒体总时长 totalMs=%lld start_time=%lld \n", dctx->totalMs, dctx->start_time);
+        // LOGE("媒体总时长 totalMs=%lld start_time=%lld \n", dctx->totalMs, dctx->start_time);
         return -1;
     }
 
-    LOGE("媒体总时长 totalMs=%lld \n", dctx->totalMs);
+    // LOGE("媒体总时长 totalMs=%lld \n", dctx->totalMs);
     if (dctx->avformatContext->start_time != AV_NOPTS_VALUE)
         dctx->offset = dctx->avformatContext->start_time;
 
@@ -265,7 +268,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
                                        &dctx->audioCodecContext, dctx->a_codec_id);
 
         if (ret != 0) {
-            LOGE("audio openFFmpegDecoderContext error!");
+            // LOGE("audio openFFmpegDecoderContext error!");
             close_decoder((long) dctx);
             return ret;
         }
@@ -278,7 +281,7 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
                                        &dctx->st_index[AVMEDIA_TYPE_VIDEO],
                                        &dctx->videoCodecContext, dctx->v_codec_id);
         if (ret != 0) {
-            LOGE("video openFFmpegDecoderContext error!");
+            // LOGE("video openFFmpegDecoderContext error!");
             close_decoder((long) dctx);
             return ret;
         }
@@ -328,7 +331,7 @@ void seekToMs(DecoderContext *dctx, int64_t offset) {
 }
 
 void close_decoder(long decodec_id) {
-    LOGE("close_decoder \n");
+    // LOGE("close_decoder \n");
     if (decodec_id > 0) {
         struct DecoderContext *ctx = (struct DecoderContext *) decodec_id;
         if (ctx->url) {
@@ -382,7 +385,7 @@ void close_decoder(long decodec_id) {
         ctx = NULL;
 
     }
-    LOGE("close_decoder out\n");
+    // LOGE("close_decoder out\n");
 }
 
 int av_read_decode_frame(long decodec_id) {
@@ -411,11 +414,11 @@ void *av_read_decode_thread(void *pVoid) {
                     AVPacket *pkg = av_packet_alloc();
                     ret = av_read_frame(ctx->avformatContext, pkg);
                     if (ret == AVERROR_EOF) {
-                        LOGE("startDecoder flush \n");
+                        // LOGE("startDecoder flush \n");
                         av_decode(ctx, NULL, AVMEDIA_TYPE_VIDEO);
                         av_decode(ctx, NULL, AVMEDIA_TYPE_AUDIO);
                         av_packet_free(&pkg);
-                        LOGE("av_read_frame eof!\n");
+                        // LOGE("av_read_frame eof!\n");
                         break;
                     }
 
@@ -461,12 +464,12 @@ void *av_read_decode_thread(void *pVoid) {
             }
         }
         if (ctx->audio_queue){
-            LOGE("push empty packet audio !\n");
+            // LOGE("push empty packet audio !\n");
             ctx->audio_queue->PushBack(NULL);
         }
-        LOGE("push empty packet video !\n");
+        // LOGE("push empty packet video !\n");
         ctx->video_queue->PushBack(NULL);
     }
-    LOGE("read thread exit !\n");
+    // LOGE("read thread exit !\n");
     pthread_exit(NULL);
 }

+ 8 - 0
src/utils/video_similarity.cpp

@@ -34,6 +34,14 @@ static const char *GetFileName(const char *ptr, int n) {
     return ptr; //反回最后一个/后面的字符串即名称
 }
 
+/**
+ * 视频相似检查开始
+ * @param id
+ * @param force_keyframe
+ * @param disableMediaType
+ * @param lists
+ * @return
+ */
 int video_similarity_detection_start(long id, int force_keyframe,
                                      DisableMediaType disableMediaType,
                                      std::vector<VideoSimilarityModel *> *lists) {