fix :
- FFMpegSliceSegment的起始结束时间不小于0的校验 - ffmpeg_slice_media少传递了options对象
This commit is contained in:
parent
f1e4fa3d6c
commit
9022e52827
|
|
@ -19,12 +19,21 @@ class FFMpegSliceSegment(BaseModel):
|
|||
@classmethod
|
||||
def parse_start(cls, v: Union[float, str, TimeDelta]):
|
||||
if isinstance(v, float):
|
||||
if v < 0.0:
|
||||
raise ValueError("开始时间点不能小于0")
|
||||
return TimeDelta(seconds=v)
|
||||
elif isinstance(v, int):
|
||||
if v < 0:
|
||||
raise ValueError("开始时间点不能小于0")
|
||||
return TimeDelta(seconds=v)
|
||||
elif isinstance(v, str):
|
||||
return TimeDelta.from_format_string(v)
|
||||
timedelta = TimeDelta.from_format_string(v)
|
||||
if timedelta.total_seconds() < 0.0:
|
||||
raise ValueError("开始时间点不能小于0")
|
||||
return timedelta
|
||||
elif isinstance(v, TimeDelta):
|
||||
if v.total_seconds() < 0.0:
|
||||
raise ValueError("开始时间点不能小于0")
|
||||
return v
|
||||
else:
|
||||
raise TypeError(v)
|
||||
|
|
@ -33,12 +42,21 @@ class FFMpegSliceSegment(BaseModel):
|
|||
@classmethod
|
||||
def parse_end(cls, v: Union[float, TimeDelta]):
|
||||
if isinstance(v, float):
|
||||
if v < 0.0:
|
||||
raise ValueError("结束时间点不能小于0")
|
||||
return TimeDelta(seconds=v)
|
||||
elif isinstance(v, int):
|
||||
if v < 0:
|
||||
raise ValueError("结束时间点不能小于0")
|
||||
return TimeDelta(seconds=v)
|
||||
elif isinstance(v, str):
|
||||
return TimeDelta.from_format_string(v)
|
||||
timedelta = TimeDelta.from_format_string(v)
|
||||
if timedelta.total_seconds() < 0.0:
|
||||
raise ValueError("结束时间点不能小于0")
|
||||
return timedelta
|
||||
elif isinstance(v, TimeDelta):
|
||||
if v.total_seconds() < 0.0:
|
||||
raise ValueError("结束时间点不能小于0")
|
||||
return v
|
||||
else:
|
||||
raise TypeError(v)
|
||||
|
|
|
|||
|
|
@ -176,6 +176,11 @@ class MediaSource(BaseModel):
|
|||
return f"{self.protocol.value}/{self.path}"
|
||||
return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}"
|
||||
|
||||
@computed_field(description="CDN挂载地址")
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return f"{config.S3_cdn_endpoint}/{self.get_cdn_url()}"
|
||||
|
||||
def __str__(self):
|
||||
match self.protocol:
|
||||
case MediaProtocol.http:
|
||||
|
|
|
|||
|
|
@ -79,9 +79,10 @@ class FFMPEGResult(BaseModel):
|
|||
@computed_field(description="可通过CDN访问的资源链接")
|
||||
@property
|
||||
def url(self) -> str:
|
||||
if not self.urn.startswith("s3://"):
|
||||
raise ValueError("无法转换非s3前缀协议")
|
||||
return self.urn.replace('s3://', f"{config.S3_cdn_endpoint}/")
|
||||
prefix = f"s3://{config.S3_region}/{config.S3_bucket_name}"
|
||||
if not self.urn.startswith(prefix):
|
||||
raise ValueError("无法转换非s3前缀协议和非当前挂载点的s3协议")
|
||||
return self.urn.replace(prefix, f"{config.S3_cdn_endpoint}/")
|
||||
|
||||
|
||||
class BaseFFMPEGTaskRequest(BaseModel):
|
||||
|
|
|
|||
|
|
@ -461,6 +461,8 @@ class VideoUtils:
|
|||
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)
|
||||
logger.warning(
|
||||
f"第{i}个切割点结束点{marker.end.total_seconds()}s接近视频时长[0-{metadata.format.duration}s]范围")
|
||||
else:
|
||||
raise ValueError(
|
||||
f"第{i}个切割点结束点{marker.end.total_seconds()}s超出视频时长[0-{metadata.format.duration}s]范围")
|
||||
|
|
|
|||
|
|
@ -161,10 +161,12 @@ with ffmpeg_worker_image.imports():
|
|||
case MediaProtocol.hls:
|
||||
outputs = await ffmpeg_hls_slice_process(media_source=media,
|
||||
media_markers=markers,
|
||||
options=options,
|
||||
fn_id=fn_id)
|
||||
case MediaProtocol.s3:
|
||||
outputs = await ffmpeg_slice_process(media_source=media,
|
||||
media_markers=markers,
|
||||
options=options,
|
||||
fn_id=fn_id)
|
||||
case _: # webhook不会报错,需要确认
|
||||
raise NotImplementedError("暂不支持的协议")
|
||||
|
|
|
|||
Loading…
Reference in New Issue