(
output_imgs_queue,
temp_dir,
result_dir,
work_id,
audio_path,
result_queue,
width,
height,
fps,
watermark_switch=0,
digital_auth=0,
)
| 47 | |
| 48 | |
| 49 | def write_video( |
| 50 | output_imgs_queue, |
| 51 | temp_dir, |
| 52 | result_dir, |
| 53 | work_id, |
| 54 | audio_path, |
| 55 | result_queue, |
| 56 | width, |
| 57 | height, |
| 58 | fps, |
| 59 | watermark_switch=0, |
| 60 | digital_auth=0, |
| 61 | ): |
| 62 | output_mp4 = os.path.join(temp_dir, "{}-t.mp4".format(work_id)) |
| 63 | fourcc = cv2.VideoWriter_fourcc(*"mp4v") |
| 64 | result_path = os.path.join(result_dir, "{}-r.mp4".format(work_id)) |
| 65 | video_write = cv2.VideoWriter(output_mp4, fourcc, fps, (width, height)) |
| 66 | print("Custom VideoWriter init done") |
| 67 | try: |
| 68 | while True: |
| 69 | state, reason, value_ = output_imgs_queue.get() |
| 70 | if type(state) == bool and state == True: |
| 71 | logger.info( |
| 72 | "Custom VideoWriter [{}]视频帧队列处理已结束".format(work_id) |
| 73 | ) |
| 74 | logger.info( |
| 75 | "Custom VideoWriter Silence Video saved in {}".format( |
| 76 | os.path.realpath(output_mp4) |
| 77 | ) |
| 78 | ) |
| 79 | video_write.release() |
| 80 | break |
| 81 | else: |
| 82 | if type(state) == bool and state == False: |
| 83 | logger.error( |
| 84 | "Custom VideoWriter [{}]任务视频帧队列 -> 异常原因:[{}]".format( |
| 85 | work_id, reason |
| 86 | ) |
| 87 | ) |
| 88 | raise CustomError(reason) |
| 89 | for result_img in value_: |
| 90 | video_write.write(result_img) |
| 91 | if video_write is not None: |
| 92 | video_write.release() |
| 93 | if watermark_switch == 1 and digital_auth == 1: |
| 94 | logger.info( |
| 95 | "Custom VideoWriter [{}]任务需要水印和数字人标识".format(work_id) |
| 96 | ) |
| 97 | if width > height: |
| 98 | command = 'ffmpeg -y -i {} -i {} -i {} -i {} -filter_complex "overlay=(main_w-overlay_w)-10:(main_h-overlay_h)-10,overlay=(main_w-overlay_w)-10:10" -c:a aac -crf 15 -strict -2 {}'.format( |
| 99 | audio_path, |
| 100 | output_mp4, |
| 101 | GlobalConfig.instance().watermark_path, |
| 102 | GlobalConfig.instance().digital_auth_path, |
| 103 | result_path, |
| 104 | ) |
| 105 | logger.info("command:{}".format(command)) |
| 106 | else: |
nothing calls this directly
no outgoing calls
no test coverage detected