fix: keep video movflags scoped to container

This commit is contained in:
ahfoysal 2026-07-06 12:58:22 +06:00
parent b08debceca
commit a77158e92f
2 changed files with 28 additions and 11 deletions

View File

@ -37,7 +37,7 @@ def get_open_write_kwargs(
open_kwargs = {
"mode": "w",
# 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)
@ -525,14 +525,8 @@ class VideoFromComponents(VideoInput):
if bit_depth is None:
bit_depth = self.__bit_depth
is_10bit = bit_depth >= 10
extra_kwargs = {}
if isinstance(format, VideoContainer) and format != VideoContainer.AUTO:
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:
open_kwargs = get_open_write_kwargs(path, "mp4", format)
with av.open(path, **open_kwargs) as output:
# Add metadata before writing any streams
if metadata is not None:
for key, value in metadata.items():

View File

@ -5,8 +5,8 @@ import os
import av
import io
from fractions import Fraction
from comfy_api.input_impl.video_types import VideoFromFile, VideoFromComponents
from comfy_api.util.video_types import VideoComponents
from comfy_api.input_impl.video_types import VideoFromFile, VideoFromComponents, get_open_write_kwargs
from comfy_api.util.video_types import VideoComponents, VideoContainer
from comfy_api.input.basic_types import AudioInput
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)
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"