mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-11 17:07:14 +08:00
Merge 15f94d06e9 into b08debceca
This commit is contained in:
commit
44bcc4f273
@ -281,11 +281,18 @@ class VideoFromFile(VideoInput):
|
|||||||
video_done = False
|
video_done = False
|
||||||
audio_done = True
|
audio_done = True
|
||||||
|
|
||||||
if len(container.streams.audio):
|
# Use the last decodable audio stream. Streams FFmpeg has no decoder for have no codec context,
|
||||||
audio_stream = container.streams.audio[-1]
|
# and decoding their packets crashes the process. (e.g. APAC spatial-audio track in iPhone)
|
||||||
|
audio_stream = next(
|
||||||
|
(s for s in reversed(container.streams.audio) if s.codec_context is not None),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
if audio_stream is not None:
|
||||||
streams += [audio_stream]
|
streams += [audio_stream]
|
||||||
resampler = av.audio.resampler.AudioResampler(format='fltp')
|
resampler = av.audio.resampler.AudioResampler(format='fltp')
|
||||||
audio_done = False
|
audio_done = False
|
||||||
|
elif len(container.streams.audio):
|
||||||
|
logging.warning("No decodable audio stream found in video; ignoring audio.")
|
||||||
|
|
||||||
for packet in container.demux(*streams):
|
for packet in container.demux(*streams):
|
||||||
if video_done and audio_done:
|
if video_done and audio_done:
|
||||||
@ -457,10 +464,13 @@ class VideoFromFile(VideoInput):
|
|||||||
else:
|
else:
|
||||||
output_container.metadata[key] = json.dumps(value)
|
output_container.metadata[key] = json.dumps(value)
|
||||||
|
|
||||||
# Add streams to the new container
|
# Add streams to the new container. Streams with no codec context cannot be used as an output template.
|
||||||
stream_map = {}
|
stream_map = {}
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
if isinstance(stream, (av.VideoStream, av.AudioStream, SubtitleStream)):
|
if isinstance(stream, (av.VideoStream, av.AudioStream, SubtitleStream)):
|
||||||
|
if stream.codec_context is None:
|
||||||
|
logging.warning("Skipping %s stream %d with unsupported codec", stream.type, stream.index)
|
||||||
|
continue
|
||||||
out_stream = output_container.add_stream_from_template(template=stream, opaque=True)
|
out_stream = output_container.add_stream_from_template(template=stream, opaque=True)
|
||||||
stream_map[stream] = out_stream
|
stream_map[stream] = out_stream
|
||||||
|
|
||||||
|
|||||||
@ -158,7 +158,14 @@ async def upload_video_to_comfyapi(
|
|||||||
|
|
||||||
# Convert VideoInput to BytesIO using specified container/codec
|
# Convert VideoInput to BytesIO using specified container/codec
|
||||||
video_bytes_io = BytesIO()
|
video_bytes_io = BytesIO()
|
||||||
video.save_to(video_bytes_io, format=container, codec=codec)
|
try:
|
||||||
|
video.save_to(video_bytes_io, format=container, codec=codec)
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError(
|
||||||
|
f"Could not convert the input video to {container.value.upper()} for upload; "
|
||||||
|
f"the file may be corrupt or use an unsupported codec. "
|
||||||
|
f"Try re-exporting it as MP4 (H.264). Original error: {e}"
|
||||||
|
) from e
|
||||||
video_bytes_io.seek(0)
|
video_bytes_io.seek(0)
|
||||||
|
|
||||||
return await upload_file_to_comfyapi(cls, video_bytes_io, filename, upload_mime_type, wait_label)
|
return await upload_file_to_comfyapi(cls, video_bytes_io, filename, upload_mime_type, wait_label)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user