Fix ValueError flush of closed file in video encoding
Replace communicate() with direct stderr.read() + wait() to avoid double-closing stdin. Catch BrokenPipeError for early ffmpeg exits. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -314,11 +314,15 @@ class FastAbsoluteSaver:
|
|||||||
print(f"xx- FastSaver: Encoding {batch_size} frames to {out_file} ({codec}, crf={crf}, {fps}fps)...")
|
print(f"xx- FastSaver: Encoding {batch_size} frames to {out_file} ({codec}, crf={crf}, {fps}fps)...")
|
||||||
|
|
||||||
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
try:
|
||||||
for img_tensor in images:
|
for img_tensor in images:
|
||||||
frame = (255.0 * img_tensor.cpu().numpy()).clip(0, 255).astype(np.uint8)
|
frame = (255.0 * img_tensor.cpu().numpy()).clip(0, 255).astype(np.uint8)
|
||||||
proc.stdin.write(frame.tobytes())
|
proc.stdin.write(frame.tobytes())
|
||||||
proc.stdin.close()
|
proc.stdin.close()
|
||||||
_, stderr = proc.communicate()
|
except BrokenPipeError:
|
||||||
|
pass
|
||||||
|
stderr = proc.stderr.read()
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise RuntimeError(f"ffmpeg failed: {stderr.decode()}")
|
raise RuntimeError(f"ffmpeg failed: {stderr.decode()}")
|
||||||
|
|||||||
Reference in New Issue
Block a user