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.

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
ffmpeg_filename (now called movie_filename)
This option was renamed to movie_filename in 3.2.5 to enable better integration of alternative movie libraries to the current ffmpeg solution.
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S
- Option Topic
File path for motion triggered ffmpeg movies (mpeg) relative to target_dir. This option was renamed to movie_filename in 3.2.5 to enable better integration of alternative movie libraries to the current ffmpeg solution.
Default value is equivalent to legacy 'oldlayout' option
For Motion 3.0 compatible mode (directories based on date and time) choose: %Y/%m/%d/%H%M%S
File extension .mpg or .avi is automatically added so do not include this.
This option uses
conversion specifiers which are codes that start by % and then a letter. The conversion specifiers used has the same function as for the C function strftime (3). The most commonly used are:
- %Y = year
- %m = month as two digits
- %d = date
- %H = hour
- %M = minute
- %S = second
- %T = HH:MM:SS
These are unique to motion
- %v = event
- %q = frame number
- %t = thread (camera) number
- %D = changed pixels
- %N = noise level
- %i = width of motion area
- %J = height of motion area
- %K = X coordinate of motion center
- %L = Y coordinate of motion center
- %C = value defined by text_event
If you are happy with the directory structures the way they were in earlier versions of motion use %v-%Y%m%d%H%M%S for 'oldlayout on' and %Y/%m/%d/%H%M%S for 'oldlayout off'.
jpeg_filename
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S-%q
- Option Topic
File path for motion triggered images (jpeg or ppm) relative to target_dir. Value 'preview' makes a jpeg filename with the same name body as the associated saved mpeg movie file.
Default value is equivalent to legacy 'oldlayout' option. For Motion 3.0 compatible mode (directories based on date and time) choose: %Y/%m/%d/%H/%M/%S-%q
This option uses
conversion specifiers which are codes that start by % and then a letter. The conversion specifiers used has the same function as for the C function strftime (3). The most commonly used are:
- %Y = year
- %m = month as two digits
- %d = date
- %H = hour
- %M = minute
- %S = second
- %T = HH:MM:SS
These are unique to motion
- %v = event
- %q = frame number
- %t = thread (camera) number
- %D = changed pixels
- %N = noise level
- %i = width of motion area
- %J = height of motion area
- %K = X coordinate of motion center
- %L = Y coordinate of motion center
- %C = value defined by text_event
If you are happy with the directory structures the way they were in earlier versions of motion use %v-%Y%m%d%H%M%S-%q for 'oldlayout on' and %Y/%m/%d/%H/%M/%S-%q for 'oldlayout off'.
The value 'preview' only works when 'output_normal' is set to 'best'. It makes Motion name the best preview jpeg file (image with most changed pixels during the event) with the same body name as the mpeg movie created during the same event. The purpose is to create a good single image that represents the saved mpeg moview so you can decide if you want to see it and spend time downloading it from a web page.
movie_filename
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S
- Option Topic
File path for motion triggered ffmpeg movies (mpeg) relative to target_dir. This was previously called ffmpeg_filename.

This option was renamed from ffmpeg_filename to movie_filename in Motion 3.2.5.
Default value is equivalent to legacy 'oldlayout' option
For Motion 3.0 compatible mode (directories based on date and time) choose: %Y/%m/%d/%H%M%S
File extension .mpg or .avi is automatically added so do not include this.
This option uses
conversion specifiers which are codes that start by % and then a letter. The conversion specifiers used has the same function as for the C function strftime (3). The most commonly used are:
- %Y = year
- %m = month as two digits
- %d = date
- %H = hour
- %M = minute
- %S = second
- %T = HH:MM:SS
These are unique to motion
- %v = event
- %q = frame number
- %t = thread (camera) number
- %D = changed pixels
- %N = noise level
- %i = width of motion area
- %J = height of motion area
- %K = X coordinate of motion center
- %L = Y coordinate of motion center
- %C = value defined by text_event
If you are happy with the directory structures the way they were in earlier versions of motion use %v-%Y%m%d%H%M%S for 'oldlayout on' and %Y/%m/%d/%H%M%S for 'oldlayout off'.
snapshot_filename
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S-snapshot
- Option Topic
File path for snapshots (jpeg or ppm) relative to target_dir.
Default value is equivalent to legacy 'oldlayout' option. For Motion 3.0 compatible mode (directories based on date and time) choose: %Y/%m/%d/%H/%M/%S-snapshot
File extension .jpg or .ppm is automatically added so do not include this
A symbolic link called lastsnap.jpg (or lastsnap.ppm) created in the target_dir will always point to the latest snapshot, unless snapshot_filename is exactly 'lastsnap'
This option uses
conversion specifiers which are codes that start by % and then a letter. The conversion specifiers used has the same function as for the C function strftime (3). The most commonly used are:
- %Y = year
- %m = month as two digits
- %d = date
- %H = hour
- %M = minute
- %S = second
- %T = HH:MM:SS
These are unique to motion
- %v = event
- %q = frame number
- %t = thread (camera) number
- %D = changed pixels
- %N = noise level
- %i = width of motion area
- %J = height of motion area
- %K = X coordinate of motion center
- %L = Y coordinate of motion center
- %C = value defined by text_event
If you are happy with the directory structures the way they were in earlier versions of motion use %v-%Y%m%d%H%M%S-snapshot for 'oldlayout on' and %Y/%m/%d/%H/%M/%S-snapshot for 'oldlayout off'.
For the equivalent of the now obsolete option 'snap_overwrite' use the value 'lastsnap'.
target_dir
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined = current working directory
- Option Topic
Target directory for picture and movie files.
This is the target directory for all snapshots, images files and movie files. 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 as an absolute path.
Note that the options snapshot_filename, jpeg_filename, ffmpeg_filename, and timelapse_filename all allows specifying directories. 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.
timelapse_filename
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d-timelapse
- Option Topic
File path for timelapse mpegs relative to target_dir (ffmpeg only).
Default value is equivalent to legacy 'oldlayout' option.
For Motion 3.0 compatible mode (directories based on date and time) choose: %Y/%m/%d-timelapse
File extension .mpg is automatically added so do not include this.
This option uses
conversion specifiers which are codes that start by % and then a letter. The conversion specifiers used has the same function as for the C function strftime (3). The most commonly used are:
- %Y = year
- %m = month as two digits
- %d = date
- %H = hour
- %M = minute
- %S = second
- %T = HH:MM:SS
These are unique to motion
- %v = event
- %q = frame number
- %t = thread (camera) number
- %D = changed pixels
- %N = noise level
- %i = width of motion area
- %J = height of motion area
- %K = X coordinate of motion center
- %L = Y coordinate of motion center
- %C = value defined by text_event
If you are happy with the directory structures the way they were in earlier versions of motion use %v-%Y%m%d-timelapse for 'oldlayout on' and %Y/%m/%d-timelapse for 'oldlayout off'.
--
KennethLavrsen - 12 Dec 2005