From c2f1761ea981f1b7ef380fbe8918baa8bdb29d17 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Sat, 14 Sep 2024 16:16:15 +0800 Subject: [PATCH] fix --- .idea/.gitignore | 8 ++++ .idea/deployment.xml | 15 ++++++ .idea/inspectionProfiles/Project_Default.xml | 47 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/remote-mappings.xml | 10 ++++ .idea/scripts.iml | 8 ++++ .idea/vcs.xml | 6 +++ cronjob/media/vd_compress.py | 46 +++++++++++------- media/calc_10bit.py | 2 +- 11 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/deployment.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/remote-mappings.xml create mode 100644 .idea/scripts.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..915080f --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..27bd85f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,47 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a9ef76c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bb83e26 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/remote-mappings.xml b/.idea/remote-mappings.xml new file mode 100644 index 0000000..8df7aba --- /dev/null +++ b/.idea/remote-mappings.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/scripts.iml b/.idea/scripts.iml new file mode 100644 index 0000000..d8e9ed3 --- /dev/null +++ b/.idea/scripts.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cronjob/media/vd_compress.py b/cronjob/media/vd_compress.py index e62bd6b..1aa8892 100644 --- a/cronjob/media/vd_compress.py +++ b/cronjob/media/vd_compress.py @@ -1,6 +1,5 @@ -import os -import time - +from aliyunsdkcore.client import AcsClient +from aliyunsdkcore.request import CommonRequest from lib.all import * import ffmpy import cv2 @@ -8,19 +7,34 @@ import oss2 import subprocess service_name = 'vd_compress' -# log_dir = '/app/log' -log_dir = '/Users/erwin/data/log' +log_dir = '/app/log' +# log_dir = '/Users/erwin/data/log' logger = Logger(service_name, log_dir=log_dir, print_terminal=False) access_key_id = "LTAI5tAdu5LRvZwm4LJa21Fo" access_key_secret = "WGvSQsDralTfFAAxhEqLBOgbXqflHo" -endpoint_internal = "https://oss-cn-hangzhou.aliyuncs.com" +endpoint_internal = "https://oss-cn-hangzhou-internal.aliyuncs.com" bucket_name = "wishpal-ironfan-media" bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint_internal, bucket_name) url_get_videos_by_status = "https://api.tiefen.fun/op/media/get_videos_by_status" url_update_video_compress = "https://api.tiefen.fun/op/media/update_video_compress" -hw_cdn_host = "https://filecdn01.tiefen.fun/" +cdn_host = "https://filecdn01.tiefen.fun/" +acs_client = AcsClient(access_key_id, access_key_secret, 'cn-hangzhou') + + +def refresh_cdn_cache(url): + request = CommonRequest() + request.set_domain('cdn.aliyuncs.com') + request.set_version('2018-05-10') + request.set_action_name('RefreshObjectCaches') + request.set_method('POST') + + request.add_query_param('ObjectPath', url) + request.add_query_param('ObjectType', 'File') # 可以是 'File' 或 'Directory' + + response = acs_client.do_action_with_exception(request) + return response class VdHelper: @@ -132,7 +146,7 @@ class S: def get_one_wait_compress_video(self): param = { - "ids": [130337], # 52062 + "ids": [], # 52062 "status": 0, "offset": 0, "limit": 1, @@ -198,7 +212,7 @@ class S: elif content_type == "video/x-m4v": local_src_path_new = local_src_path + ".m4v" else: - logger.Error("invalid content_type, id: {}, src_id: {}, content_type: {}".format(video_id, hw_cdn_host + src_id, content_type)) + logger.Error("invalid content_type, id: {}, src_id: {}, content_type: {}".format(video_id, cdn_host + src_id, content_type)) return False os.renames(local_src_path, local_src_path_new) @@ -210,20 +224,17 @@ class S: logger.Info("pixel_format: {}".format(pf)) output_file = local_h264_720_path + ".mp4" - # self.to_del_files.append(output_file) + self.to_del_files.append(output_file) if pf not in ["yuv420p", "yuvj420p"]: # 先转成8bit, 再转成264 720p mp4 output_file_8bit = local_h264_720_path + "_8bit_tmp.mp4" vdh.transfer_h264_720p_25fps_10bit_to_8bit(output_file_8bit, output_file) + self.to_del_files.append(output_file_8bit) else: # 转成264 720p mp4 vdh.transfer_h264_720p_25fps(output_file) # 上传 - # 如果文件存在,则先删除再上传 - if bucket.object_exists(src_id_h264_720): - ret_oss = bucket.delete_object(src_id_h264_720) - logger.Info("{} already exists in oss, delete status: {}".format(src_id_h264_720, ret_oss.status)) upload_ret = self.upload_video_to_oss(output_file, src_id_h264_720) upload_ret_status = upload_ret.status logger.Info("upload_ret, {}, {}".format(src_id, upload_ret_status)) @@ -233,12 +244,16 @@ class S: # 更新db db_ret = self.set_compress_finish(video_id, file_size, "", 0, src_id_h264_720, output_file_size, 100, int(time.time())) + # 刷新cdn + file_url = cdn_host + src_id_h264_720 + refresh_res = refresh_cdn_cache(file_url) + logger.Info("refresh ali cdn, url: {}, res: {}".format(file_url, refresh_res)) # vdh.remove() # os.remove(output_file) logger.Info("before, {}, {}, {}".format(src_id, content_type, file_size)) logger.Info("after_h264720, {}, {}, {}, {}".format(src_id_h264_720, output_content_type, output_file_size, db_ret)) - logger.Info("host: {}".format(hw_cdn_host + src_id_h264_720)) + logger.Info("host: {}".format(file_url)) return True @@ -317,4 +332,3 @@ while True: s.set_compress_finish(video_id, 0, "", 0, "", 0, -200, int(time.time())) else: s.set_compress_finish(video_id, 0, "", 0, "", 0, -100, int(time.time())) - break diff --git a/media/calc_10bit.py b/media/calc_10bit.py index 007659e..82b8699 100644 --- a/media/calc_10bit.py +++ b/media/calc_10bit.py @@ -52,7 +52,7 @@ class S: "src_id": 1, "src_id_720": 1 } - docs = self.col_video.find({}, projection=prj) + docs = self.col_video.find({"pixel_format": {"$exists": False}}, projection=prj) total = len(docs) idx = 0