---
# System prepended metadata

title: 2021-10-15 Video Issues and Fixes

---

# 2021-10-15 Video Issues and Fixes

## Issue: video-capture halting problem

We noticed that video-capture cannot play to the end of AVI video files. The casues are due to:

- Wrong total frame count in AVI file header. We use `showriff` command from `xawtv` package to show that the frame count in header and actual number of frames mismatch.
- The erroneous frame count was due to ungraceful shutdown by the time we recorded the video.

We apply the fixes to workaround.

- Convert AVI files to HEVC encoded MP4 files. It gives several benefits: Fix the frame count, and store the data is much smaller size.
- Implement graceful shutdown in video-capture.

## Issue: File Writing Bottleneck while recording video file.

In the beginning, we write the camera image into AVI files. The desired spec is to record 1920x1080 30 fps videos from 3 cameras. We noticed framerate drop when writing to external USB due to insufficient writing speed.

An early attemp was to encode the video to H.264 or HEVC. However, the CPU encoding cannot run in real-time. Hence, we reduce the quality to 1280x70 10 fps to workaround. Second is that it's subject to loss of data when ungraceful shutdown when unencoded video could not catch up.

Now we see the Tesla T4 GPU in our IPC supports hardware video encoding call NVENC. Stated from NVIDIA's blog, Tesla T4 could support real-time HEVC encoding.

https://developer.nvidia.com/blog/turing-h264-video-encoding-speed-and-quality/

We tested on IPC using 3 Logitech c930e cameras. With 1920x1080 30 FPS resolution on each camera, we demonstrated that one camera wrote HEVC encoded to stream at 2000kbits/s bitrate. The overall speed would be 3x2000kbits/s ~= 750 kbytes/s.
