My code tries to get frames from webcam, detect faces and save video file simultaneously. I use Python, opencv for image and video processing, face_recognition library for face detection and recognition.
The problem is that recorder video is too slow - final FPS is about 1.3, however the camera has 30 FPS. I tried to use multithreading, but the problem didn’t disappear.
Hi,
In OpenCV, main format is BGR which is not supported by most hardware engines in Jetson, and have to utilize significant CPU usage. It limits performance. For running deep learning inference, we suggest try DeepStream SDK. You can try default deepstream-app and then apply your model.
If I understand properly, I can modify the pipeline to simultaneously process video capture in Python code and to save video to file. I read that I should use tee, queue and filesink. But I have some problems - if I try to modify my pipeline, it crashes.
Did you kill the pipeline while running ? For properly saving before closing, sending an EOS may be be required but this is not obvious from opencv.
You may just read read the frame in opencv with appsink and send it to a videoWriter such as here.
Yes, you are right - I’m killing the pipeline while running. But using cv2 videoWriter is a bad idea - as I wrote at the beggining of this topic, I also perform some face recognition manipulations, which leads to distortion in speed of saved video.
Do you have any ideas about how to save video using your gstreamer pipeline properly? I’ve read something about -e option…
You may try removing the muxer and save H264 file.
Otherwise, there might be several ways to do this. I think the simplest way would be to use a gst-launch -e command with tee and one sub-pipeline ancoding and saving file, and a second pipeline for your app, sinking to a v4l2loopback node (or shmsink but it may be limited). From opencv app, you would just open the v4l2loopback node (may use V4L API).
My attempts are in vain. I cannot achieve the desired result - to process video and to save video to the file at the same time. Can you help me, please? I am trying to find the answer myself but with no results yet. How should I modify the pipeline above to reach the goal?
Even if I try to execute simple pipeline like gst-launch-1.0 nvarguscamerasrc num-buffers=2000 ! 'video/x-raw(memory:NVMM),width=1920, height=1080, framerate=30/1, format=NV12' ! nvvidconv ! x264enc ! qtmux ! filesink location=test.mp4 -e from terminal, I can’t play the recorded video afterwards on Windows machine using various players :(
Maybe I should reinstall opencv like it’s mentioned in this topic?
UPD: Now I can open it with VLC player, but the video is still quite slow :( But we can open it - it’s a great result itself! :D
I think, it happens because face detection and face recognition takes some time and I should use 2 different pipelines - one for processing and one for saving. But I have no idea how to do it.