Hello! I am using the rgb_encoding.py example to record and convert a video. However, I need to interrupt the recording based on a condition. I have a function that checks if a traffic light is red or not. I need a separate file for each duration of the red. What would be the best way to achieve this?

Thanks! Mladen

  • erik replied to this.

    Hello mzamanov , I would just create a new file and start writing to it instead of the different one. One note here is that it would work with MJPEG, but for h264/h265 encoding, you would need to wait for a keyframe, otherwise, you would just have some strange artifacts at the beginning. You can reduce this effect by setting keyframes more frequently, but this would also increase the final file size.
    Thanks, Erik

    Thanks, Erik! I plan to check the condition every second, not every frame. What is the default keyframe frequency? Is it every second for the 30 FPS?

    • erik replied to this.

      mzamanov I think that by default it's every 30th frame, so every second at 30FPS. You could also count frames to recognize which one is the keyframe and start a new video file then, so you avoid having artifacts.
      Thanks, Erik