3

I have a Pi 3 with Stretch on it and I'm trying to get Motion to work correctly. In particular I want it to stream to a browser that I'll be able to access. I was able to successfully get the stream to work once. So it's not an issue with the default local host value in the configuration file.

After I got it working once I tried adding it to the rc.local file so it would restart automatically if there was a power failure. After adding it to the file I decided to test it out and reboot the Pi. Now I can't get it to stream at all or save files based on motion detection.

If I check to see if the service is running it says it is, but there are errors. See below for what it gives.

     pi@raspberrypi:~ $ sudo service motion status
     motion.service - LSB: Start Motion detection
       Loaded: loaded (/etc/init.d/motion; generated; vendor preset: enabled)
       Active: active (running) since Mon 2018-06-25 16:22:54 CDT; 2min 42s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 2573 ExecStop=/etc/init.d/motion stop (code=exited, status=0/SUCCESS)
      Process: 2612 ExecStart=/etc/init.d/motion start (code=exited, status=0/SUCCESS)
       CGroup: /system.slice/motion.service
               └─2622 /usr/bin/motion

    Jun 25 16:22:55 raspberrypi motion[2622]: [1:ml1] [NTC] [VID] v4l2_scan_controls:         "Red Balance", default 1000, current
    Jun 25 16:22:55 raspberrypi motion[2622]: [1:ml1] [NTC] [VID] v4l2_scan_controls: found control 0x0098090f, "Blue Balance", ra
    Jun 25 16:22:55 raspberrypi motion[2622]: [1:ml1] [NTC] [VID] v4l2_scan_controls:         "Blue Balance", default 1000, curren
    Jun 25 16:22:55 raspberrypi motion[2622]: [1:ml1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
    Jun 25 16:22:55 raspberrypi motion[2622]: [1:ml1] [NTC] [STR] http_bindsock: listening on 127.0.0.1 port 8081
    Jun 25 16:22:55 raspberrypi motion[2622]: [1:ml1] [NTC] [ALL] motion_init: Started motion-stream server on port 8081 (auth Dis
    Jun 25 16:23:00 raspberrypi motion[2622]: [1:ml1] [ERR] [ENC] ffmpeg_set_outputfile: Permission denied. ./01-20180625162259.mk
    Jun 25 16:23:00 raspberrypi motion[2622]: [1:ml1] [ERR] [ENC] ffmpeg_open: Could not set the stream
    Jun 25 16:23:00 raspberrypi motion[2622]: [1:ml1] [ERR] [EVT] event_ffmpeg_newfile: ffopen_open error creating (new) file [./0
    Jun 25 16:23:00 raspberrypi motion[2622]: [1:ml1] [NTC] [ALL] motion_detected: Motion detected - starting event 1

My guess is that the line "ffmpeg_set_outputfile: Permission denied. ./01-20180625162259.mk" is tell me the problem, but I can't figure out how to fix it. Thanks in advanced for any ideas any of you might have.

Steven
  • 31
  • 3

3 Answers3

2

In Debian I wasn't able to get this to work with another directory other than the home directory of the motion process, specified in /etc/passwd , indifferent of permissions

I had to mount --bind /home/storage/videos /var/lib/motion in order to mount another drive in the home dir of the motion process.

To me, without digging in the code, this looks like a bug in motion.

jsaddwater
  • 131
  • 5
2

When I faced this error, the solution was to give the motion user access to the directory defined by the target_dir option.

Aska
  • 21
  • 1
0

The motion package for some distros (Fedora 37, for example) don't set the correct SELinux contexts. To see the contexts SELinux knows about, run:

sudo semanage fcontext -l | grep motion

That should include output something like this:

/var/log/motion\.log.*  regular file  system_u:object_r:motion_log_t:s0
/var/motion(/.*)?       all files     system_u:object_r:motion_data_t:s0

You can confirm whether or not any existing paths that match the shown patterns have the correct context set using:

ls -Z <path>

To ensure the motion data directory exists, and to ensure it and any log files have the correct SELinux contexts, run the following (I created a recordings subdirectory because /var/motion should really be owned by root, but motion needs any directories it writes to to be owned by the user motion):

sudo mkdir -p /var/motion/recordings
sudo chown motion:video /var/motion/recordings
sudo restorecon -r /var/motion
sudo restorecon /var/log/motion.log*

If you're going to configure motion to save its output to a different data directory than /var/motion, then you will also need the correct SELinux context, user and group for that directory (similar thing if you specify a different location for logs). You can do something like:

MOTION_OUTPUT_DIR="/path/you/choose"

mkdir -p "$MOTION_OUTPUT_DIR" chown motion:video "$MOTION_OUTPUT_DIR" chcon --reference=/var/motion --recursive "$MOTION_OUTPUT_DIR"

Now just set target_dir /var/motion/recordings explicitly in /etc/motion/motion.conf and restart the motion service (sudo systemctl restart motion).

jwatt
  • 101