Skip to content

Instantly share code, notes, and snippets.

@marc-hanheide
Created April 2, 2020 14:13
Show Gist options
  • Select an option

  • Save marc-hanheide/c52ca5f043475ebc3f3a18cde4792a0b to your computer and use it in GitHub Desktop.

Select an option

Save marc-hanheide/c52ca5f043475ebc3f3a18cde4792a0b to your computer and use it in GitHub Desktop.
Using V4L2 video loopback with ffmpeg and ROS
# https://superuser.com/questions/1330959/what-is-the-right-ffmpeg-output-format-for-a-v4l2-loopback-device
# https://github.com/lucasw/image_to_v4l2loopback
# install and load video loopback
sudo apt-get install v4l2loopback-utils v4l2loopback-dkms
sudo modprobe v4l2loopback
# stream the desktop
ffmpeg -f x11grab -r 15 -s 640x480 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuyv422 -threads 0 -f v4l2 /dev/video0
# stream a video
ffmpeg -re -i video.mp4 -s 640x480 -vcodec rawvideo -pix_fmt yuyv422 -threads 0 -f v4l2 /dev/video0
# read the device into ROS streams:
rosrun usb_cam usb_cam_node _pixel_format:=yuyv _io_method:=mmap _framerate:=15
# save images to disk from topic
rosrun image_view extract_images image:=/usb_cam/image_raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment