I want to capture images from a Logitech C910 webcam in intervals. Problem is that after a shot is taken, the camera resets focus, making the next shot unfocused.
I am using v4l2-ctl
to set the focus.
$v4l2-ctl --device=/dev/video1 --set-ctrl=focus_auto=0
$v4l2-ctl --device=/dev/video1 --set-ctrl=focus_absolute=119
This is my script to automate the capturing.
#!/bin/bash
while true; do
ffmpeg -f v4l2 -i /dev/video1 -vframes 1 $(date '+%Y%m%d%H%M%S')
sleep 60
done
I have tried using fswebcam
and streamer
instead of ffmpeg
with the same result. The focus resets every time when a shot is taken.
Playing a video from the webcam with $mpv /dev/video1
also resets the focus after the player is closed.
When examining current values using v4l2-ctl --list-ctrls
, the value of focus_absolute
is unchanged after taking the first and second shot. But output of the second one is unfocused.
$v4l2-ctl -d /dev/video1 --list-ctrls
...
focus_absolute 0x009a090a (int) : min=0 max=255 step=17 default=68 value=119
focus_auto 0x009a090c (bool) : default=1 value=0
Setting focus to 119, making first shot, setting focus to 119 again and making second shot also results in second image being unfocused. If, however, after taking the first shot I change focus to some other value and then back to 119, both images are focused.
#!/bin/bash
# Set Manual Focus
v4l2-ctl --device=/dev/video1 --set-ctrl=focus_auto=0
# Infinite Loop
while true; do
# Reset Focus
v4l2-ctl --device=/dev/video1 --set-ctrl=focus_absolute=136
v4l2-ctl --device=/dev/video1 --set-ctrl=focus_absolute=119
# Save Image
ffmpeg -f v4l2 -i /dev/video1 -vframes 1 $(date '+%Y%m%d%H%M%S')
# Wait
sleep 60
done
...so this is my current working script that saves a focused image captured from my webcam every 60 seconds. BUT, every time a shot is taken, lens in the camera moves and the mechanics even makes a weird clicking noise. Since I want to use this to make a long timelapses with thousands shots per every day, I can imaging this would result in excessive wear of the camera over time. So I am still looking for different ways to do this. NOTE: The clicking noise is not present when I don't do the refocusing part.
As the focus reset occurs every time the capture from camera is stopped (and the camera LED turns off). How could I keep the stream from camera opened and save a picture from this stream in intervals? Are there are any other methods I could try to keep the camera from resetting focus after the stream ends?
// I hope I didn't make the question too extensive.
0 Answers