MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / __call__

Method __call__

tools/preprocess/process_pipepline.py:159–383  ·  view source on GitHub ↗
(
        self,
        video_path,
        refer_image_path,
        output_path,
        resolution_area=[1280, 720],
        fps=30,
        iterations=3,
        k=7,
        w_len=1,
        h_len=1,
        retarget_flag=False,
        use_flux=False,
        replace_flag=False,
        drop_tail_invalid_frames=False,
    )

Source from the content-addressed store, hash-verified

157 return (keypoints_body * wh).astype(np.int32)
158
159 def __call__(
160 self,
161 video_path,
162 refer_image_path,
163 output_path,
164 resolution_area=[1280, 720],
165 fps=30,
166 iterations=3,
167 k=7,
168 w_len=1,
169 h_len=1,
170 retarget_flag=False,
171 use_flux=False,
172 replace_flag=False,
173 drop_tail_invalid_frames=False,
174 ):
175 if replace_flag:
176 video_reader = VideoReader(video_path)
177 frame_num = len(video_reader)
178 print("frame_num: {}".format(frame_num))
179
180 video_fps = video_reader.get_avg_fps()
181 print("video_fps: {}".format(video_fps))
182 print("fps: {}".format(fps))
183
184 # TODO: Maybe we can switch to PyAV later, which can get accurate frame num
185 duration = video_reader.get_frame_timestamp(-1)[-1]
186 expected_frame_num = int(duration * video_fps + 0.5)
187 ratio = abs((frame_num - expected_frame_num) / frame_num)
188 if ratio > 0.1:
189 print("Warning: The difference between the actual number of frames and the expected number of frames is two large")
190 frame_num = expected_frame_num
191
192 if fps == -1:
193 fps = video_fps
194
195 target_num = int(frame_num / video_fps * fps)
196 print("target_num: {}".format(target_num))
197 idxs = get_frame_indices(frame_num, video_fps, target_num, fps)
198 frames = video_reader.get_batch(idxs).asnumpy()
199
200 frames = [resize_by_area(frame, resolution_area[0] * resolution_area[1], divisor=16) for frame in frames]
201 height, width = frames[0].shape[:2]
202 logger.info(f"Processing pose meta")
203
204 tpl_pose_metas = self.pose2d(frames)
205 pose_valid_flags = self._get_pose_valid_flags(tpl_pose_metas)
206 if drop_tail_invalid_frames:
207 frames, tpl_pose_metas, pose_valid_flags = self._trim_tail_invalid_frames(frames, tpl_pose_metas, pose_valid_flags, "Animate replace")
208
209 invalid_pose_count = len(pose_valid_flags) - sum(pose_valid_flags)
210 if invalid_pose_count > 0:
211 logger.info(f"Animate replace preprocessing: {invalid_pose_count}/{len(pose_valid_flags)} frame(s) have invalid body keypoints")
212
213 face_images = self._build_face_images(frames, tpl_pose_metas, pose_valid_flags)
214
215 logger.info(f"Processing reference image: {refer_image_path}")
216 refer_img = cv2.imread(refer_image_path)

Callers

nothing calls this directly

Calls 15

_get_pose_valid_flagsMethod · 0.95
_build_face_imagesMethod · 0.95
get_maskMethod · 0.95
get_editing_promptsMethod · 0.95
get_frame_indicesFunction · 0.90
resize_by_areaFunction · 0.90
padding_resizeFunction · 0.90
draw_aapose_by_meta_newFunction · 0.90
get_mask_body_imgFunction · 0.90
get_aug_maskFunction · 0.90

Tested by

no test coverage detected