View Single Post
  #2   Spotlight this post!  
Unread 09-08-2016, 03:28
calcmogul's Avatar
calcmogul calcmogul is offline
WPILib Developer
AKA: Tyler Veness
FRC #3512 (Spartatroniks)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Santa Maria, CA
Posts: 51
calcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nice
Re: Simulate a Webcam with Pictures (Or IP Camera)

You could use gstreamer to do that. The following script will run an MJPEG server on localhost port 8080 using JPEG images from the current directory that match the name pattern. They will be served in a loop until the server is killed.

Code:
#!/bin/bash
gst-launch-1.0 multifilesrc location="img.%04d.jpg" index=0 \
    caps="image/jpeg,framerate=\(fraction\)12/1" loop=true ! jpegdec ! \
    videoconvert ! videorate ! jpegenc ! queue ! multipartmux ! \
    tcpserversink host=127.0.0.1 port=8080
%04d represents an integer padded on the left with zeroes to four digits. I used the following script to rename all .jpg files in the current directory to the form the gstreamer command accepts.

Code:
#!/bin/bash
count=0
for file in *.jpg; do
  new=$(printf "img.%04d.jpg" "$count")
  mv -- "$file" "$new"
  let count=count+1
done
Reply With Quote