`encode_video` truncates a fractional `fps`, so the video runs longer than its audio
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 83/100
Línea de trabajo
Empieza por la configuración del flujo de encode_video en src/diffusers/utils/export_utils.py; el issue señala rate=int(fps) como causa y apunta al exportador HDR de LTX-2 como ejemplo de una frecuencia fraccionaria. Añade la prueba de regresión propuesta en tests/others/test_utils.py, codificando 30 fotogramas a 29.97 fps. El trabajo está terminado cuando el flujo codificado informa average_rate == Fraction(2997, 100).
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
diffusers.utils.export_utils.encode_video opens the video stream with rate=int(fps)
(export_utils.py#L364),
so 29.97 is written as 29 fps and 23.976 as 23. The audio stream keeps its real sample rate, so the video ends up
longer than the audio and drifts further out of sync the longer the clip is: about 0.35 s over 10 s at 29.97.
The LTX-2 pipelines take frame_rate as a float and the docs pass it straight through as encode_video(..., fps=frame_rate).
The LTX-2 HDR exporter already keeps the fraction with Fraction(frame_rate).limit_denominator(1000)
(ltx2/export_utils.py#L74).
Reproduction
I can't run the LTX-2 checkpoint on my machine, so this calls encode_video the way the LTX-2 docs do, with inputs
shaped like the pipeline's output_type="np" video and stereo audio:
import av
import numpy as np
import torch
from diffusers.utils.export_utils import encode_video
for fps in (24.0, 29.97, 23.976):
num_frames = round(fps * 10) # 10 seconds
video = np.random.rand(num_frames, 64, 64, 3).astype(np.float32)
audio = torch.zeros(2, 48000 * 10)
encode_video(video, fps=fps, output_path="out.mp4", audio=audio, audio_sample_rate=48000)
with av.open("out.mp4") as container:
v, a = container.streams.video[0], container.streams.audio[0]
print(fps, v.average_rate, f"video {float(v.duration * v.time_base):.3f}s", f"audio {float(a.duration * a.time_base):.3f}s")
Logs
24.0 24/1 video 10.000s audio 10.000s
29.97 29/1 video 10.345s audio 10.000s
23.976 23/1 video 10.435s audio 10.000s
System Info
- diffusers main (29d199aba)
- torch 2.14.1+cpu, PyAV 19.0.2, Python 3.12.13, Windows 11
Proposed fix
Use the same expression as the LTX-2 HDR exporter, rate=Fraction(fps).limit_denominator(1000) (Fraction is already imported in that file), plus a test in tests/others/test_utils.py that encodes 30 frames at 29.97 and checks average_rate == Fraction(2997, 100). The test fails on main with AVRational(29, 1) and passes with the change. With the change the same script prints (300 frames at 29.97 fps really are 10.010 s):
24.0 24/1 video 10.000s audio 10.000s
29.97 2997/100 video 10.010s audio 10.000s
23.976 2997/125 video 10.010s audio 10.000s
Happy to open a PR if that works for you.
Who can help?
@DN6
- Lenguaje dominante
- Python
- Estrellas
- 34.8k
- Forks
- 7.4k
- Merge medio
- 2 d 7 h
- PR fusionados (30 d)
- 54
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de huggingface/diffusers
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
huggingface/diffusers#15125 ·
Los mantenedores suelen responder en 1 día
-
VaeImageProcessor.denormalize() raises AttributeError for NumPy inputsPosiblemente ocupada @tonycoder-hub la tomó hace 14 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
huggingface/diffusers#15011 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`ModelMixin.from_pretrained` on a sharded checkpoint fails under `HF_HUB_OFFLINE=1` even when fully cached (`_get_checkpoint_shard_files` still calls `model_info`)Posiblemente ocupada @Subodh-17 la tomó hace 20 días. Abiertobug models
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
huggingface/diffusers#14952 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
UniPCMultistepScheduler fails in torch.linalg.solve under a float64 default dtype: the unit entry of rks takes the default dtypePosiblemente ocupada @deep1blue la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
huggingface/diffusers#14888 ·
Los mantenedores suelen responder en 1 día
-
WanAnimatePipeline.get_i2v_mask() defaults device to "cuda", which raises on non-CUDA accelerators (NPU/XPU/MPS)Posiblemente ocupada @li-lizhe la tomó hace 29 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
huggingface/diffusers#14881 ·
Los mantenedores suelen responder en 1 día
Todos los issues de huggingface/diffusers
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
UKGovernmentBEIS/optstop#10 ·
-
maintenance
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
pollen-robotics/reachy_mini#1508 ·
Los mantenedores suelen responder en 1 día
-
[BUG] `cloud-keys.env` values retain enclosing quotes causing 401 Unauthorized, and missing utf-8 encoding crashes on WindowsPosiblemente ocupada @divyanshu07-code la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
open-jarvis/OpenJarvis#1192 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
sylvainmetayer/homelab#851 ·
Los mantenedores suelen responder en 1 día