Motion - Advanced Filenames

Advanced Filenames

Motion has a very advanced and flexible automated filenaming feature.

By using conversion specifiers (codes that consist of a '%' followed by a letter) you can build up the filenames including sub directories for pictures and movies using any combination of letters, numbers and conversion specifiers which are codes that represents time, date, event number and frame numbers.

The option target_dir is the target directory for all snapshots, motion images and normal images. The default is the current working directory (current working directory of the terminal from which motion was started). You will normally always want to specify this parameter.

Note that the options snapshot_filename, jpeg_filename, ffmpeg_filename, and timelapse_filename all allow specifying directories by using '/' in the filename. These will all be relative to target_dir. This means in principle that you can specify target_dir as '/' and be 100% flexible. It also means that Motion can write files all over your harddisk if you make a mistake. It is recommended to specify the target_dir as deep or detailed as possible for this reason. And note that targer_dir does not allow conversion specifiers.

The conversion specifier %C which is defined by the option text_event is interesting in connection with filenames because it can be used to create files and directories for each event in a very flexible way.

The convertion specifier %t (thread/camera number) is also very useful. Here is an example of filename definitions in motion.conf:

target_dir /usr/local/webcam
snapshot_filename cam%t/%v-%Y%m%d%H%M%S-snapshot
jpeg_filename cam%t/%v-%Y%m%d%H%M%S-%q
ffmpeg_filename cam%t/%v-%Y%m%d%H%M%S
timelapse_filename cam%t/%Y%m%d%H-timelapse

The smart thing is that this defines the filename of all your camera threads in motion.conf so you do not need to specify target dir and filenames in the thread config files. In the above example an mpegfile for camera thread 3 will be saved as a filename similar to /usr/local/webcam/cam3/28-20051128130840.avi

NOTE: Unless you use the minimum_gap option to limit the number of shots to less then one per second - you must use the frame modifier %q as part of the jpeg_filename. Otherwise the pictures saved within the same second will overwrite each other. The %q in jpeg_filename ensures that each jpeg (or ppm) picture saved gets a unique filename.

ALERT! Security Warning! Note that the flexibility of this feature also means you have to pay attention to the following.
  • Anyone with access to the remote control port (http) can alter the values of these options and save files anywhere on your server with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside.
  • Anyone with local access to the computer and edit rights to the motion.conf file can alter the values of these options and save files anywhere on your server with the same privileges as the user running Motion. Make sure the motion.conf file is maximum readonly to anyone else but the user running Motion.
  • It is a good idea to run Motion as a harmless user. Not as root.

These are the advanced filename options in motion.conf

-- KennethLavrsen - 12 Dec 2005
Topic revision: r7 - 12 Dec 2005, KennethLavrsen
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.