mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-10 00:17:16 +08:00
fix: keep video movflags scoped to container
This commit is contained in:
parent
b08debceca
commit
a77158e92f
@ -37,7 +37,7 @@ def get_open_write_kwargs(
|
|||||||
open_kwargs = {
|
open_kwargs = {
|
||||||
"mode": "w",
|
"mode": "w",
|
||||||
# If isobmff, preserve custom metadata tags (workflow, prompt, extra_pnginfo)
|
# If isobmff, preserve custom metadata tags (workflow, prompt, extra_pnginfo)
|
||||||
"options": {"movflags": "use_metadata_tags"},
|
"container_options": {"movflags": "use_metadata_tags"},
|
||||||
}
|
}
|
||||||
|
|
||||||
is_write_to_buffer = isinstance(dest, io.BytesIO)
|
is_write_to_buffer = isinstance(dest, io.BytesIO)
|
||||||
@ -525,14 +525,8 @@ class VideoFromComponents(VideoInput):
|
|||||||
if bit_depth is None:
|
if bit_depth is None:
|
||||||
bit_depth = self.__bit_depth
|
bit_depth = self.__bit_depth
|
||||||
is_10bit = bit_depth >= 10
|
is_10bit = bit_depth >= 10
|
||||||
extra_kwargs = {}
|
open_kwargs = get_open_write_kwargs(path, "mp4", format)
|
||||||
if isinstance(format, VideoContainer) and format != VideoContainer.AUTO:
|
with av.open(path, **open_kwargs) as output:
|
||||||
extra_kwargs["format"] = format.value
|
|
||||||
elif isinstance(path, io.BytesIO):
|
|
||||||
# BytesIO has no file extension, so av.open can't infer the format.
|
|
||||||
# Default to mp4 since that's the only supported format anyway.
|
|
||||||
extra_kwargs["format"] = "mp4"
|
|
||||||
with av.open(path, mode='w', options={'movflags': 'use_metadata_tags'}, **extra_kwargs) as output:
|
|
||||||
# Add metadata before writing any streams
|
# Add metadata before writing any streams
|
||||||
if metadata is not None:
|
if metadata is not None:
|
||||||
for key, value in metadata.items():
|
for key, value in metadata.items():
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import os
|
|||||||
import av
|
import av
|
||||||
import io
|
import io
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
from comfy_api.input_impl.video_types import VideoFromFile, VideoFromComponents
|
from comfy_api.input_impl.video_types import VideoFromFile, VideoFromComponents, get_open_write_kwargs
|
||||||
from comfy_api.util.video_types import VideoComponents
|
from comfy_api.util.video_types import VideoComponents, VideoContainer
|
||||||
from comfy_api.input.basic_types import AudioInput
|
from comfy_api.input.basic_types import AudioInput
|
||||||
from av.error import InvalidDataError
|
from av.error import InvalidDataError
|
||||||
|
|
||||||
@ -237,3 +237,26 @@ def test_duration_consistency(video_components):
|
|||||||
manual_duration = float(components.images.shape[0] / components.frame_rate)
|
manual_duration = float(components.images.shape[0] / components.frame_rate)
|
||||||
|
|
||||||
assert duration == pytest.approx(manual_duration)
|
assert duration == pytest.approx(manual_duration)
|
||||||
|
|
||||||
|
|
||||||
|
def test_open_write_kwargs_keep_movflags_container_scoped():
|
||||||
|
"""movflags must not leak into stream codec options such as AAC."""
|
||||||
|
kwargs = get_open_write_kwargs("out.mp4", "mp4", VideoContainer.AUTO)
|
||||||
|
|
||||||
|
assert kwargs["container_options"] == {"movflags": "use_metadata_tags"}
|
||||||
|
assert "options" not in kwargs
|
||||||
|
|
||||||
|
|
||||||
|
def test_open_write_kwargs_sets_buffer_format():
|
||||||
|
"""BytesIO outputs still get an explicit container format."""
|
||||||
|
kwargs = get_open_write_kwargs(io.BytesIO(), "mov,mp4,m4a,3gp,3g2,mj2", VideoContainer.AUTO)
|
||||||
|
|
||||||
|
assert kwargs["format"] == "mov"
|
||||||
|
assert kwargs["container_options"] == {"movflags": "use_metadata_tags"}
|
||||||
|
assert "options" not in kwargs
|
||||||
|
|
||||||
|
|
||||||
|
def test_open_write_kwargs_honors_explicit_container_format():
|
||||||
|
kwargs = get_open_write_kwargs(io.BytesIO(), "mov,mp4,m4a,3gp,3g2,mj2", VideoContainer.MP4)
|
||||||
|
|
||||||
|
assert kwargs["format"] == "mp4"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user