Synopsis #
Motion can record video when a camera image changes and can provide a local control page and MJPEG stream. On FreeBSD, a supported USB camera normally reaches Motion through webcamd, the cuse kernel module, and a /dev/video* node.
Prove that camera path before configuring Motion. Keep Motion’s web control and stream bound to localhost; both reveal a privacy-sensitive device, and the control interface can change the running configuration. Remote access should cross an authenticated tunnel or a deliberately designed reverse proxy rather than a public listener.
Establish the camera first #
Install the camera utilities and Motion from the configured package repository:
# pkg install webcamd pwcview motion
Follow Diagnose webcamd, cuse, and a webcam
until the intended camera produces a local image in pwcview. Record the selected device node:
$ ls -l /dev/video*
$ pwcview -f 30 -s vga
Substitute the node established on the system. Close pwcview before starting Motion because two processes may not be able to capture from the same device simultaneously.
Create a working configuration #
The FreeBSD package installs a distribution example, not an active configuration. Preserve that example and create the file required by the rc service:
# install -m 600 /usr/local/etc/motion/motion-dist.conf /usr/local/etc/motion/motion.conf
# install -d -m 700 /var/db/motion
Edit /usr/local/etc/motion/motion.conf. Begin with the following small set of current Motion 4.7 options, changing /dev/video0 only when the established camera uses another node:
daemon on
pid_file /var/run/motion.pid
target_dir /var/db/motion
video_device /dev/video0
width 640
height 480
framerate 15
movie_output on
picture_output off
webcontrol_port 8080
webcontrol_localhost on
webcontrol_parms 0
stream_port 8081
stream_localhost on
The packaged rc script expects /usr/local/etc/motion/motion.conf and tracks /var/run/motion.pid. daemon on and the matching pid_file allow Motion to detach while preserving rc service control. Start with a modest resolution and frame rate that the camera already proved it can deliver.
The example enables event movies and disables still pictures. Review the complete installed example and Motion configuration reference before enabling scripts, databases, notifications, or longer retention.
Start and verify Motion #
Enable the packaged service and start it:
# sysrc motion_enable=YES
# service motion start
# service motion status
$ pgrep -lf motion
Inspect recent daemon messages if startup fails:
# tail -n 100 /var/log/messages
Common failures at this stage are an absent /dev/video* node, a device still held by a viewer, an unsupported image format or resolution, an unwritable target directory, or a configuration option copied from an older Motion release.
Confirm that the two HTTP listeners remain local:
# sockstat -4 -6 -l | grep motion
The expected listener addresses are loopback addresses on ports 8080 and 8081. A wildcard address such as *: or a non-loopback host address means the interface is exposed beyond the intended boundary.
Check control, streaming, and recording separately #
Open the local control page and stream from a browser on the FreeBSD host:
http://127.0.0.1:8080/
http://127.0.0.1:8081/
The control page proves the daemon’s HTTP interface. The stream proves ongoing capture. Neither proves that event detection writes a usable recording.
Create motion in the camera’s field of view, wait for the configured event gap, and inspect the target directory:
# find /var/db/motion -type f -ls
Play a completed sample file and confirm its time, duration, and image content. Then review free space and ownership:
$ df -h /var/db/motion
# ls -ld /var/db/motion
Video retention needs an explicit capacity and privacy policy. A full target filesystem can interrupt recording and other services if it shares their dataset. Place recordings in a dedicated dataset or filesystem when quotas, snapshots, or disposal policy require a separate boundary.
Reach the interface without publishing it #
For occasional administration from another machine, retain the localhost settings and use SSH port forwarding from the client:
$ ssh -L 8080:127.0.0.1:8080 -L 8081:127.0.0.1:8081 administrator@camera-host
While that SSH session remains open, the client can use http://127.0.0.1:8080/ and http://127.0.0.1:8081/. SSH supplies authentication and encryption without changing Motion’s listener scope.
A permanently shared interface needs its own threat model, authentication, TLS termination, access logs, updates, and exposure test. Use Publish a network service safely before placing a reverse proxy or firewall rule in front of Motion. Do not expose an unauthenticated Motion control port directly to the Internet.
Recheck after camera or package changes #
Moving a USB camera, changing a dock, or attaching an identical device can alter device selection. After such a change:
- confirm the camera with
webcamd -l; - confirm the resulting
/dev/video*node; - test one local frame with
pwcview; - restart Motion;
- verify a new completed recording.
After a Motion package upgrade, compare the installed distribution example and upstream release notes with the active configuration. Do not replace the active file wholesale because it also carries local device, storage, and exposure policy.