Random Debugging: video related

I’m trying to use my Raspberry Pi as a home monitoring system, together with a webcam.

Over the past few weeks or so, I encountered multiple problems, each of which wasn’t complicated, but due to the lack of documentation and/or proper error message, they took a long time to resolve.

  • Video not playable
    • Part of the setup was just to read from the webcam frame by frame, then write the frames to a video file, pretty much like https://gist.github.com/boyou/580bbdc0fedb7af5446ef5b8ccf4ce8f.
    • No error/warning was raised, a video file was generated, but it couldn’t be played by VLC or the browser.
    • I wasn’t so familiar with ffmpeg / ffprob / etc, so I ended up eyeballing and trying random things like different codecs, and finally found out that the size parameter to VideoWriter is (width, height), while the ndarray is in row first order.
    • I could have used things like ffmpeg -i tmp.mp4 or ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 tmp.mp4, and noticed the video file is indeed malformed.
    • But anyway, opencv should have raised an error or warning.
  • Low frame rate of video
    • I was trying to let ffmpeg read the webcam and periodically write to video files, with command like this.
    • However, the frame rate was very low (10), instead of the specified 30.
    • Luckily this time there was some useful log, “The driver changed the time per frame from 1/30 to 1/10”.
    • Some search lead me to this answer, so we need to configure the codec twice, both to mjpeg.

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *