Video Replay
This example demonstrates how to replay a previously recorded video and showcases how to use the ReplayVideo node for feeding frames back into a DepthAI pipeline.Setup
This example requires the DepthAI v3 API, see installation instructions.Pipeline
Source code
Python
C++
Python
PythonGitHub
1import depthai as dai
2import argparse
3import time
4from pathlib import Path
5import cv2
6
7parser = argparse.ArgumentParser()
8parser.add_argument("-v", "--inputVideo", default="test_video.mp4", help="Input video name")
9parser.add_argument("-m", "--inputMetadata", default="test_video.mcap", help="Input metadata name")
10
11args = parser.parse_args()
12
13# Check if the input video file exists
14if not Path(args.inputVideo).exists():
15 print("First record a video using the record_video.py script")
16 raise FileNotFoundError(f'Input video file not found: {args.inputVideo}')
17
18with dai.Pipeline() as pipeline:
19 replay = pipeline.create(dai.node.ReplayVideo)
20 replay.setReplayVideoFile(Path(args.inputVideo))
21 if Path(args.inputMetadata).exists():
22 replay.setReplayMetadataFile(Path(args.inputMetadata))
23 replay.setOutFrameType(dai.ImgFrame.Type.NV12)
24 replay.setLoop(False)
25
26 videoOut = replay.out.createOutputQueue()
27
28 pipeline.start()
29 while pipeline.isRunning() and replay.isRunning():
30 try:
31 outFrame : dai.ImgFrame = videoOut.get()
32 except dai.MessageQueue.QueueException:
33 # Replay stopped the pipeline
34 break
35 outFrameCv = outFrame.getCvFrame()
36 cv2.imshow("video", outFrameCv)
37 if cv2.waitKey(1) == ord('q'):
38 print("Stopping pipeline")
39 pipeline.stop()
40 break
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.