给切分结尾的数值添加了1毫秒的容忍值以应对浮点数精确问题
This commit is contained in:
parent
93353c4c36
commit
86bf94fe0c
|
|
@ -3,4 +3,4 @@ modal_app_name=bowong-ai-video
|
||||||
S3_mount_dir=/mntS3
|
S3_mount_dir=/mntS3
|
||||||
S3_bucket_name=modal-media-cache
|
S3_bucket_name=modal-media-cache
|
||||||
S3_region=ap-northeast-2
|
S3_region=ap-northeast-2
|
||||||
S3_cdn_endpoint=https://d2nj71io21vkj2.cloudfront.net
|
S3_cdn_endpoint=https://cdn.roasmax.cn
|
||||||
|
|
|
||||||
|
|
@ -424,15 +424,7 @@ class VideoUtils:
|
||||||
if not output_path:
|
if not output_path:
|
||||||
output_path = FileUtils.file_path_extend(media_path, "slice")
|
output_path = FileUtils.file_path_extend(media_path, "slice")
|
||||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
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)
|
metadata = VideoUtils.ffprobe_media_metadata(media_path)
|
||||||
for index, marker in enumerate(media_markers):
|
for index, marker in enumerate(media_markers):
|
||||||
filter_complex.extend(
|
filter_complex.extend(
|
||||||
|
|
@ -443,13 +435,19 @@ class VideoUtils:
|
||||||
)
|
)
|
||||||
ffmpeg_cmd.option('filter_complex', ';'.join(filter_complex))
|
ffmpeg_cmd.option('filter_complex', ';'.join(filter_complex))
|
||||||
|
|
||||||
|
diff_tolerance = 0.001
|
||||||
|
|
||||||
for i, marker in enumerate(media_markers):
|
for i, marker in enumerate(media_markers):
|
||||||
if marker.start.total_seconds() > metadata.format.duration or marker.start.total_seconds() < 0:
|
if marker.start.total_seconds() > metadata.format.duration or marker.start.total_seconds() < 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"第{i}个切割点起始点{marker.start.total_seconds()}s超出视频时长[0-{metadata.format.duration}s]范围")
|
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:
|
if marker.end.total_seconds() > metadata.format.duration or marker.end.total_seconds() < 0:
|
||||||
raise ValueError(
|
if marker.end.total_seconds() > 0 and math.isclose(marker.end.total_seconds(), metadata.format.duration,
|
||||||
f"第{i}个切割点结束点{marker.end.total_seconds()}s超出视频时长[0-{metadata.format.duration}s]范围")
|
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))
|
segment_output_path = FileUtils.file_path_extend(output_path, str(i))
|
||||||
ffmpeg_cmd.output(segment_output_path,
|
ffmpeg_cmd.output(segment_output_path,
|
||||||
map=[f"[cut{i}]", f"[acut{i}]"],
|
map=[f"[cut{i}]", f"[acut{i}]"],
|
||||||
|
|
|
||||||
|
|
@ -164,10 +164,10 @@ with ffmpeg_worker_image.imports():
|
||||||
outputs = await ffmpeg_hls_slice_process(media_source=media,
|
outputs = await ffmpeg_hls_slice_process(media_source=media,
|
||||||
media_markers=markers,
|
media_markers=markers,
|
||||||
fn_id=fn_id)
|
fn_id=fn_id)
|
||||||
# case MediaProtocol.s3:
|
case MediaProtocol.s3:
|
||||||
# outputs = await ffmpeg_slice_process(media_source=media,
|
outputs = await ffmpeg_slice_process(media_source=media,
|
||||||
# media_markers=markers,
|
media_markers=markers,
|
||||||
# fn_id=fn_id)
|
fn_id=fn_id)
|
||||||
case _: # webhook不会报错,需要确认
|
case _: # webhook不会报错,需要确认
|
||||||
raise NotImplementedError("暂不支持的协议")
|
raise NotImplementedError("暂不支持的协议")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue