Reverted to original version of mediaUpload
This commit is contained in:
+13
-4
@@ -14,7 +14,6 @@ from .utils.runwareUtils import (
|
||||
sanitize_for_logging,
|
||||
safe_json_dumps,
|
||||
sendMediaUUID,
|
||||
convertVideoInputToDataUri,
|
||||
)
|
||||
|
||||
|
||||
@@ -107,9 +106,19 @@ class RunwareMediaUpload:
|
||||
def _convertVideoToBase64(self, videoTensor):
|
||||
"""Convert video file to base64 data URI"""
|
||||
print(f"[Debug] VideoFromFile object detected")
|
||||
out = convertVideoInputToDataUri(videoTensor)
|
||||
print(f"[Debug] Processing video file (data URI length {len(out) if out else 0})")
|
||||
return out
|
||||
|
||||
videoFile = self._getVideoFilePath(videoTensor)
|
||||
videoPath = self._extractVideoPath(videoFile)
|
||||
|
||||
print(f"[Debug] Processing video file: {videoPath}")
|
||||
|
||||
with open(videoPath, 'rb') as f:
|
||||
videoBytes = f.read()
|
||||
|
||||
mimeType = self._getMimeType(videoPath)
|
||||
videoBase64 = base64.b64encode(videoBytes).decode('utf-8')
|
||||
|
||||
return f"data:{mimeType};base64,{videoBase64}"
|
||||
|
||||
def _getVideoFilePath(self, videoTensor):
|
||||
"""Extract video file path from VideoFromFile object"""
|
||||
|
||||
@@ -516,36 +516,6 @@ def convertTensor2IMG(tensorImage):
|
||||
return imgDataUri
|
||||
|
||||
|
||||
def convertVideoInputToDataUri(video_tensor):
|
||||
"""Convert ComfyUI VIDEO (file-backed, e.g. Load Video) to data:<mime>;base64,... for API payloads."""
|
||||
if video_tensor is None:
|
||||
return None
|
||||
video_file = getattr(video_tensor, "_VideoFromFile__file", None)
|
||||
if video_file is None:
|
||||
for attr in ("video_path", "path", "file_path", "filename", "_file"):
|
||||
if hasattr(video_tensor, attr):
|
||||
video_file = getattr(video_tensor, attr)
|
||||
break
|
||||
if video_file is None:
|
||||
raise ValueError(
|
||||
"Could not resolve video file from VIDEO input. Connect a Load Video (file) output."
|
||||
)
|
||||
path = video_file.name if hasattr(video_file, "name") else video_file
|
||||
if not isinstance(path, str):
|
||||
raise ValueError(f"Unexpected video file type: {type(video_file)}")
|
||||
with open(path, "rb") as f:
|
||||
video_bytes = f.read()
|
||||
ext = os.path.splitext(path.lower())[1]
|
||||
mime = {
|
||||
".mp4": "video/mp4",
|
||||
".avi": "video/avi",
|
||||
".mov": "video/quicktime",
|
||||
".webm": "video/webm",
|
||||
}.get(ext, "video/mp4")
|
||||
b64 = base64.b64encode(video_bytes).decode("utf-8")
|
||||
return f"data:{mime};base64,{b64}"
|
||||
|
||||
|
||||
def convertTensor2IMGBase64Only(tensorImage):
|
||||
"""Convert tensor to base64 data URI without caching - for frame images"""
|
||||
imageNP = (tensorImage.squeeze().numpy() * 255).astype(np.uint8)
|
||||
|
||||
@@ -50,7 +50,7 @@ def _build_element_dict(
|
||||
description: str,
|
||||
frontalImage: Any,
|
||||
refer_images: List[Any],
|
||||
refer_videos: List[Any],
|
||||
refer_videos: List[str],
|
||||
voice: str,
|
||||
tags: str,
|
||||
) -> Dict[str, Any]:
|
||||
@@ -70,9 +70,8 @@ def _build_element_dict(
|
||||
imgs = [x for x in refer_images if x is not None]
|
||||
if imgs:
|
||||
el["images"] = imgs
|
||||
vids = [x for x in refer_videos if x is not None]
|
||||
if vids:
|
||||
el["videos"] = vids
|
||||
if refer_videos:
|
||||
el["videos"] = refer_videos
|
||||
voices = _split_lines_or_csv(voice)
|
||||
if voices:
|
||||
el["voice"] = voices
|
||||
@@ -116,8 +115,12 @@ class RunwareVideoInferenceElements:
|
||||
"tooltip": f"Optional reference image {i} for image_refer (up to {_REF_IMAGE_SLOTS}).",
|
||||
})
|
||||
for i in range(1, _REF_VIDEO_SLOTS + 1):
|
||||
optional[f"videos_{i}"] = ("VIDEO", {
|
||||
"tooltip": f"Optional reference video {i} for video_refer (file-backed VIDEO, e.g. Load Video).",
|
||||
optional[f"videos_{i}"] = ("STRING", {
|
||||
"default": "",
|
||||
"tooltip": (
|
||||
f"Optional reference video {i}: public URL or mediaUUID from Runware Media Upload "
|
||||
f"(upload a video first, then paste the UUID here)."
|
||||
),
|
||||
})
|
||||
return {"required": {}, "optional": optional}
|
||||
|
||||
@@ -143,11 +146,11 @@ class RunwareVideoInferenceElements:
|
||||
if slot is not None:
|
||||
refer_images.append(rwUtils.convertTensor2IMG(slot))
|
||||
|
||||
refer_videos: List[Any] = []
|
||||
refer_videos: List[str] = []
|
||||
for i in range(1, _REF_VIDEO_SLOTS + 1):
|
||||
slot = kwargs.get(f"videos_{i}")
|
||||
if slot is not None:
|
||||
refer_videos.append(rwUtils.convertVideoInputToDataUri(slot))
|
||||
raw = kwargs.get(f"videos_{i}")
|
||||
if raw is not None and str(raw).strip() != "":
|
||||
refer_videos.append(str(raw).strip())
|
||||
|
||||
el = _build_element_dict(
|
||||
str(kwargs.get("id") or ""),
|
||||
|
||||
Reference in New Issue
Block a user