Motion-Project / motion

Motion, a software motion detector. Home page: https://motion-project.github.io/
GNU General Public License v2.0
3.67k stars 549 forks source link

Odd video results using "use_extpipe" w/ffmpeg #277

Closed gaenserich closed 7 years ago

gaenserich commented 7 years ago

I get some rather odd results when producing video from a webcam via extpipe. Compare the "best" jpg snapshot:

best

with the screenshot of the video (video.jpg):

video (The video has a yellow overlay over the top half, and the corners of the image don't match that of the original frame.)

This happens most of the time, except occassionally in very high light times of day. I have tried fiddling a little bit with the pixel format setting in ffmpeg (changing "-pix_fmt yuv420p" to "-pix_fmt yuvj420p"), but the problem remains.

This issue does not appear when using the integrated ffmpeg encoding options.

I'm running Arch Linux Arm on a Raspberry Pi2 uname -a: Linux myhostname 4.4.38-1-ARCH #1 SMP Thu Dec 15 18:42:01 MST 2016 armv7l GNU/Linux

ffmpeg -version:

ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.2.1 (GCC) 20160830
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-netcdf --enable-shared --enable-version3 --enable-x11grab --host-cflags='"-fPIC"'
libavutil      55. 34.100 / 55. 34.100
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.100 / 57. 56.100
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libavresample   3.  1.  0 /  3.  1.  0
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

motion: Version 4.0.1

/etc/motion/motion.conf:

daemon off
process_id_file /run/motion/motion.pid
log_level 4
output_pictures best
quality 100
picture_type jpeg
use_extpipe on
extpipe ffmpeg -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -c:v libx264 -preset ultrafast -f mp4 %f.mp4
text_right %Y-%m-%d\n%T-%q
text_event %Y-%m-%d_%H.%M.%S-%v
exif_text %i%J/%K%L
picture_filename %v/%Y-%m-%d_%H.%M.%S-%q-%v
movie_filename %v/%Y-%m-%d_%H.%M.%S-%v
quiet on
camera_dir /etc/motion/conf.d

with one single camera in /etc/motion/conf.d/camera1.conf

camera_id 1
camera_name camera1
power_line_frequency -1
width 800
height 480
framerate 10
netcam_url http://[lan.ip.of.camera]/video
netcam_keepalive on
auto_brightness on
brightness 128
threshold 2000
threshold_tune on
noise_tune on
despeckle_filter EedDl
area_detect 269
smart_mask_speed 3
lightswitch 60
minimum_motion_frames 4
event_gap 5
locate_motion_mode on
on_event_start /etc/systemd/scripts/motion/event-start.sh "camera1" "%t" "%Y-%m-%d %H:%M:%S" "%v" "%q" "%D @ %N" "%i x %J" "%K / %L"
on_event_end /etc/systemd/scripts/motion/event-end.sh "camera1" "%t" "%Y-%m-%d %H:%M:%S" "%v" "%q" "%D @ %N" "%i x %J" "%K / %L"
target_dir /tmp/motion/camera1

Also $ ffprobe http://[lan.ip.of.camera]/video

Input #0, mpjpeg, from 'http://[lan.ip.of.camera]/video':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 800x480 [SAR 1:1 DAR 5:3], 25 tbr, 25 tbn, 25 tbc
tosiara commented 7 years ago

Can you also paste a snip of log to see few events with ext pipe?

tosiara commented 7 years ago

And would it be possible also to get two test movies: good and bad?

gaenserich commented 7 years ago

Sure thing. Here's a "good" video using the integrated ffmpeg features:

2016-12-29_09.48.50-03.mp4.zip

And here is the "bad" video using extpipe and ffmpeg: 2016-12-29_11.37.16-40.mp4.zip

Mr-DaveDev commented 7 years ago

Can you also try moving the pipe options out of the main motion.conf and put them instead into the camera1.conf and remove the on_event_end

gaenserich commented 7 years ago

Here are the logs. For around the "good" video:


Dec 29 09:48:51 raspberrypi sudo[31689]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 29 09:48:51 raspberrypi sudo[31703]:   motion : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/msmtpq -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications]
Dec 29 09:48:51 raspberrypi sudo[31703]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 29 09:48:53 raspberrypi motion[23958]:   mail for [ -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications] ] : send was successful
Dec 29 09:48:53 raspberrypi sudo[31703]: pam_unix(sudo:session): session closed for user root
Dec 29 09:48:56 raspberrypi sudo[31689]: pam_unix(sudo:session): session closed for user root
Dec 29 09:49:02 raspberrypi motion[23958]: 2016-12-29_09.48.55-01-03.jpg 800x480 24bit N Exif JFIF  [OK] 292141 --> 277443 bytes (5.03%), optimized.
Dec 29 09:49:02 raspberrypi sudo[31745]:   motion : TTY=unknown ; PWD=/tmp/motion/camera1/03 ; USER=root ; COMMAND=/usr/bin/msmtpq -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications] 
Dec 29 09:49:02 raspberrypi sudo[31745]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 29 09:49:05 raspberrypi motion[23958]:   mail for [ -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications]  ] : send was successful
Dec 29 09:49:05 raspberrypi sudo[31745]: pam_unix(sudo:session): session closed for user root
Dec 29 10:19:19 raspberrypi motion[23958]: [1:nc1:camera1] [ALR] [NET] netcam_handler_loop: netcam camera handler: finish set, exiting

