Motion - Support Question 2006x 06x 19x 174238

Need some timelapse setup help


I recently installed motion v3.2.6 on a Fedora Core 4 system (kernel version 2.6.16-1.2111_FC4) and am having trouble creating a timelapse movie. I compiled motion with ffmpeg and mysql support.

I have run the program in "motion capture mode" and it detects my network camera and creates JPEGs when motion is detected but now I just want to create a series of timelapses movie with one frame every 10 seconds and a new move created hourly. I have set ffmpeg_timelapse to 10 and ffmpeg_timelapse_mode to hourly yet no movie files are created and no error messages are produced. Is there some other config parameter that I am neglecting to set? (config file attached below)

Configure settings:
./configure --build=i686-redhat-linux-gnu --host=i686-redhat-linux-gnu --target=i686-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc/motion --prefix=/usr --without-pgsql --with-ffmpeg --with-mysql --without-libjpeg-mmx

daemon on
setup_mode off
;videodevice /dev/video0
; tunerdevice /dev/tuner0
input 8
norm 0
frequency 0
rotate 0
width 352
height 240
framerate 10
netcam_userpass xxxx:yyyy
; netcam_proxy value
auto_brightness off
brightness 0
contrast 0
saturation 0
hue 0
roundrobin_frames 1
roundrobin_skip 1
switchfilter off
threshold 1500
threshold_tune off
noise_level 32
noise_tune on
night_compensate off
despeckle EedDl
; mask_file value
smart_mask_speed 0
lightswitch 0
minimum_motion_frames 1
pre_capture 0
post_capture 0
gap 60
minimum_gap 0
max_mpeg_time 0
low_cpu 0
output_all off
output_normal off
output_motion off
quality 75
ppm off
ffmpeg_cap_new on
ffmpeg_cap_motion off
ffmpeg_timelapse 10
ffmpeg_timelapse_mode hourly
ffmpeg_bps 500000
ffmpeg_variable_bitrate 0
ffmpeg_video_codec mpeg4
ffmpeg_deinterlace off
snapshot_interval 0
locate off
text_right %Y-%m-%d\n%T-%q
; text_left CAMERA %t
text_changes off
text_event %Y%m%d%H%M%S
text_double off
target_dir /var/tmp/movie2
snapshot_filename %v-%Y%m%d%H%M%S-snapshot
jpeg_filename %v-%Y%m%d%H%M%S-%q
movie_filename %v-%Y%m%d%H%M%S
timelapse_filename %Y%m%d-timelapse
webcam_port 0
webcam_quality 50
webcam_motion off
webcam_maxrate 1
webcam_localhost on
webcam_limit 0
control_port 0
control_localhost on
control_html_output on
; control_authentication username:password
track_type 0
track_auto off
; track_port value
track_motorx -1
track_motory -1
track_maxx 0
track_maxy 0
track_iomojo_id 0
track_step_angle_x 10
track_step_angle_y 10
track_move_wait 10
track_speed 255
track_stepsize 40
quiet on
; on_event_start value
; on_event_end value
; on_picture_save value
; on_motion_detected value
; on_movie_start value
; on_movie_end value
sql_log_image off
sql_log_snapshot off
sql_log_mpeg off
sql_log_timelapse off
sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')
; mysql_db value
; mysql_host value
; mysql_user value
; mysql_password value
; pgsql_db value
; pgsql_host value
; pgsql_user value
; pgsql_password value
; pgsql_port 5432
; video_pipe value
; motion_video_pipe value
; thread /usr/local/etc/thread1.conf
; thread /usr/local/etc/thread2.conf
; thread /usr/local/etc/thread3.conf
; thread /usr/local/etc/thread4.conf


Motion version: 3.2.6
ffmpeg version: 0.4.9
Libraries: ffmpeg, mysql
Server OS: FC4, kernel 2.6.16-1.2111_FC4

-- MikeKenney - 19 Jun 2006


Looking at your config and the fact that you have have no errors my guess is that Motion does create timelapse movies.

You have a config parameter timelapse_filename %Y%m%d-timelapse and that means that today the filename would be 20060619-timelapse.mpg.

But since you have an hourly schedule you need the hour to be part of the filename. Otherwise Motion will overwrite the previous file all the time until the date changes.

Try with %Y%m%d%H-timelapse

-- KennethLavrsen - 19 Jun 2006


Aarrg, dumb mistake which I have now corrected. However, there was no timelapse file created/overwritten. I'll see what happens over the next hour.

