mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-12 01:17:46 +08:00
fix: trimmed transcode before delayed audio starts
Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
parent
891258882d
commit
524414b117
@ -707,13 +707,17 @@ class VideoFromFile(VideoInput):
|
|||||||
|
|
||||||
elif packet.stream == audio_stream and not audio_done:
|
elif packet.stream == audio_stream and not audio_done:
|
||||||
for resampled in itertools.chain.from_iterable(map(resampler.resample, packet.decode())):
|
for resampled in itertools.chain.from_iterable(map(resampler.resample, packet.decode())):
|
||||||
|
frame_start = None
|
||||||
|
if resampled.pts is not None:
|
||||||
|
# passthrough frames keep the source stream's time base
|
||||||
|
tb = resampled.time_base if resampled.time_base else audio_time_base
|
||||||
|
frame_start = float(resampled.pts * tb)
|
||||||
|
if duration and not audio_started and frame_start >= start_time + duration:
|
||||||
|
audio_done = True
|
||||||
|
break
|
||||||
if not audio_started:
|
if not audio_started:
|
||||||
if resampled.pts is None:
|
if frame_start is None:
|
||||||
frame_start = 0.0
|
frame_start = 0.0
|
||||||
else:
|
|
||||||
# passthrough frames keep the source stream's time base
|
|
||||||
tb = resampled.time_base if resampled.time_base else audio_time_base
|
|
||||||
frame_start = float(resampled.pts * tb)
|
|
||||||
to_skip = max(0, int((start_time - frame_start) * sample_rate))
|
to_skip = max(0, int((start_time - frame_start) * sample_rate))
|
||||||
if to_skip >= resampled.samples:
|
if to_skip >= resampled.samples:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -481,6 +481,12 @@ def test_save_to_transcode_learns_unprobed_audio_params():
|
|||||||
assert result["audio_codecs"] == ["aac"]
|
assert result["audio_codecs"] == ["aac"]
|
||||||
assert result["audio_seconds"] == pytest.approx(1.0, abs=0.1)
|
assert result["audio_seconds"] == pytest.approx(1.0, abs=0.1)
|
||||||
|
|
||||||
|
buffer.seek(0)
|
||||||
|
trimmed_before_audio = transcode_and_probe(VideoFromFile(buffer, duration=1))
|
||||||
|
assert trimmed_before_audio["frames"] == fps
|
||||||
|
assert trimmed_before_audio["audio_codecs"] == []
|
||||||
|
assert trimmed_before_audio["audio_seconds"] is None
|
||||||
|
|
||||||
|
|
||||||
def test_save_to_transcode_trimmed_fragmented_mp4_keeps_audio():
|
def test_save_to_transcode_trimmed_fragmented_mp4_keeps_audio():
|
||||||
"""Fragmented mp4 (MediaRecorder, DASH/HLS-derived files) delivers audio well behind
|
"""Fragmented mp4 (MediaRecorder, DASH/HLS-derived files) delivers audio well behind
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user