【翻译】动态图像监测开源代码 motion 学习-----Motion Guide - Basic Features(motion的基本特性)(二)
说在前面:
原文链接 点击打开链接
Motion Guide - Basic Features(基本特性)
Generating MPEG films with ffmpeg(用ffmpeg产生MPEG影片)
- ffmpeg-0.4.8. With this release Motion supports mpeg1, mpeg4 and msmpeg4. Lately newer distributions have problems building this 2003 release of ffmpeg so many of you no longer have this option.
- ffmpeg-0.4.9pre1. Is supported starting from Motion version 3.1.18. With this release Motion supports mpeg4 and msmpeg4 but not mpeg1. The reason is that the ffmpeg team has decided no longer to support non-standard framerates in their mpeg1 encoder library. Also ffmpeg-0.4.9pre1 gives people problems on newer distributions.
- ffmpeg from CVS. This may work. We cannot continuously monitor and try every time a new source file is checked into ffmpeg. You will have to try.
- ffmpeg RPMs. Currently each Motion release is tested with the current Livna ffmpeg rpm package for Fedora. See the Download Filespage for direct links to the version which has been certified with the latest Motion release.
- ffmpeg debian binaries. Latest versions from the debian repository for Debian Sarge works fine with Motion.
- Certified ffmpeg CVS snapshot for latest Motion release is available from the Motion Sourceforge Related Projects file area
Download the ffmpeg and untar it to /usr/local/ffmpeg. Then it should be a simple matter of entering the ffmpeg directory and run the commands(首先下载ffmpeg然后解压到/usr/local/ffmpeg.。接下来就是进入ffmpeg目录,然后执行下面的命令)
cd /usr/local/ffmpeg
./configure --enable-shared
make
make install
This creates the
libavcodec.so
and libavformat.so
libraries under /usr/local/lib
and header files under /usr/local/include/ffmpeg
.(告诉你生成了哪些文件,文件在哪里)Make sure you have 'root' privileges for the next steps.(在下面的步骤里,确保你拥有了root权限)
Open the file
/etc/ld.so.conf
in your favorite text editor.(用你最喜欢的编辑器打开文件/etc/ld.so.conf)
/usr/local/lib
ldconfig
.
Motion should now be able to find the shared libraries for ffmpeg (
libavcodec.so
and libavformat.so
) in/usr/local/lib
.
下面另一种方法安装ffmpeg(用rpm包安装):
You can also find a pre-compiled binary package (e.g. rpm or deb) and install this. Normally an rpm will place thelibavcodec.so
under /usr/lib
. There are various RPMs available from different repositories. Some need additional RPMs that are actually not needed by Motion but need to be installed to satisfy dependencies. The editor has tried different RPMs of ffmpeg-0.4.8 and they all seem to work.
Motion then need to be built by running ./configure
,make
and make install
. ((接下来就是从新配置和安装motion。分别执行:./configure
,
make
和 make install
)。Note that with earlier versions of motion you had to specify the location of libavcodec. Now configure searches for the shared library in /usr/lib
and /usr/local/lib
by default.)
Note that if you install ffmpeg from source and already have ffmpeg installed from an RPM, the Motion configure may very well find the binary library from the rpm instead of the sources. Make sure to uninstall any old ffmpeg RPMs before you install ffmpeg from sources.(提示你如果你在已经用rpm方式安装了ffmpeg情况下去安装源码方式ffmpeg,那么motion会从rpm找到二进制库而不是从源码方式中找。确保在安装源码方式的ffmpeg时,把旧的rpm版的ffmpeg卸掉。)
从此处之后只对每个选项中我认为比较重要的段落进行意思解析,提示需要注意的地方,不会再出现对整段进行翻译的情况,除非是我认为很重要的地方。而且每段的意思解析都会紧跟在该段之后(这样更清晰),如果某段没有意思解析,则说明该段不重要或者我也理解不了,如果需要详细的内容请点击文章开头的源码链接自行翻阅。(为了简单,文中的 “说:” 代表 “意思是:”,再直白一点就是 “作者要告诉你的是:” )
ffmpeg_bps(ffmpeg比特率)
- Type: Integer
- Range / Valid values: 0 - 9999999
- Default: 400000
- Option Topic
To use this feature you need to install the FFmpeg Streaming Multimedia System.
Experiment to get the desired quality. The better quality the bigger files. This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled).
ffmpeg_cap_motion
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Use ffmpeg libraries to encode motion type mpeg movies where you only see the pixels that changes.
Works like ffmpeg_cap_new but outputs motion pixel type pictures instead.
This feature generates the special motion type movie where you only see the pixels that changes as a graytone image. If labelling is enabled you see the largest area in blue. Smartmask is shown in red. The filename given is the same as the normal mpegs except they have an 'm' appended after the filename before the .mpg. E.g. 20040424181525m.mpg
To use this feature you need to install the FFmpeg Streaming Multimedia System
ffmpeg_cap_new
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Use ffmpeg libraries to encode mpeg movies in realtime.
Generates a new film at the beginning of each new event and appends to the film for each motion detected within the same event. The current event ends when the time defined by the 'gap' option has passed with no motion detected. At the next detection of motion a new mpeg film is started.
To use this feature you need to install the FFmpeg Streaming Multimedia System
Must not be included in config file without having ffmpeg installed.
ffmpeg_deinterlace(ffmpeg隔行扫描)
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Use ffmpeg to deinterlace(隔行扫描) video. Necessary if you use an analog(模拟) camera and see horizontal combing on moving objects in video or pictures.
Must not be included in config file without having ffmpeg installed.
一个动态影像是由一连串连续的静态影像所组成的,其中每一个静态影像称为帧(frame),而动态影像中每秒所包含静态影像的数量则称为帧(速)率(frame per second, fps)。
而在显示器上显示动态影像的方式有两种:
- 渐进扫描:或称为逐行扫描。将每一帧从左至右、由上至下,逐一的将所有的画素显示出来。
- 交错扫描:或称为隔行扫描。将一帧图像的奇数行画素及偶数行画素分开,分成为两个场(field)。轮流扫描奇数行所构成的场及偶数行所构成的场。
因为一个场只有一个帧一半的资讯,因此在装置处理速度无法即时的处理整个帧的资讯以及传输带宽不够即时传输整个帧的情形下,使用交错扫描可以节省一半的资讯量且可以为持相同的更新率。
ffmpeg_timelapse(时间推移)
- Type: Boolean
- Range / Valid values: 0 - 2147483647
- Default: 0 (disabled)
- Option Topic
Create a timelapse movie saving a picture frame at the interval in seconds set by this parameter. Set it to 0 if not used.
This feature uses ffmpegs libavcodec to encode a timelaps movie saving a picture frame at the interval in seconds set by this parameter. Setting this option to 0 disables it.
The feature gives your viewer the chance to watch the day pass by. It makes a nice effect to film flowers etc closeup during the day. Options like frame_rate, snapshot, gap etc have no impact on the ffmpeg timelapse function.
Note that the timelapse format is always mpeg1 independent of ffmpeg_video_codec. This is because mpeg1 allows the timelapse to stop and the file to be reopened and more film appended.
To use this feature you need to install the FFmpeg Streaming Multimedia System.
(renamed from ffmpeg_timelaps to ffmpeg_timelapse in 3.1.14)
ffmpeg_timelapse_mode(时间推移方式)
- Type: Discrete Strings
- Range / Valid values: hourly, daily, weekly-sunday, weekly-monday, monthly, manual
- Default: daily
- Option Topic
把下面这几段读完感觉有点意思了,这个功能定义一个值后,可以按照这个值所代表的时间来对下一次的文件进行重新名字,以便查看视频的人可以很方便找到想要的某个时间的视频。ffmpeg_timelapse这个选项也是这种用途,只是定义方式不一样,但是ffmpeg_timelapse只用于mepg1视频压缩方式(这是一种旧的压缩方式)。
举个例子更容易理解:假如把此项定义为hourly,那么每隔一个小时你可以对要保存的视频文件定义一个新名字,以便与和之前的文件进行区分。目的是为了让观看视频者尽快的找到想要的视频文件。这样一说好像就明白多了。
其他几个定义请自己再往读一下吧。
The file rollover mode of the timelapse video.Note that it is important that you use the conversion specifiers in ffmpeg_filename that ensure that the new timelapse file indeed is a new file. If the filename does not change Motion will simply append the timelapse pictures to the existing file.
The value 'Manual' means that Motion does not automatically rollover to a new filename. You can do it manually using the http control interface by setting the option 'ffmpeg_timelapse' to 0 and then back to your chosen value. Value 'hourly' rolls over on the full hour. Value 'daily' which is the default rolls over at midnight. There are two weekly options because depending on where you come from a week may either start on Sunday or Monday. And 'monthly' naturally rolls over on the 1st of the month.
ffmpeg_video_codec(视频压缩方式)
- Type: Discrete Strings
- Range / Valid values: mpeg1 (ffmpeg-0.4.8 only), mpeg4, msmpeg4, swf, flv, ffv1, mov
- Default: mpeg4
- Option Topic
Codec to be used by ffmpeg for the video compression. Timelapse mpegs are always made in mpeg1 format independent from this option.
- mpeg1 - gives you mpeg1 files with extension .mpg. It is only supported by the old ffmpeg version 0.4.8. The ffmpeg team decided no longer to support non-standard framerates for mpeg1 from ffmpeg version 0.4.9pre1.
- mpeg1是一种旧的压缩方式,后缀为.mpg
- mpeg4 - gives you mpeg4 files with extension .avi
- mpeg4后缀为.avi,这个很常见
- msmpeg4 - also gives you mpeg4 files. It is s recommended for use with Windows Media Player because it requires with no installation of codec on the Windows client.
- swf - gives you a flash film with extension .swf
- swf格式的视频我也见过
- flv - gives you a flash video with extension .flv
- flv格式也很常见
- ffv1 - FF video codec 1 for Lossless Encoding (experimental)
- mov - QuickTime (since 3.2.10).
This option does not affect the timelapse feature. Timelapse is always recorded in mpeg1 format because we need to be able to append to an existing file. mpeg4 does not easily allow this.
If you want to use this feature you can read about theFFmpeg Streaming Multimedia System
Snapshots - The Traditional Periodic Web Camera(传统的周期性的网络摄像头)
Motion can also act like a traditional web camera.snapshot_interval(快照间隔)
- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0 (disabled)
- Option Topic
Make automated snapshots every 'snapshot_interval' seconds.
The snapshots are stored in the target directory + the directory/filename specified by the snapshot_filename option.
This is the traditional web camera feature where a picture is taken at a regular interval independently of motion in the picture.
还是说此特性的功能类似传统的网络摄像头。
See the also snapshot_filename option in the section Advanced Filenames.
Text Features(视频中文字的显示特性)
Text features are highly flexible. You can taylor the text displayed on the images and films to your taste and you can add your own user defined text.This is how the overlayed text is located.
Below are the options that controls the display of text. The 'locate' option is not a text feature but described here because it is related to information overlayed on the output images.
The text_event
feature is special in that it defines the conversion specifier %C which can be used both for text display and for filenames.
说:text_event
特性有点特殊,因为它定义的转换说明符C%可以同时用在文本显示和文件名称中。
locate(位置)
- Type: Boolean
- Range / Valid values: on, off, preview
- Default: off
- Option Topic
Locate and draw a box around the moving object. Value 'preview' makes Motion only draw a box on a saved preview jpeg image and not on the saved mpeg movie.
说:Locate会在移动的物体上画一个框。值preview是Motion在保存的预览图中画一个框,而不是在保存的mpeg影片上画框。
The value 'preview' only works when 'output_normal' is set to either 'first' or 'best'.
值 preview仅在output_normal被设置为'first' or 'best'时才有效。
text_changes
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Turns the text showing changed pixels on/off.
说:控制文本显示像素值
By setting this option to 'on' the number of pixels that changed compared to the reference frame is displayed in the upper right corner of the pictures. This is good for calibration and test. Maybe not so interesting for a greater public. Set it to your personal taste.
说:这个选项适用于校准和调试。不太适合给大众观看(非专业人士可能看不懂!)。所以,决定权依然在你,看自己的口味行事吧亲
text_double(文本字体大小加倍,目的很清楚)
- Type: Boolean
- Range / Valid values: on, off
- Default: off
Draw characters at twice normal size on images.
说:使图像上的字是正常字体大小的2倍。
This option makes the text defined by text_left, text_right and text_changes twice the normal size. This may be useful when using large picture formats such as 640 x 480.
说:这个选项比较适合尺寸比较大的图像,比如640 x 480.
text_event(事件的时间)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %Y%m%d%H%M%S
- Option Topic
This option defines the value of the speciel event conversion specifier %C. You can use any conversion specifier in this option except %C. Date and time values are from the timestamp of the first image in the current event.
The idea is that %C can be used filenames and text_left/right for creating a unique identifier for each event.
Option text_event defines the value %C which then can be used in filenames and text_right/text_left. The text_event/%C uses the time stamp for the first image detected in a new event. %C is an empty string when no event is in progress (gap period expired). Pre_captured and minimum_motion_frames images are time stamped before the event happens so %C in text_left/right does not have any effect on those images.
text_left(左下角的文本)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
User defined text overlayed on each in the lower left corner. Use A-Z, a-z, 0-9, " / ( ) @ ~ # < > , . : - + _ \n and vertical bar and conversion specifiers (codes starting by a %).
说:位置在左下角。可以使用 A-Z, a-z, 0-9, " / ( ) @ ~ # < > , . : - + _ \n and vertical bar和conversion specifiers 。
text_left is displayed in the lower left corner of the pictures. If the option is not defined no text is displayed at this position.
说:如果诶有定义此选项,则不显示关于该选项的任何内容
You can place the text in quotation marks to allow leading spaces. With a combination is spaces and newlines you can position the text anywhere on the picture.
说:把文本放在引号内可以允许空格开头。通过空格和\n的组合允许文本显示在图像上的任何位置。闭上眼想像一下就可以明白了。
Detailed Description
A conversion specifier is a code that starts by % (except newline which is \n). 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
With a combination of text, spaces, new lines \n and conversion specifiers you have some very flexible text features.
For a full list of conversion specifiers see the section Conversion Specifiers for Advanced Filename and Text Feature.
说:相信内容参见Advanced Filename 和Text Feature的.Conversion Specifiers 部分。
text_right(右下角的文本)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %Y-%m-%d\n%T
- Option Topic
text_right is displayed in the lower right corner of the pictures. If the option is not defined no text is displayed at this position.
You can place the text in quotation marks to allow leading spaces. With a combination is spaces and newlines you can position the text anywhere on the picture.
A major difference from text_left is that if this option is undefined the default is %Y-%m-%d\n%T which displays the date in ISO format YYYY-MM-DD and below the time in 24 hour clock HH:MM:SS.
Detailed Description
A conversion specifier is a code that starts by % (except newline which is \n). 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
With a combination of text, spaces, new lines \n and conversion specifiers you have some very flexible text features.
For a full list of conversion specifiers see the sectionConversion Specifiers for Advanced Filename and Text Feature.
说:把文本放在引号内可以允许空格开头。通过空格和\n的组合允许文本显示在图像上的任何位置。详细内容参见Advanced Filename 和Text Feature的.Conversion Specifiers 部分。
(回去睡觉,过个周末)
(周末结束,继续 . . .)
Advanced Filenames(厉害的文件命名方法)
Motion has a very advanced and flexible automated filenaming feature.说:Motion有高级且灵活的文件自动命名规则。
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.
说:Motion的输出结果全部都保存在target_dir
这个选项所定义的目录中。target_dir
默认是运行motion的当前目录。通常你需要根据自己的情况指明target_dir
这个参数。
Note that the options
snapshot_filename
,jpeg_filename
, ffmpeg_filename
, andtimelapse_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.
说:选项snapshot_filename
,jpeg_filename
, ffmpeg_filename
和timelapse_filename允许指明的目录名称中包含字符'/'。它们的目录全都和target_dir相关联。需要注意的是,如果你指定target_dir时有错误,那么将会出现motion在你的硬盘上到处都存有文件。所以,建议你一定要严格详细地指定target_dir所代表的目录。而且,target_dir不允许包含转换说明符。(说明白了,这段话就是要告诉你,target_dir这个目录非常重要,一定要使用绝对路径,因为其他文件的输出目录都跟它有关。)
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:
说:%t很有用,它可以代表线程或者相机的序号,看看下面的例子就明白了。下面是一个在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 injpeg_filename
ensures that each jpeg (or ppm) picture saved gets a unique filename.
说:除非你使用了minimum_gap
选项,否则在定义jpeg_filename时一定要使用%q 这个说明符。%q 可以保证jpeg_filename文件不重名。重名就会覆盖之前的文件。
![ALERT! ALERT!](https://i-blog.csdnimg.cn/blog_migrate/8165cbe962fb1e56da951b245b57644f.png)
主要告诉你一些安全警告,建议你使用一个普通无害的用户运行motion,不要使用root。
- 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
下面是在motion.conf中关于文件名称的选项
target_dir(目标目录,最重要的一个)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined = current working directory(默认为当前工作目录)
- Option Topic
ffmpeg_filename (now called movie_filename)(在版本3.2.5中已经重命名为movie_filename)
![ALERT! ALERT!](https://i-blog.csdnimg.cn/blog_migrate/8165cbe962fb1e56da951b245b57644f.png)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S
- Option Topic
下面主要告诉你命名方式和要注意的地方,上面已经介绍过。在这里我建议把target_dir 定义为自己希望的绝对路径后,其他的几个选项用默认值就行,除非有很强的目的性再去改它们。下面的几个选项也是类似的。
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
movie_filename(之前叫ffmpeg_filename)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S
- Option Topic
snapshot_filename
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S-snapshot
- Option Topic
- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d-timelapse
- Option Topic
Conversion Specifiers for Advanced Filename and Text Features(转换说明符)
The table below shows all the supported Conversion Specifiers you can use in the optionstext_event
,text_left
, text_right
, sql_query
,snapshot_filename
, jpeg_filename
,ffmpeg_filename
, timelapse_filename
,on_event_start
, on_event_end
, on_picture_save
,on_movie_start
, on_movie_end
, andon_motion_detected
. 说:下表中的转换说明符可以用在 text_event
,text_left
, text_right
, sql_query
,snapshot_filename
,
jpeg_filename
,ffmpeg_filename
, timelapse_filename
,on_event_start
, on_event_end
, on_picture_save
,on_movie_start
, on_movie_end
, andon_motion_detected这些选项中。
In text_left
and text_right
you can additionally use '\n' for new line.
说:在选项text_left
and text_right中还可以加上'\n' 来换行。
转换说明符列表链接 点击打开链接
Webcam Server(网络相机服务,就是支持在网页上观看视频)
Motion has simple webcam server built in. The video stream is in mjpeg format.
说:Motion内置有简单的网络相机服务。视频格式为mjpeg。
Each thread can have its own webcam server. If you enable the webcam server (option webcam_port to a number different from 0) and you have more than one camera, you must make sure to include webcam_port in each thread config file and set webcam_port to different and unique port numbers or zero (disable). Otherwise each webcam server will use the setting from the motion.conf file and try to bind to the same port. If the webcam_port numbers are not different from each other Motion will disable the webcam feature.
说:每一个线程都可以有自己的网路相机。如果你使能了网络相机(即选项webcam_port非0)并且有多个相机,那么你必须确保每个相机的线程有自己独立的 webcam_port 值(非0)。否则每个网络相机都将使用motion.conf 中设定的webcam_port, 都试图去连接那同一个webcam_port 从而产生冲突。如果每个网络相机的webcam_port 值是唯一的,那么Motion将忽略motion中的webcam特性。
Note: The webcam server feature requires that the option
ppm
is set to off.
注意:网络相机需要把ppm这个选项关掉。
The
webcam_maxrate
and webcam_quality
options are important to limit the load on your server and link. Don't set them too high unless you only use it on the localhost or on an internal LAN. The option webcam_quality
is equivalent to the quality level for jpeg pictures.
说:不要把选项webcam_maxrate
and webcam_quality很重要,但是不要把它们
设置的太大,除非你只在本地或者网络LAN上使用。webcam_quality
选项等价于jpeg图片的质量。
The
webcam_limit
option prevents people from loading your Network connection by streaming for hours and hours. The options defines the number of picture frames sent as mjpeg Motion will allow without re-connecting (e.g. clicking refresh in the browser).
说:webcam_limit
选项阻止别人不停地加载你的网络连接。它定义了作为mjpeg格式发送的图片数量。Motion不用重新连接。
The option
webcam_localhost
is a security feature. When enabled you can only access the webserver on the same machine as Motion is running on. If you want to present a live webcam on your web site this feature must be disabled.
说:webcam_localhost
选项是一个安全特性,它只允许在本机上使用网络服务。如果你想在网址上线展示,那就把这个选项关掉。
The webserver generates a stream in "multipart jpeg" format (mjpeg). You cannot watch the stream with most browsers. Only certain versions of Netscape works. Mozilla and Firefox brosers can view the mjpeg stream but you often have to refresh the page once to get the streaming going. Internet Explorer cannot show the mjpeg stream. For public viewing this is not very useful. There exists a java applet called Cambozola which enabled any Java capable browser to show the stream. To enable the feature to a broad audience you should use this applet or similar.
主要告诉你如果想在浏览器上看motion工作时的视频,你只能使用Mozilla and Firefox这种支持流mjpeg 的浏览器。Internet Explorer不行。但是你可以通过支持java的浏览器使用一个叫 Cambozola的java小程序来观看motion的视频。
To use the webcam feature with Cambozola is actually very simple.
说:用Cambozola 很简单,下面就是步骤。
1. Create a html page in which you will want the streamed picture.
打开浏览器
2. In the html page include this code
在地址栏输入下面的代码
<applet code=com.charliemouse.cambozola.Viewer
archive=cambozola.jar width="320" height="240" style="border-width:1; border-color:gray; border-style:solid;"> <param name=url value="http://www.myurl.com:8081"> </applet>
Where the width and height is the image size of the video stream.
width and height是图像的尺寸
Replace www.myurl.com:8081 by the real url and port number of your choice.
用你真实的链接和端口替换www.myurl.com:8081
3. In the same directory you place the cambozola.jar file. No need to build the java applet from source. Simply use the applet in the package.
在同一个目录中加入文件cambozola.jar,不用编译,只是使用。
4. Enable the feature in motion.conf.
最后在motion.conf使能网络相机的特性即可
You can also view the live webcam stream using MPlayer like this:
你还可以通过MPlayer来观看在线的饿视频,方式如下
mplayer -demuxer lavf http://www.myurl.com:8081/stream.mjpg
Note that the
stream.mjpg
part is important, without it you will get a LAVF_check: no clue about this gibberish!
error from libavformat.
注意stream.mjpg
一定要加上,否则会有错误
Note that you can stream from multiple videos by having several applet viewers on each page (pointed to different url's, of course).
你可以通过多个浏览器页面同时观看多个相机的视频,每个相机指向不同的端口。
These are the special webcam parameters.
下面就是这些特殊的网络相机参数,上面已经介绍的饿差不多了,简单看一下它们的定义就行。
webcam_limit
- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0 (unlimited)
- Option Topic
webcam_localhost
- Type: Boolean
- Range / Valid values: on, off
- Default: on
- Option Topic
webcam_maxrate
- Type: Integer
- Range / Valid values: 1 - 100
- Default: 1
- Option Topic
webcam_motion
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
webcam_port
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0 (disabled)
- Option Topic
webcam_quality
- Type: Integer
- Range / Valid values: 1 - 100
- Default: 50
- Option Topic
Remote Control with http(利用HTTP进行远程控制)
Motion can be remote controlled via a simple http interface. http is the language a normal web browser talks when it requests a web page. The web server answers back with some simple http headers followed by a webpage coded in HTML.
说:motion可以通过简单的HTTP见面来控制。
Most Motion config options can be changed while Motion is running except options related to the size of the captured images and mask files which are loaded only when Motion starts. So only your fantasy sets the limit to what you can change combining cron and the remote control interface for Motion.
说:大部分的配置选项都可以远程控制,除了那些和图像尺寸相关的和那一些在一开始就加载到motion中的mask文件。
So the most obvious tool to use to remote control Motion is any web browser. All commands are sent using the http GET method which simply means that the information is sent via the URL and maybe a query string. You can use any browser (Firefox, Mozilla, Internet Explorer, Konquerer, Opera etc). You can also use the text based browser lynx to control Motion from a console. It navigates fine through the very simple and minimalistic http control interface of Motion.
说:你可以用任何浏览器来进行远程控制。
The details about how to control Motion via the URL is described in detail in the Motion http API topic.
说:详细的远程控制信息请阅读Motion http API 。
But it is probably simpler to connect to the control port with a browser, navigate to the function you want, and copy the URL from the browser URL entry line. If your control_port is 8080 and you browse from the same machine on which Motion runs simply look up http://localhost:8080/ and navigate around. Connecting from a remote machine is done by using a domain name (examplehttp://mydomain.com:8080/) or the IP address of the machine (example http://192.168.1.4:8080/). The option control_localhost must be off to allow connection from a remote machine.
说:用浏览器连接motion很简单。如果 control_port 是8080,那么在本机上可以在浏览器地址栏中直接输入http://localhost:8080/ ,如果远程控制则输入http://mydomain.com:8080/,mydomain为你的域名,用IP待地也行。如果要使用这个选项,你要control_localhost这个选项关掉。
If you want to use a script or cron to automatically change Motion settings while Motion runs you use a program that can fetch a webpage. We simply just throw away the html page that Motion returns. Programs commonly available on Linux machines are wget and lwp-request. Here is an example of how to start and stop motion detection via cron. These two lines are added to /etc/crontab.
0 9 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/start > /dev/null
0 18 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/pause > /dev/null
If you want to use the http remote control from your own software (for example your own PHP front end) you can set the new motion.conf option html_output off. Then Motion answers back with very basic text only and no html around it. A bit like the xmlrpc interface did.
To remote control Motion from a web pages you can for example use PHP. In PHP it takes this simple code line to send a remote commend to Motion. Here we pause motion detection for camera 2
readfile('http://localhost:8080/2/detection/pause');
What happened to XMLRPC?
XMLRPC is replaced by a simpler http remote control interface. It is still being worked on but it is absolutely useable now and much nicer to work with than xmlrpc. Another advantage is that you do not need to install xmlrpc libraries. It is all written in standard C.
![ALERT! ALERT!](https://i-blog.csdnimg.cn/blog_migrate/8165cbe962fb1e56da951b245b57644f.png)
- Anyone with access to the remote control port (http) can alter the values of any options and save files anywhere on your server with the same privileges as the user running Motion. They can execute any command on your computer 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.
- If you limit control port to localhost you still need to take care of any user logging into the server with any kind of terminal session.
- It is a good idea to run Motion as a harmless user. Not as root!!
These are the config file options that control Motion.
These must be placed in motion.conf and not in a thread config file.
control_authentication(控制的认证,可以设置用户名和密码登录的方式)
- Type: String
- Range / Valid values: Max 4096 characters
- Default: Not defined
- Option Topic
control_html_output
- Type: Boolean
- Range / Valid values: on, off
- Default: on
- Option Topic
control_localhost(本地控制)
- Type: Boolean
- Range / Valid values: on, off
- Default: on
- Option Topic
control_port(控制端口)
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0 (disabled)
- Option Topic
External Commands(外部命令的执行)
Motion can execute external commands based on the motion detection and related events. They are all described in this section. The option
quiet
is also included in this section.
![ALERT! ALERT!](https://i-blog.csdnimg.cn/blog_migrate/8165cbe962fb1e56da951b245b57644f.png)
- Anyone with access to the remote control port (http) can execute any command on your computer 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.
- If you limit control port to localhost you still need to take care of any user logging into the server with any kind of GUI or terminal session. All it takes is a browser or single command line execution to change settings in Motion.
- It is a good idea to run Motion as a harmless user. Not as root!!
These are the options
on_area_detected
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Command to be executed when motion in a predefined area is detected. Check option area_detect.
on_camera_lost(当打不开或找不到相机时执行脚本)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
It depends on the driver, some drivers dosn't detect a lost camera at all
Some hangs the motion thread. Some even hangs the PC!
on_event_end(事件结束时执行)
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Full path name of the program/script.
This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.
The command is run when an event is over. I.e. the number of seconds defined by the time 'gap' has passed since the last detection of motion and motion closes the mpeg file.
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
on_motion_detected
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Command to be executed when a motion frame is detected. You can use Conversion Specifiers and spaces as part of the command.
Do not write "none" if you do not want to execute commands. Simply do not include the option in the file or comment it out by placing a "#" or ";" as the first character on the line before the execute command.
on_movie_end
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Command to be executed when an ffmpeg movie is closed at the end of an event. You can useConversion Specifiers and spaces as part of the command. Use %f for passing filename (with full path) to the command.
说:在一个事件结束时当一个ffmpeg影片被关闭时执行其命令。
Full path name of the program/script.This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.
The command is run when an event is over. I.e. the number of seconds defined by the time 'gap' has passed since the last detection of motion and motion closes the mpeg file.
This option was previously called onffmpegclose.
on_movie_start
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Full path name of the program/script.
This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script. When you use ffmpeg the film is generated on the fly and on_movie_start then runs when the new mpeg file is created. Often you will want to use the on_movie_end option which runs when the mpeg file is closed and the event is over.
This option was previously called onmpeg.
on_picture_save
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
quiet
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Be quiet, don't output beeps when detecting motion.
Only works in non-daemon mode.
What happened to mail and sms?
The 6 new on_xxxxx options replace the former execute, mail and sms options.
They are quite generic and flexible. These small bash scripts gives to the same functionality as mail and sms BUT you have all the flexibility you want to extend the messages, change the 'from' email address etc.
Sending email at start of event(在事件开始发送邮件)
_Script written by JoergWeber _(此脚本归功于JoergWeber )
#!/bin/sh
# Motion sample script to send an e-mail at start of an event.
# Replaces the former 'mail' option.
# Just define this script as 'on_event_start'-script in motion.conf like that:
# on_event_start send_mail "%Y-%m-%d %T" (这是定义的样式,很重要)
#change to suit your needs:
#location of 'mail' binary(mail命令的二进制文件路径)
MAIL="/usr/bin/mail"
#Destination e-mail address(e-mail地址,即发给谁)
TO="root@localhost"
#Subject of the e-mail(e-mail的主题)
SUBJECT="Motion detected"
#Don't change anything below this line(不要修改此行的任何内容)
echo -e "This is an automated message generated by motion.\n\nMotion detected: $1\n\n" | $MAIL -s "$SUBJECT" $TO
Sending SMS at start of event(在时间开始时发送SMS)
_Script written by JoergWeber _(此脚本归功于JoergWeber )
If you uncomment the line
#/usr/local/bin/send_mail $1
you can combine both sending email and sms.
#/usr/local/bin/send_mail $1
这行内容注释掉,你可以同时发送email和sms。#!/bin/sh
# Motion sample script to send an sms at start of an event.
# Replaces the former 'sms' option.
# Just define this script as 'on_event_start'-script in motion.conf like that:
# on_event_start send_sms "%Y-%m-%d %T"(这是定义的样式,很重要)
#
# If you want to send an e-mail message here as well, just uncomment the last
# line of this script.
#change to suit your needs:
#location of 'sms-client' binary(二进制文件sms-client的位置)
SMS_CLIENT="/usr/bin/sms_client"
#Destination sms number(sms号码,即发给谁)
TO="12345"
#Don't change anything below this line(下行内容不要改)
$SMS_CLIENT $TO "Motion detected $1"
#/usr/local/bin/send_mail $1(如果相同时发送邮件,那么去掉注释即可)
-- KennethLavrsen - 13 Apr 2005