Is the timelapse file created right away and then appended to?

-- MikeKenney - 19 Jun 2006

I found the source of the problem. Using lsof, I discovered that motion is writing to the file /.mpg. This is despite the fact that I have specified target_dir and timelapse_filename. Any idea what might be causing this? Do I need to have a trailing / on the target_dir value?...

-- MikeKenney - 19 Jun 2006

If you get a .mpg file then the reason is nornally that the ffmpeg version does not match the motion version. The API changed several times so Motion must be compiled with the same version of ffmpeg that you have installed.

-- KennethLavrsen - 19 Jun 2006

I did build the RPM on this system with ffmpeg 0.4.9 installed. Has motion been tested with ffmpeg 0.4.9? Should I try reverting to an older version (of ffmpeg)?

-- MikeKenney - 19 Jun 2006

I just ran motion under gdb and set a breakpoint at event_ffmpeg_timelapse and then stepped through the function. It appears that cnt->timelapsefilename is getting overwritten somewhere in the call to ffmpeg_open. Below is the gdb session:

Breakpoint 1, event_ffmpeg_timelapse (cnt=0x8e51018, type=32,
    img=0x8e5f760 "��\023", dummy1=0x0, dummy2=0x0, currenttime_tm=0x8e559d0)
    at event.c:407
407             int width = cnt->imgs.width;
(gdb) next
408             int height = cnt->imgs.height;
(gdb) next
411             if (!cnt->ffmpeg_timelapse) {
(gdb) next
417                     if (cnt->conf.timepath)
(gdb) next
422                     mystrftime(cnt, tmp, sizeof(tmp), timepath, currenttime_tm, NULL, 0);
(gdb) next
423                     sprintf(cnt->timelapsefilename, "%s/%s", cnt->conf.filepath, tmp);
(gdb) next
425                     if (cnt->imgs.type == VIDEO_PALETTE_GREY) {
(gdb) print cnt->timelapsefilename
$1 = "/var/tmp/movie2/2006061914-timelapse", '\0' <repeats 4059 times>
(gdb) next
434                             u = img+width*height;
(gdb) next
435                             v = u+(width*height)/4;
(gdb) next
438                     if ( (cnt->ffmpeg_timelapse =
(gdb) next
447                     cnt->ffmpeg_timelapse->udata = convbuf;
(gdb) print cnt->timelapsefilename
$2 = ".mpg\000tmp/movie2/2006061914-timelapse", '\0' <repeats 4059 times>

-- MikeKenney - 19 Jun 2006

Problem solved, (simple) patch below, you will probably want to add some error checking. It appears that using the same buffer as sprintf source and destination is a bad idea.

diff -ur motion-3.2.6.dist/ffmpeg.c motion-3.2.6/ffmpeg.c
--- motion-3.2.6.dist/ffmpeg.c  2006-03-22 23:17:44.000000000 -0800
+++ motion-3.2.6/ffmpeg.c       2006-06-19 14:39:04.000000000 -0700
@@ -149,6 +149,7 @@
 static AVOutputFormat *get_oformat(const char *codec, char *filename)
        const char *ext;
+        char *tmpfilename;
        AVOutputFormat *of = NULL;

        /* Here, we use guess_format to automatically setup the codec information.
@@ -196,7 +197,9 @@

        /* WARNING: potential buffer overflow */
-       sprintf(filename, "%s.%s", filename, ext);
+       tmpfilename = strdup(filename);
+       sprintf(filename, "%s.%s", tmpfilename, ext);
+       free(tmpfilename);
        return of;

-- MikeKenney - 19 Jun 2006

Thanks for the patch.

I asked in #c on freenode IRC and I was told that sprintf(var1, "%s.%s", var1, var2) may indeed be insecure. It must be a coincidense that it often was connected with which ffmpeg version you had. Maybe the fact that people recompiled Motion with the ffmpeg that had fixed things. Or it is the linking that makes the variable be placed differently.

I will not use your patch directly. But I will do something similar but without the overhead of reserving extra memory and free it.

And at the same time get some sprintf's changed to snprintf so we cannot get buffer overflows.

-- KennethLavrsen - 20 Jun 2006


SVN 86 - MotionDailySourceSnap motion-20060620-215157.tar.gz

-- KennethLavrsen - 20 Jun 2006

Fix in 3.2.7

-- KennethLavrsen - 20 Oct 2006
Topic revision: r8 - 20 Oct 2006, KennethLavrsen
Copyright © 1999-2019 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.