1

What i want to do is generate a video file(mp4 or mkv format) with ffmpeg from the receiving frames simultaneously without saving images on storage. Attached below is my python ROS subscriber code.

import cv2
from cv_bridge import CvBridge
import rospy
from sensor_msgs.msg import Image
import numpy as np


def callback(data):
    # Used to convert between ROS and OpenCV images
    br = CvBridge()

    # Output debugging information to the terminal
    rospy.loginfo("receiving video frame")
    # Convert ROS Image message to OpenCV image
    current_frame = br.imgmsg_to_cv2(data)

    cv2.imshow("camera", current_frame)

    cv2.waitKey(1)


def listener():
    rospy.init_node("video_sub_py", anonymous=True)
    rospy.Subscriber("video_frames", Image, callback)

    rospy.spin()

    cv2.destroyAllWindows()


if __name__ == "__main__":
    listener()
techyidiot
  • 11
  • 4
  • This is just a simple subscriber. What have you already tried? Whats the output format you want? Please try to go more in detail here. – Fruchtzwerg May 20 '21 at 12:00
  • mp4 or mkv format would be better(but format is not a concern here). Couldn't find a proper approach related with this issue, since posted here. – techyidiot May 20 '21 at 12:17
  • `cv2` has `VideoWriter` – furas May 20 '21 at 13:10
  • Check this answer: https://stackoverflow.com/questions/42620869/unable-to-write-video-using-opencv-in-python – Fruchtzwerg May 20 '21 at 14:54
  • this needs to be done with ffmpeg. Im hoping to extend the work later for video compression with ffmpeg and send through http, so as the first step i'm looking to write to a video file. – techyidiot May 20 '21 at 15:08

0 Answers0