Description
ffmpeg gets stuck at frame=0 when encoding certain large HEVC videos, causing infinite loop and server timeout.
Error
[libx264 @ 0x576011df9500] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x576011df9500] profile High, level 5.1, 4:2:0, 8-bit
frame= 0 fps=0.0 q=0.0 size= 0KiB time=N/A bitrate=N/A speed=N/A
frame= 0 fps=0.0 q=0.0 size= 0KiB time=N/A bitrate=N/A speed=N/A
[repeats forever, never progresses]
Video Info
- Input: HEVC (Main), 2160x3732, 24fps, 22.5s duration
- Output: h264 with preset "slow"
- Bitrate: 32021 kb/s
Issue
subprocess.run() has no timeout - hangs indefinitely when ffmpeg stalls. Server eventually killed by Gunicorn timeout.
Proposed Fix
Add timeout to ffmpeg subprocess:
result = subprocess.run(ffmpeg_cmd, timeout=300) # 5 min max
And/or change preset from "slow" to "medium" for faster encoding.
Frequency
Rare - large portrait 4K videos from certain phones
Description
ffmpeg gets stuck at
frame=0when encoding certain large HEVC videos, causing infinite loop and server timeout.Error
[libx264 @ 0x576011df9500] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x576011df9500] profile High, level 5.1, 4:2:0, 8-bit
frame= 0 fps=0.0 q=0.0 size= 0KiB time=N/A bitrate=N/A speed=N/A
frame= 0 fps=0.0 q=0.0 size= 0KiB time=N/A bitrate=N/A speed=N/A
[repeats forever, never progresses]
Video Info
Issue
subprocess.run()has no timeout - hangs indefinitely when ffmpeg stalls. Server eventually killed by Gunicorn timeout.Proposed Fix
Add timeout to ffmpeg subprocess: