Source type: file, permission denied

Forum for questions and support relating to the 1.29.x releases only.
Locked
linforpros
Posts: 39
Joined: Fri Jan 29, 2016 6:12 pm

Source type: file, permission denied

Post by linforpros »

Hello,
I am experimenting with source type of File and I am getting "permission denied" in the logs. The file is located under:
/root/images/file.jpg

Is there a directory where files for the source type of "File" should live?
I am aware of the FAQ and sources that zm may not support but there is no hint there about it.
best regards
LinforPros
Nerre
Posts: 100
Joined: Thu Sep 25, 2014 10:22 am

Re: Source type: file, permission denied

Post by Nerre »

What are the permissions for the file?

Usually normal users don't have read access to files under /root, and zm is usually run as the web server user (www-data in Debian).
linforpros
Posts: 39
Joined: Fri Jan 29, 2016 6:12 pm

Re: Source type: file, permission denied

Post by linforpros »

I moved the file to /var/lib/zoneminder/images dir. After a while it disapeared in an abyss :-)
I seems that was not the right directory for it to live.

Aswering your question, though, the permissions are:
-rw-r--r--. 1 root root 418401 Apr 12 2008 file.jpg

I have moved the file again to /var/lib/zoneminder/images and chmod'ed it with
chmod a-w file.jpg
chown apache:apache file.jpg

The file is just a jpg image, no process is ovewriting it at the moment. I am just curious how it works. I can see it in zmNinja and via www.

But what is the right place to place that type of source?
Also, just for an excercise, how to produce a changing .jpg file from some footage? So that I can simulate motion?
Is this something like fmpeg file.avi > file.jpg?



Thanks for any hints
best regards
LinforPros
ParanoidVideo
Posts: 9
Joined: Tue Dec 29, 2015 9:53 pm

Re: Source type: file, permission denied

Post by ParanoidVideo »

On Debian (Ubuntu) the process is running as www-data. The www-data UID is a normal user.

The source file can be placed anywhere you want it to be, doesn't matter. Provide the full path. Make sure that the file is readable by the www-data user. Make sure every directory in the path to the file is also executable by the www-data user. Here is how I checked mine:

$ namei -m /var/ftp/pictures/file.jpg
f: /var/ftp/pictures/file.jpg
drwxr-xr-x /
drwxr-xr-x var
drwxr-xr-x ftp
drwxr-xr-x pictures
-rw-r--r-- file.jpg


Question for everyone: It looks like the load average went way up when I switched to a file type source for one camera. Do you have any suggestions for that? With one camera (Axis web camera) the load is around 0.2 which seems fine. I added a 2nd camera, which is file type (it drops files in by FTP every 2 seconds) and the load went way up. Even though the file rate is lower and the files are much smaller. I must be doing something wrong?
ParanoidVideo
Posts: 9
Joined: Tue Dec 29, 2015 9:53 pm

Re: Source type: file, permission denied

Post by ParanoidVideo »

Another question on source type file. It is triggering on partial images, like this:
026-analyse.jpg
026-analyse.jpg (16.76 KiB) Viewed 6083 times
Clearly what has happened is that it's loading the image while FTP is saving the image.

Any suggestions on how to prevent this? Ideally FTP would be an atomic operation, but that's clearly not the way ti's working. I'm using pure-ftpd.

I did just now add the NoTruncate option on pure-ftp. I will post a follow-up if that solves the problem.
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Source type: file, permission denied

Post by bbunge »

While I have not used the Source Type of "File" there are a couple of things you should know.

1. Files you put in /var/lib/zoneminder/images will be deleted by Zoneminder. If there is no database entry files will be purged.

2. Using the "Files" source type likely means you are uploading a stream of images to your ZM server from a camera or other device. Likely using FTP. So you need to have those files go somewhere where the next file can overwrite the previous with the same file name. How about your /home directory or somewhere you set up to receive the uploaded file? You might be able to use a RAM drive (tmpfs) like /dev/shm

3. Start out with a small file size at a low frame rate. Get it to work then increase things. You may be surprised how well a 1 FPS stream works. I have a very old Axis camera that bangs away at 1 FPS and keeps on working!

bb
linforpros
Posts: 39
Joined: Fri Jan 29, 2016 6:12 pm

Re: Source type: file, permission denied

Post by linforpros »

Hi,
ffmpeg and its "-update" option is well suited to overwite a destination file so perhaps it fits the purpose.

Code: Select all

1. Files you put in /var/lib/zoneminder/images will be deleted by Zoneminder. If there is no database entry files will be purged. 
For example

Code: Select all

ffmpeg -loop -i input.flv -vf fps=1 -update 1 /var/lib/zoneminder/images/image_overwritten.jpg
First. There are two problems, however, with the above command: permission denied if you do it as normal user, and permission not right if done so as root.
Second. input.flv is a vidoe file and the -loop option that ffmpeg takes works only on images, not files. I do not know how to make it work.


Code: Select all

2. Using the "Files" source type likely means you are uploading a stream of images to your ZM server from a camera or other device
I probably do not need a database entry for the file so it could live under /var/lib/zoneminder and then be purged after ffmpeg process has stopped.
best regards
LinforPros
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Source type: file, permission denied

Post by bbunge »

I think you are not hearing what we are saying..

The source type File works with image files that are sent from a camera to a place the server can read them. Most cameras have this ability in fact, this is how they work! They do not make a video file but a series of still images. Think film.

I suspect that you can't do what you think you should be able to do.

I'll not try again to second guess what you want to do. I recommend you peruse the documentation here:

http://zoneminder.readthedocs.org/en/latest/
Nerre
Posts: 100
Joined: Thu Sep 25, 2014 10:22 am

Re: Source type: file, permission denied

Post by Nerre »

Using chmod on the file won't help since it will be overwritten when the next file is saved.

As for the problem with ZM reading the file while it's written I think the only way is to upload the file using a temporary name and then rename it when finished. The problem of course is that the camera might not be able to handle this.

Maybe the ftp server can be configured to open the file exclusively while writing? That means ZM won't get access to the file until it is closed.
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Source type: file, permission denied

Post by knight-of-ni »

If anyone is familiar with the MAX FPS and Alarm MAX FPS fields, you may know that I regularly tell people in the forum to either a) leave those fields empty or b) put a fps value that is higher than the frame rate of the sending device, but never ever place a value in there that is lower. Failing to follow this rule, for camera streams, will cause lag in your live video, dropped frames, missed events, etc. = bad. Because this thread describes a source type of "file" (i.e. the source type is not a stream), this rule does not apply.

When you use a source type of "file", ZoneMinder will try to read the file, over and over, as fast as it can. This is why your load went up. ZoneMinder will read the file as fast as your hardware will let it. So, in this particular case, you do need to place reasonable values into the MAX FPS fields. Since ZoneMinder is reading a file, and not a video stream, these fields will work as intended and not cause any of the previously mentioned problems.

I think I read your image is being updated every 2 seconds. That means a reasonable MAX FPS value for you is 0.5. Placing a value larger than this simply wastes resources. While this won't guarantee you won't ever get a broken image, you may find that it happens so rarely that it is not worth dealing with.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
Locked