diff --git a/.runtime.env b/.runtime.env index f0442f9..a31361e 100644 --- a/.runtime.env +++ b/.runtime.env @@ -3,4 +3,4 @@ modal_app_name=bowong-ai-video S3_mount_dir=/mntS3 S3_bucket_name=modal-media-cache S3_region=ap-northeast-2 -S3_cdn_endpoint=https://d2nj71io21vkj2.cloudfront.net +S3_cdn_endpoint=https://cdn.roasmax.cn diff --git a/src/BowongModalFunctions/utils/VideoUtils.py b/src/BowongModalFunctions/utils/VideoUtils.py index 28b3fe3..84652d6 100644 --- a/src/BowongModalFunctions/utils/VideoUtils.py +++ b/src/BowongModalFunctions/utils/VideoUtils.py @@ -424,15 +424,7 @@ class VideoUtils: if not output_path: output_path = FileUtils.file_path_extend(media_path, "slice") os.makedirs(os.path.dirname(output_path), exist_ok=True) - # if media_path.endswith(".m3u8"): - # metadata = VideoUtils.ffprobe_media_metadata(media_path) - # video_metadata = metadata.streams[0] - # playlist = m3u8.loads(media_path) - # duration = sum(segment.duration for segment in playlist.segments) - # logger.info(f"HLS duration: {duration}") - # video_metadata.duration = duration if duration > 0 else 3600 * 12 - # else: - # video_metadata = VideoUtils.ffprobe_video_format(media_path=media_path) + metadata = VideoUtils.ffprobe_media_metadata(media_path) for index, marker in enumerate(media_markers): filter_complex.extend( @@ -443,13 +435,19 @@ class VideoUtils: ) ffmpeg_cmd.option('filter_complex', ';'.join(filter_complex)) + diff_tolerance = 0.001 + for i, marker in enumerate(media_markers): if marker.start.total_seconds() > metadata.format.duration or marker.start.total_seconds() < 0: raise ValueError( f"第{i}个切割点起始点{marker.start.total_seconds()}s超出视频时长[0-{metadata.format.duration}s]范围") if marker.end.total_seconds() > metadata.format.duration or marker.end.total_seconds() < 0: - raise ValueError( - f"第{i}个切割点结束点{marker.end.total_seconds()}s超出视频时长[0-{metadata.format.duration}s]范围") + if marker.end.total_seconds() > 0 and math.isclose(marker.end.total_seconds(), metadata.format.duration, + rel_tol=diff_tolerance): + marker.end = TimeDelta(seconds=metadata.format.duration) + else: + raise ValueError( + f"第{i}个切割点结束点{marker.end.total_seconds()}s超出视频时长[0-{metadata.format.duration}s]范围") segment_output_path = FileUtils.file_path_extend(output_path, str(i)) ffmpeg_cmd.output(segment_output_path, map=[f"[cut{i}]", f"[acut{i}]"], diff --git a/src/cluster/ffmpeg_app.py b/src/cluster/ffmpeg_app.py index ef8674e..9fa7862 100644 --- a/src/cluster/ffmpeg_app.py +++ b/src/cluster/ffmpeg_app.py @@ -164,10 +164,10 @@ with ffmpeg_worker_image.imports(): outputs = await ffmpeg_hls_slice_process(media_source=media, media_markers=markers, fn_id=fn_id) - # case MediaProtocol.s3: - # outputs = await ffmpeg_slice_process(media_source=media, - # media_markers=markers, - # fn_id=fn_id) + case MediaProtocol.s3: + outputs = await ffmpeg_slice_process(media_source=media, + media_markers=markers, + fn_id=fn_id) case _: # webhook不会报错,需要确认 raise NotImplementedError("暂不支持的协议")