0

I want to be able to apply keystone correction to a webcam stream. The raw image-stream contains a rectangular background and I am using a rectangular overlay, which the user drags the corners to match the actual corners in the image. Finally, the user clicks a button that sends the coordinates to the server. The server then updates the filter parameters and restarts the stream. Everything works using ffmpeg to stream RTMP to nginx, but the HLS stream generated by nginx lags unsatisfactorily and/or hangs. I am using the filter as follows:

-lavfi   "perspective=x0=100:y0=20:x1=520:y1=20:x2=100:y2=380:x3=520:y3=380:interpolation=linear:sense=source"

Switching to using motion to stream the image has much better real-time performance and I can embed the image in the HTML described above absolutely fine. The problem is I can't find a way of inserting the ffmpeg filter into the motion stream, I think it is only for saved files. Is is possible?

1 Answer 1

0

With a pointer from the maintainer of motion, I have got this working:

  1. Install the v4l2loopback device. In my case, it reported the loopback device as /dev/video2, so the ffmpeg command streams from the webcam on /dev/video0 through the perspective filter, correcting the keystone effect, and puts the result to /dev/video2.
ffmpeg -f v4l2 -i /dev/video0 -f v4l2 /dev/video2 -lavfi \
     "perspective=x0=23:y0=43:x1=500:y1=38:x2=33:y2=467:x3=508:y3=471:interpolation=linear:sense=source"
  1. Run motion as standard, but using the loopback device as the camera input.

Still a bit to do to make the ffmpeg re-start nicely, but it is mostly there now.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .