opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

Error while using GStream and OpenCV

Open 6CRIPT opened this issue 1 year ago • 0 comments

Expected behaviour

The idea is to use GStream with OpenCV to compress a video.

Actual behaviour

The code raises an error because of the pipeline

Steps to reproduce

  • operating system: ubuntu 20.04
  • opencv-python version 4.20

My code is: `compressed_video_path = os.path.join(picture_path, f"{datetime.datetime.now()}.mp4")

        gst_pipeline = (
            f"appsrc format=GST_APP_FORMAT_TIME ! videoconvert ! x264enc ! mp4mux ! filesink location={compressed_video_path}"
        )


        recorded_video = cv2.VideoWriter(gst_pipeline, 
                                        cv2.CAP_GSTREAMER, 
                                        0,  
                                        self.camera_fps, 
                                        (self.frame_size[1], self.frame_size[0]))

        if not recorded_video.isOpened():
            raise ValueError("Error!!!")

        for frame in frames_to_compress:
            recorded_video.write(frame)

        recorded_video.release()   

        rospy.loginfo(f"Compressed video saved in {compressed_video_path}.")`

And when calling the ros service involved, I have the error "Error!!!"

6CRIPT avatar Oct 08 '24 13:10 6CRIPT