fix : ffmpeg_slice_media 根据seek_head处理切割点时间为相对时间

This commit is contained in:
shuohigh@gmail.com 2025-06-18 10:21:52 +08:00
parent 40e0089308
commit 2551702443
1 changed files with 9 additions and 5 deletions

View File

@ -448,6 +448,7 @@ class VideoUtils:
if not is_streams:
ffmpeg_cmd.input(media_path)
seek_head = 0
else:
seek_head = media_markers[0].start.total_seconds()
seek_tail = media_markers[-1].end.total_seconds()
@ -462,7 +463,7 @@ class VideoUtils:
segment.end = segment.end - timedelta(seconds=seek_head)
logger.info(f"Only using {seek_head}s --> {seek_tail}s = {duration}s")
ffmpeg_cmd.input(local_m3u8_path,
ss=seek_head,
# ss=seek_head,
t=duration,
protocol_whitelist="file,http,https,tcp,tls")
# reconnect="1", # 自动重连
@ -477,19 +478,22 @@ class VideoUtils:
metadata = VideoUtils.ffprobe_media_metadata(media_path)
for index, marker in enumerate(media_markers):
start = marker.start.total_seconds() - seek_head
end = marker.end.total_seconds() - seek_head
# 处理指定的输出分辨率
if options.width and options.height:
filter_complex.extend(
[
f"[v:0]trim=start={marker.start.total_seconds()}:end={marker.end.total_seconds()},scale={options.width}:{options.height},setpts=PTS-STARTPTS[cut{index}]",
f"[a:0]atrim=start={marker.start.total_seconds()}:end={marker.end.total_seconds()},asetpts=PTS-STARTPTS[acut{index}]",
f"[v:0]trim=start={start}:end={end},scale={options.width}:{options.height},setpts=PTS-STARTPTS[cut{index}]",
f"[a:0]atrim=start={start}:end={end},asetpts=PTS-STARTPTS[acut{index}]",
]
)
else:
filter_complex.extend(
[
f"[v:0]trim=start={marker.start.total_seconds()}:end={marker.end.total_seconds()},setpts=PTS-STARTPTS[cut{index}]",
f"[a:0]atrim=start={marker.start.total_seconds()}:end={marker.end.total_seconds()},asetpts=PTS-STARTPTS[acut{index}]",
f"[v:0]trim=start={start}:end={end},setpts=PTS-STARTPTS[cut{index}]",
f"[a:0]atrim=start={start}:end={end},asetpts=PTS-STARTPTS[acut{index}]",
]
)
ffmpeg_cmd.option('filter_complex', ';'.join(filter_complex))