Timelapse video using Linux, motion and USB webcam
===================================================hardware: webcams
================= 1. usb webcam 'ausdom' (1920x1080) 2. usb webcam logitech brio 4k usb3 necessary to recieve 4k in webcam mode (?streaming only) ---software: motion
================ using cli tool called 'motion' (fresh from git, much newer than in debian) https://github.com/Motion-Project/motion stream visible at: http://localhost:8080/ cam1: http://localhost:8081/0/streammotion.conf settings
-------------------- [config guide] https://motion-project.github.io/motion_config.html #take a snapshot each 20sec snapshot_interval 20 #%v parameter, which is default start of filename, confuses file ordering snapshot_filename cam1-%Y%m%d%H%M%S-snapshot #maximum jpeg quality picture_quality 100 #tried these autoexposure settings, with no result, but may help #auto_brightness 3 #brightness 100 #auto_brightness "Exposure (Absolute)" # auto exposure in camera, aperture priority, palette YUYV # see https://motion-project.github.io/motion_config.html#video_params video_params palette=15,"Exposure, Auto"=3,"Brightness"=100 #,"Exposure, Auto"=3 #same as: ID10094849=3, # the lower the framerate the lower machine load framerate 2 #we don't need a motion detection and movie saving here, timelapse runs #still on movie_output off picture_output offexposure
======== camera parameters are set using video4linux: (apt-get install v4l-utils) v4l2ucp (gui) + v4l2-ctl #print out all the active settings v4l2-ctl --all # print out options for settings v4l2-ctl --list-ctrls-menus parameters description in video4linux: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-camera.html #setting using cli e.g.: v4l2-ctl -c brightness=120 Exposure (auto) - Manual Exposure - Aperture Priority - exposure_absolute should be the shutter speed -- but must not be longer than duration of the frame -- and exposure_auto must be off to set it or can be set using video_params setting in motion.conf like: video_params ID10094849=3,palette=15,"Brightness"=135 more about v4l settings: https://www.kurokesu.com/main/2016/01/16/manual-usb-camera-settings-in-linux/ output format settings: v4l2-ctl -d /dev/video0 --help-vidcap output format list: v4l2-ctl -d /dev/video0 --list-formats-ext set to 4k v4l2-ctl --set-fmt-video=width=4096,height=2160,pixelformat=MJPG or uvc set the parametrers using uvcdynctrl: uvcdynctrl -c -v and see or grab the image using guvcviewsoftware: alternatives
=======================fswebcam
-------- more simple than motion, easy to use get a frame: # -S sets skip frames after starting the camera to let the auto exposure set-up - 25 is enough # --frames - how many frames to get and join into one (good for static images, motion is blured) # fps 1 ok for timelapse -- necessary for 4k probably fswebcam -d v4l2:/dev/video0 -l 20 --fps 1 -p MJPEG --jpeg 95 -S 5 --frames 10 -r 4096x2160 cam1-%Y-%m-%d_%H-%M-%S.jpg #using logitech brio 4k, 4096x2160 is available only in MJPEG paletteffmpeg?
------- * using ffmpeg to grab individual frames via cron or for loop: #path to ttf font will differ system-to-system ffmpeg -f video4linux2 -input_format yuyv422 -framerate 2 -video_size 1920x1080 -s 1920x1080 \ -i /dev/video0 -frames 1 \ -vf drawtext="fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf:text='%{localtime\:%Y-%m-%d%T}':x=20:y=20:fontcolor=white" \ ./cam1-$(date +%Y%m%d-%H%M%S).jpg (from https://zeevox.net/wordpress/2019/11/linux-webcam-timelapse/) (autoexposure doesn't work now, maybe configure separately)output movie
============ to make a movie out of bunch of jpegs: ffmpeg -framerate 25 -pattern_type glob -i '*snapshot.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4motion (?) bug:
auto exposure doesn't work in fullhd with my camera, whilst ok at 640x480 https://github.com/Motion-Project/motion/issues/1652 it's maybe a linux kernel v4l2 bug. (solution - update kernel?) --------------------- EOF Comments requested ~~~~~~~~~ Binary Sxizophreny - index of comp related stuff Kangaroo's Homepage (czech)