Quellcode durchsuchen

增加 处理完毕后释放视频剪辑对象 逻辑

zhangyong vor 1 Jahr
Ursprung
Commit
316815878f
2 geänderte Dateien mit 9 neuen und 5 gelöschten Zeilen
  1. 1 1
      main.py
  2. 8 4
      video_stitching/video_stitching.py

+ 1 - 1
main.py

@@ -18,7 +18,7 @@ def job_douyin_data():
 schedule.every().day.at("14:00").do(job_douyin_data)
 
 # 设置下午4点运行任务
-schedule.every().day.at("10:15").do(job_video_stitching)
+schedule.every().day.at("10:50").do(job_video_stitching)
 
 while True:
     schedule.run_pending()

+ 8 - 4
video_stitching/video_stitching.py

@@ -131,7 +131,7 @@ class VideoStitching():
         total_duration = 0
         included_videos = []
         # 设置最大可使用的内存限制(单位:字节)
-        memory_limit = 4 * 1024 * 1024 * 1024  # 4GB
+        memory_limit = 2 * 1024 * 1024 * 1024  # 2GB
         resource.setrlimit(resource.RLIMIT_AS, (memory_limit, memory_limit))
         # 提取视频的音频
         Common.logger().info(f"开始提取视频的音频{audio}")
@@ -149,12 +149,16 @@ class VideoStitching():
             total_duration += clip.duration
             if total_duration >= duration_limit:
                 break
+            # 处理完毕后释放视频剪辑对象
+            clip.close()
+            Common.logger().info(f"处理完毕后释放视频剪辑对象")
 
         # 如果总时长小于等于目标时长,则不做视频拼接
         if total_duration <= duration_limit:
             Common.logger().info(f"时长小于等于目标时长,不做视频拼接")
             return ""
         else:
+            Common.logger().info(f"总时长大于目标时长")
             remaining_time = duration_limit
             final_clips = []
 
@@ -199,7 +203,7 @@ class VideoStitching():
                 # /System/Library/Fonts/Hiragino Sans GB.ttc 本地字体
                 Common.logger().info(f"字幕:{text}")
 
-                sub = editor.TextClip(text, font="//usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
+                sub = editor.TextClip(text, font="/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
                                       fontsize=30, color="black").set_duration(end - start).set_start(
                     start).set_position(
                     ("center", final_height - 80)).set_opacity(0.8)
@@ -321,12 +325,12 @@ class VideoStitching():
                         time.sleep(120)
                         count += 1
                         Common.logger().info(f"视频添加到对应用户成功")
-                        if count >= 20:
+                        if count >= 13:
                             break
             except Exception as e:
                 Common.logger().warning(f"新拼接视频发送oss失败:{e}\n")
                 continue
-            if count >= 20:
+            if count >= 13:
                 break
 
     @classmethod