From 255170244313ef62238a94c03ac2ff5d042ff78b Mon Sep 17 00:00:00 2001 From: "shuohigh@gmail.com" Date: Wed, 18 Jun 2025 10:21:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=20:=20ffmpeg=5Fslice=5Fmedia=20=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEseek=5Fhead=E5=A4=84=E7=90=86=E5=88=87=E5=89=B2?= =?UTF-8?q?=E7=82=B9=E6=97=B6=E9=97=B4=E4=B8=BA=E7=9B=B8=E5=AF=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BowongModalFunctions/utils/VideoUtils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/BowongModalFunctions/utils/VideoUtils.py b/src/BowongModalFunctions/utils/VideoUtils.py index fc88c63..b07148e 100644 --- a/src/BowongModalFunctions/utils/VideoUtils.py +++ b/src/BowongModalFunctions/utils/VideoUtils.py @@ -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))