Store mp4 metadata at the beginning of the file when possible. (#15195)

This commit is contained in:
comfyanonymous
2026-08-01 00:21:28 -07:00
committed by GitHub
parent 235b466a0c
commit 2881e61610
3 changed files with 22 additions and 5 deletions

View File

@@ -36,6 +36,7 @@ def test_get_open_write_kwargs_filepath_no_format():
kwargs_specific = get_open_write_kwargs("output.avi", "mp4", "avi")
fail_msg = "Format should not be set for file paths (Specific)"
assert "format" not in kwargs_specific, fail_msg
assert kwargs_specific["options"]["movflags"] == "use_metadata_tags"
def test_get_open_write_kwargs_base_options_mode():
@@ -43,9 +44,9 @@ def test_get_open_write_kwargs_base_options_mode():
kwargs = get_open_write_kwargs("output.mp4", "mp4", VideoContainer.AUTO)
assert kwargs["mode"] == "w", "mode should be set to write"
fail_msg = "movflags should be set to preserve custom metadata tags"
fail_msg = "movflags should preserve custom metadata tags and enable faststart for MP4 files"
assert "movflags" in kwargs["options"], fail_msg
assert kwargs["options"]["movflags"] == "use_metadata_tags", fail_msg
assert kwargs["options"]["movflags"] == "use_metadata_tags+faststart", fail_msg
def test_get_open_write_kwargs_bytesio_auto_format():

View File

@@ -258,6 +258,18 @@ def test_save_to_h264_crf_controls_quality(tmp_path):
assert os.path.getsize(transcoded) < os.path.getsize(high_quality)
def test_save_to_mp4_writes_metadata_before_media(video_components, tmp_path):
encoded = tmp_path / "encoded.mp4"
remuxed = tmp_path / "remuxed.mp4"
VideoFromComponents(video_components).save_to(str(encoded), metadata={"prompt": {"test": "value"}})
VideoFromFile(str(encoded)).save_to(str(remuxed), metadata={"prompt": {"test": "value"}})
for path in (encoded, remuxed):
data = path.read_bytes()
assert data.index(b"moov") < data.index(b"mdat")
def create_transcode_source(
width=64, height=64, frames=30, fps=30, audio_streams=1, undecodable_audio=0, rotation=False,
container_format="mov", audio_codec="pcm_s16le",