And the "bad" video:

Dec 29 11:36:01 raspberrypi motion[32693]:   mail for [ -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications]  ] : send was successful
Dec 29 11:37:16 raspberrypi motion[32693]: [1:ml1:camera1] [ERR] [EVT] event_extpipe_put: Error writing in pipe , state error 1: Interrupted system call
Dec 29 11:37:16 raspberrypi sudo[6472]:   
Dec 29 11:37:16 raspberrypi sudo[6472]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 29 11:37:17 raspberrypi sudo[6476]:   motion : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/msmtpq -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications]
Dec 29 11:37:17 raspberrypi sudo[6476]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 29 11:37:19 raspberrypi motion[32693]:   mail for [ -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications] ] : send was successful
Dec 29 11:37:19 raspberrypi sudo[6476]: pam_unix(sudo:session): session closed for user root
Dec 29 11:37:32 raspberrypi motion[32693]: 2016-12-29_11.37.17-00-40.jpg 800x480 24bit N Exif JFIF  [OK] 325737 --> 307412 bytes (5.63%), optimized.
Dec 29 11:37:32 raspberrypi sudo[6550]:   motion : TTY=unknown ; PWD=/tmp/motion/camera1/40 ; USER=root ; COMMAND=/usr/bin/msmtpq -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications] 
Dec 29 11:37:32 raspberrypi sudo[6550]: pam_unix(sudo:session): session opened for user root by (uid=0)
Dec 29 11:37:35 raspberrypi motion[32693]:   mail for [ -C /etc/msmtprc -- [email-address-where-i-get-motion-notifications]  ] : send was successful
Dec 29 11:37:35 raspberrypi sudo[6550]: pam_unix(sudo:session): session closed for user root
gaenserich commented 7 years ago

Interesting. Since pushing the extpipe command out to camera1.conf, no odd videos have been produced yet. I'll check back in if a bad one ever does.

gaenserich commented 7 years ago

The odd output is back even with the extpipe parameters in camera1.conf. As above, the bad video coincides with this log message:

[ERR] [EVT] event_extpipe_put: Error writing in pipe , state error 1: Interrupted system call
Mr-Dave commented 7 years ago

Is the activity that occurs with the on_event_end doing something with the file? Moving it/deleting it / claiming ownership to it etc?

gaenserich commented 7 years ago

Yes, moving it from tmpfs to disk. Do events perhaps behave obstensively differently with extpipe options vs ffmpeg or jpeg built-ins, e.g. they issue the end script without having necessarily finished writing?

Am 29.12.2016 22:06 schrieb "Mr-Dave" notifications@github.com:

Is the activity that occurs with the on_event_end doing something with the file? Moving it/deleting it / claiming ownership to it etc?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Motion-Project/motion/issues/277#issuecomment-269726482, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHnoygnmOGcTWb2ObaytRYUFt2kXDEUks5rNHUqgaJpZM4LUjca .

Mr-Dave commented 7 years ago

The process is the same for extpipe as the internal encoder. Since something seems to be triggering the system interrupt, it may be worth looking into the script. You can also try using the on_movie_end with the %f parameter to make sure you are only working with the newly created file rather than a subsequent one that is in the process of being created.

tosiara commented 7 years ago

@gaenserich can you check if the issue is related to scripts?

tosiara commented 7 years ago

@gaenserich do you have an update for this issue?