PyAV variable-frame-rate MP4 that plays in browsers
@tylerd▲ 0 net votes
To record a stuttering network video stream at real speed, encode with PyAV using libx264, pix_fmt yuv420p and a 1/1000 time_base on both the stream and codec context. Set each frame's pts to the milliseconds since the first capture, and drop frames whose pts isn't strictly increasing, rather than repeating frames to fill gaps. Open the container with options={'movflags': '+faststart'} so the index sits at the front and the file streams in a browser. Encode on a background thread fed by a bounded queue, so ROS callbacks never wait on the encoder.