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

Watchdog timeout - started happening after i added audio encoding to the video file #1173

Closed MSC2016 closed 4 years ago

MSC2016 commented 4 years ago
  1. Reviewed guide and contributing documents? (Yes)
  2. version [4.2.2]
  3. installed as a package
  4. standalone
  5. video stream source [V4L - USB] (very old webcam)
  6. hardware [ARM Linksys wrt32x]]:
  7. operating system [OpenWrt 19.07.3]:

I added audio encoding to the out file via the movie_extpipe. everything worked fine when that line was: movie_extpipe ffmpeg -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -vcodec mpeg4 -f mp4 %f.mp4 (video only)

but then i added audio encoding changing extpipe as follows: movie_extpipe ffmpeg -f alsa -thread_queue_size 1024 -ac 1 -i hw:0 -y -f rawvideo -video_size %wx%h -framerate %fps -thread_queue_size 1024 -i pipe:0 -vcodec mpeg4 -f mp4 %f.mp4

It works, it starts the file when an event is triggered, it encodes audio + video but afer the event_gap + post_capture that i increased to keep the video smooth and the video/audio sync relatively close, when it is suposed to end the video file i get: motion_watchdog: Thread 1 - Watchdog timeout. Trying to do a graceful restart motion_watchdog: Thread 1 - Watchdog timeout did NOT restart, killing it!

i believe it keeps encoding audio to the file instead of stopping and closing the file.

I am new to motion and my native language is not English, sorry about possible errors. If anyone needs more information please let me know, i will post as needed.

CLI output_____:

root@OpenWrt:/etc/motion# motion
[0:Unknown] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0:Unknown] [NTC] [ALL] motion_startup: Logging to file (/mnt/S2Portable/motion/motion.log)
ffmpeg version 3.4.7 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7.5.0 (OpenWrt GCC 7.5.0 r11133-2d14da2c7d)
  configuration: --enable-cross-compile --cross-prefix=arm-openwrt-linux-muslgnueabi- --arch=arm --cpu=cortex-a9 --target-os=linux --prefix=/usr --pkg-config=pkg-config --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --disable-runtime-cpudetect --enable-lto --enable-vfp --disable-neon --disable-x86asm --enable-avresample --disable-decoder=atrac3 --disable-decoder=h264 --disable-decoder=hevc --disable-decoder=vc1 --disable-muxer=h264 --disable-muxer=hevc --disable-muxer=vc1 --disable-demuxer=h264 --disable-demuxer=hevc --disable-demuxer=vc1 --disable-parser=h264 --disable-parser=hevc --disable-parser=vc1 --enable-libopus --enable-small --enable-libmp3lame
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'hw:0':
  Duration: N/A, start: 1594781268.095926, bitrate: 768 kb/s
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Input #1, rawvideo, from 'pipe:0':
  Duration: N/A, start: 0.000000, bitrate: 55296 kb/s
    Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 55296 kb/s, 15 tbr, 15 tbn, 15 tbc
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Output #0, mp4, to '/mnt/S2Portable/motion/15072020024748.mp4':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(progressive), 640x480, q=2-31, 200 kb/s, 15 fps, 15360 tbn, 15 tbc
    Metadata:
      encoder         : Lavc57.107.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s
    Metadata:
      encoder         : Lavc57.107.100 aac
[alsa @ 0xb5c38850] Thread message queue blocking; consider raising the thread_queue_size option (current value: 1024)
[alsa @ 0xb5c38850] ALSA buffer xrun.
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:40.94 bitrate= 117.3kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:41.95 bitrate= 116.5kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:42.95 bitrate= 115.8kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:43.95 bitrate= 115.1kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:44.96 bitrate= 114.4kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:45.96 bitrate= 113.7kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:46.96 bitrate= 113.0kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:47.96 bitrate= 112.4kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:48.97 bitrate= 111.7kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:49.97 bitrate= 111.0kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:50.97 bitrate= 110.4kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:51.97 bitrate= 109.8kbits/s speed=   1x
SIGVTALRM went off q=11.9 size=    2304kB time=00:02:52.98 bitrate= 109.1kbits/s speed=   1x

AT THIS POINT I PRESSED CTRL + C

^Cframe=  923 fps=5.3 q=11.9 Lsize=    2713kB time=00:02:53.79 bitrate= 127.9kbits/s speed=   1x
video:1657kB audio:979kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.897775%
[aac @ 0xb28a90] Qavg: 247.418
Exiting normally, received signal 2.
Segmentation fault
root@OpenWrt:/etc/motion# 

LOG file_____:

[0:Unknown] [NTC] [ALL] [Jul 15 02:47:30] motion_startup: Motion 4.2.2 Started
[0:Unknown] [NTC] [ALL] [Jul 15 02:47:30] motion_startup: Using log type (ALL) log level (NTC)
[0:Unknown] [NTC] [STR] [Jul 15 02:47:30] webu_start_strm: Starting all camera streams on port 8081
[0:Unknown] [NTC] [STR] [Jul 15 02:47:30] webu_strm_ntc: Started camera 0 stream on port 8081
[0:Unknown] [NTC] [STR] [Jul 15 02:47:30] webu_start_ctrl: Starting webcontrol on port 8080
[0:Unknown] [NTC] [STR] [Jul 15 02:47:30] webu_start_ctrl: Started webcontrol on port 8080
[0:Unknown] [NTC] [ENC] [Jul 15 02:47:30] ffmpeg_global_init: No ffmpeg functionality included
[0:Unknown] [NTC] [ALL] [Jul 15 02:47:30] translate_init: Language: English
[0:Unknown] [NTC] [ALL] [Jul 15 02:47:30] motion_start_thread: Camera ID: 0 is from /etc/motion/motion.conf
[0:Unknown] [NTC] [ALL] [Jul 15 02:47:30] motion_start_thread: Camera ID: 0 Camera Name: (null) Device: /dev/video0
[0:Unknown] [NTC] [ALL] [Jul 15 02:47:30] main: Waiting for threads to finish, pid: 13007
[1:Unknown] [NTC] [ALL] [Jul 15 02:47:30] motion_init: Camera 0 started: motion detection Enabled
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] vid_start: Opening V4L2 device
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_device_open: Using videodevice /dev/video0 and input -1
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_device_capability: - VIDEO_CAPTURE
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_device_capability: - STREAMING
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_input_select: Name = "Camera 1"- CAMERA
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_norm_select: Device does not support specifying PAL/NTSC norm
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_pixfmt_set: Testing palette MJPG (640x480)
[1:Unknown] [NTC] [VID] [Jul 15 02:47:30] v4l2_pixfmt_set: Using palette MJPG (640x480)
[1:Unknown] [NTC] [ALL] [Jul 15 02:47:30] image_ring_resize: Resizing pre_capture buffer to 1 items
[1:Unknown] [NTC] [ENC] [Jul 15 02:47:48] ffmpeg_open: No ffmpeg functionality included
[1:Unknown] [ERR] [EVT] [Jul 15 02:47:48] event_ffmpeg_newfile: Error opening context for movie output.
[1:Unknown] [NTC] [ALL] [Jul 15 02:47:48] create_path: creating directory /mnt/S2Portable/motion
[1:Unknown] [NTC] [EVT] [Jul 15 02:47:48] event_create_extpipe: pipe: ffmpeg -f alsa -thread_queue_size 1024 -ac 1 -i hw:0 -y -f rawvideo -video_size 640x480 -framerate 15 -thread_queue_size 1024 -i pipe:0 -vcodec mpeg4 -f mp4 /mnt/S2Portable/motion/15072020024748.mp4
[1:Unknown] [NTC] [EVT] [Jul 15 02:47:48] event_create_extpipe: cnt->moviefps: 15
[1:Unknown] [NTC] [EVT] [Jul 15 02:47:48] event_newfile: File of type 8 saved to: /mnt/S2Portable/motion/15072020024748
[1:Unknown] [NTC] [ALL] [Jul 15 02:47:48] motion_detected: Motion detected - starting event 1
[1:Unknown] [NTC] [EVT] [Jul 15 02:49:49] event_extpipe_end: CLOSING: extpipe file desc 10, error state 0
[0:Unknown] [ERR] [ALL] [Jul 15 02:50:18] motion_watchdog: Thread 1 - Watchdog timeout. Trying to do a graceful restart
[0:Unknown] [ERR] [ALL] [Jul 15 02:50:28] motion_watchdog: Thread 1 - Watchdog timeout did NOT restart, killing it!
[1:Unknown] [NTC] [EVT] [Jul 15 02:50:41] event_extpipe_end: pclose return: -1
[1:Unknown] [NTC] [ALL] [Jul 15 02:50:41] mlp_actions: End of event 1
[1:Unknown] [NTC] [ALL] [Jul 15 02:50:41] motion_loop: Thread exiting
[1:Unknown] [NTC] [VID] [Jul 15 02:50:41] vid_close: Cleaning up V4L2 device
[1:Unknown] [NTC] [VID] [Jul 15 02:50:41] v4l2_cleanup: Closing video device /dev/video0

motion.conf file_____:

# /etc/motion/motion.conf
#
# This config file was generated by motion 4.2.2
# at 2020-07-10T11:55:45

############################################################
# System control configuration parameters
############################################################

# Start in daemon (background) mode and release terminal.
daemon off

# Start in Setup-Mode, daemon disabled.
setup_mode off

# File to store the process ID.
pid_file /var/run/motion/motion.pid

# File to write logs messages into.  If not defined stderr and syslog is used.
log_file /mnt/S2Portable/motion/motion.log

# Level of log messages [1..9] (EMG, ALR, CRT, ERR, WRN, NTC, INF, DBG, ALL).
log_level 6

# Filter to log messages by type (COR, STR, ENC, NET, DBL, EVT, TRK, VID, ALL).
log_type all

# Do not sound beeps when detecting motion
quiet on

# Native language support.
native_language on

# User defined name for the camera.
; camera_name value

# Numeric identifier for the camera.
camera_id 0

# Target directory for pictures, snapshots and movies
target_dir /mnt/S2Portable/motion

# Video device (e.g. /dev/video0) to be used for capturing.
videodevice /dev/video0

# Parameters to control video device.  See motion_guide.html
; vid_control_params value

# Preferred color palette to be used for the video device
v4l2_palette 8

# The input number to be used on the video device.
input -1

# The video norm to use for video capture and TV tuner cards.
norm 0

# The frequency to set the tuner to (kHz) for TV tuner cards
frequency 0

# The Motion method to use to change the brightness/exposure on video device.
auto_brightness 0

# Device name (e.g. /dev/tuner0) to be used for capturing when using tuner as source
; tunerdevice value

# Number of frames to capture in each roundrobin step
roundrobin_frames 1

# Number of frames to skip before each roundrobin step
roundrobin_skip 1

# Try to filter out noise generated by roundrobin
roundrobin_switchfilter off

# The full URL of the network camera stream.
; netcam_url value

# Optional high resolution URL for rtsp/rtmp cameras only.
; netcam_highres value

# Username and password for network camera. Syntax username:password
; netcam_userpass value

# The method for keep-alive of network socket for mjpeg streams.
netcam_keepalive off

# The URL to use for a netcam proxy server.
; netcam_proxy value

# Use less strict jpeg checks for network cameras.
netcam_tolerant_check off

# Use TCP transport for RTSP/RTMP connections to camera.
netcam_use_tcp on

# Name of mmal camera (e.g. vc.ril.camera for pi camera).
; mmalcam_name value

# Camera control parameters (see raspivid/raspistill tool documentation)
; mmalcam_control_params value

############################################################
# Image Processing configuration parameters
############################################################

# Image width in pixels.
width 640

# Image height in pixels.
height 480

# Maximum number of frames to be captured per second.
framerate 15

# Minimum time in seconds between capturing picture frames from the camera.
minimum_frame_time 0

# Number of degrees to rotate image.
rotate 0

# Flip image over a given axis
flip_axis none

# Draw a locate box around the moving object.
locate_motion_mode off

# Set the look and style of the locate box.
locate_motion_style box

# Text to be overlayed in the lower left corner of images
text_left CAMERA1

# Text to be overlayed in the lower right corner of images.
text_right %Y-%m-%d\n%T-%q

# Overlay number of changed pixels in upper right corner of images.
text_changes off

# Scale factor for text overlayed on images.
text_scale 2

# The special event conversion specifier %C
text_event %Y%m%d%H%M%S

############################################################
# Motion detection configuration parameters
############################################################

# Always save pictures and movies even if there was no motion.
emulate_motion off

# Threshold for number of changed pixels that triggers motion.
threshold 500

# The maximum threshold for number of changed pixels that triggers motion.
threshold_maximum 0

# Enable tuning of the threshold down if possible.
threshold_tune off

# Noise threshold for the motion detection.
noise_level 32

# Automatically tune the noise threshold
noise_tune on

# Despeckle the image using (E/e)rode or (D/d)ilate or (l)abel.
;despeckle_filter EedDl

# Area number used to trigger the on_area_detected script.
; area_detect value

# Full path and file name for motion detection mask PGM file.
; mask_file value

# Full path and file name for privacy mask PGM file.
; mask_privacy value

# The value defining how slow or fast the smart motion mask created and used.
smart_mask_speed 0

# Percentage of image that triggers a lightswitch detected.
lightswitch_percent 10

# When lightswitch is detected, ignore this many frames
lightswitch_frames 0

# Number of images that must contain motion to trigger an event.
minimum_motion_frames 1

# Gap in seconds of no motion detected that triggers the end of an event.
event_gap 60

# The number of pre-captured (buffered) pictures from before motion.
pre_capture 0

# Number of frames to capture after motion is no longer detected.
post_capture 900
############################################################
# Script execution configuration parameters
############################################################

# Command to be executed when an event starts.
on_event_start ssmtp (censored)@gmail.com < /etc/motion/mail.txt

# Command to be executed when an event ends.
; on_event_end value

# Command to be executed when a picture is saved.
; on_picture_save value

# Command to be executed when motion in a predefined area is detected
; on_area_detected value

# Command to be executed when motion is detected
; on_motion_detected value

# Command to be executed when a movie file is created.
; on_movie_start arecord -f S16_LE -r 48000 | lame --preset insane - /mnt/S2Portable/motion/%d%m%Y%H%M%S.mp3

# Command to be executed when a movie file is closed.
; on_movie_end pkill -SIGTERM -f "^lame --preset insane - /mnt/S2Portable/motion/%d%m%Y%H%M%S.mp3"

# Command to be executed when a camera can't be opened or if it is lost
; on_camera_lost value

# Command to be executed when a camera that was lost has been found.
; on_camera_found value

############################################################
# Picture output configuration parameters
############################################################

# Output pictures when motion is detected
picture_output off

# Output pictures with only the pixels moving object (ghost images)
picture_output_motion off

# Format for the output pictures.
picture_type jpeg

# The quality (in percent) to be used in the picture compression
picture_quality 100

# Text to include in a JPEG EXIF comment
; picture_exif value

# File name(without extension) for pictures relative to target directory
picture_filename %Y%m%d%H%M%S-%q

############################################################
# Snapshot output configuration parameters
############################################################

# Make automated snapshot every N seconds
snapshot_interval 0

# File name(without extension) for snapshots relative to target directory
snapshot_filename %d%m%Y%H%M%S-snapshot

############################################################
# Movie output configuration parameters
############################################################

# Create movies of motion events.
movie_output on

# Create movies of moving pixels of motion events.
movie_output_motion off

# Maximum length of movie in seconds.
movie_max_time 600

# The fixed bitrate to be used by the movie encoder. Ignore quality setting
movie_bps 500000

# The encoding quality of the movie. (0=use bitrate. 1=worst quality, 100=best)
movie_quality 100

# Container/Codec to used for the movie. See motion_guide.html
movie_codec mpeg4

# Duplicate frames to achieve "framerate" fps.
movie_duplicate_frames on

# Pass through from the camera to the movie without decode/encoding.
movie_passthrough off

# File name(without extension) for movies relative to target directory
movie_filename %d%m%Y%H%M%S

# Use pipe and external encoder for creating movies.
movie_extpipe_use on

# Full path and options for external encoder of movies from raw images
movie_extpipe ffmpeg -f alsa -thread_queue_size 1024 -ac 1 -i hw:0 -y -f rawvideo -video_size %wx%h -framerate %fps -thread_queue_size 1024 -i pipe:0 -vcodec mpeg4 -f mp4 %f.mp4

# this works        - movie_extpipe ffmpeg -f alsa -ac 1 -i hw:0 -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -vcodec mpeg4 -f mp4 %f.mp4
# this records audio    - ffmpeg -f alsa -ac 1 -i hw:0 /mnt/S2Portable/alsaout.wav

############################################################
# Timelapse output configuration parameters
############################################################

# Interval in seconds between timelapse captures.
timelapse_interval 0

# Timelapse file rollover mode. See motion_guide.html for options and uses.
timelapse_mode daily

# Frame rate for timelapse playback
timelapse_fps 15

# Container/Codec for timelapse movie.
timelapse_codec mpeg4

# File name(without extension) for timelapse movies relative to target directory
timelapse_filename %d%m%Y-timelapse

############################################################
# Loopback pipe configuration parameters
############################################################

# v4l2 loopback device to receive normal images
; video_pipe value

# v4l2 loopback device to receive motion images
; video_pipe_motion value

############################################################
# Webcontrol configuration parameters
############################################################

# Port number used for the webcontrol.
webcontrol_port 8080

# Enable IPv6 addresses.
webcontrol_ipv6 off

# Restrict webcontrol connections to the localhost.
webcontrol_localhost off

# Type of configuration options to allow via the webcontrol.
webcontrol_parms 0

# Method that webcontrol should use for interface with user.
webcontrol_interface 0

# The authentication method for the webcontrol
webcontrol_auth_method 0

# Authentication string for the webcontrol. Syntax username:password
; webcontrol_authentication value

# Use ssl / tls for the webcontrol
webcontrol_tls off

# Full path and file name of the certificate file for tls
; webcontrol_cert value

# Full path and file name of the key file for tls
; webcontrol_key value

# The cross-origin resource sharing (CORS) header for webcontrol
; webcontrol_cors_header value

############################################################
# Live stream configuration parameters
############################################################

# The port number for the live stream.
stream_port 8081

# Restrict stream connections to the localhost.
stream_localhost off

# Authentication method for live stream.
stream_auth_method 0

# The authentication string for the stream. Syntax username:password
; stream_authentication value

# Use ssl / tls for stream.
stream_tls off

# The cross-origin resource sharing (CORS) header for the stream
; stream_cors_header value

# Percentage to scale the stream image on the webcontrol.
stream_preview_scale 25

# Have the stream image start on a new line of the webcontrol
stream_preview_newline off

# Method for showing stream on webcontrol.
stream_preview_method 0

# Quality of the jpeg images produced for stream.
stream_quality 100

# Provide the stream images in black and white
stream_grey off

# Output frames at 1 fps when no motion is detected.
stream_motion off

# Maximum framerate of images provided for stream
stream_maxrate 15

# Limit the number of images per connection
stream_limit 0

############################################################
# Database and SQL Configuration parameters
############################################################

# The type of database being used if any.
; database_type value

# Database name to use. For sqlite3, the full path and name.
; database_dbname value

# The host on which the database is located
database_host localhost

# Port used by the database.
database_port 0

# User account name for database.
; database_user value

# User password for database.
; database_password value

# Database wait for unlock time
database_busy_timeout 0

# Log to the database when creating motion triggered image file
sql_log_picture off

# Log to the database when creating a snapshot image file
sql_log_snapshot off

# Log to the database when creating motion triggered movie file
sql_log_movie off

# Log to the database when creating timelapse movie file
sql_log_timelapse off

# SQL query at event start.  See motion_guide.html
; sql_query_start value

# SQL query at event stop.  See motion_guide.html
; sql_query_stop value

# SQL query string that is sent to the database.  See motion_guide.html
; sql_query value

############################################################
# Tracking configuration parameters
############################################################

# Method used by tracking camera. See motion_guide.html
track_type 0

# Enable auto tracking
track_auto off

# Serial port of motor
; track_port value

# Motor number for x-axis
track_motorx 0

# Set motorx reverse
track_motorx_reverse off

# Motor number for y-axis
track_motory 0

# Set motory reverse
track_motory_reverse off

# Maximum value on x-axis
track_maxx 0

# Minimum value on x-axis
track_minx 0

# Maximum value on y-axis
track_maxy 0

# Minimum value on y-axis
track_miny 0

# Center value on x-axis
track_homex 128

# Center value on y-axis
track_homey 128

# ID of an iomojo camera if used
track_iomojo_id 0

# Angle in degrees the camera moves per step on the X-axis with auto-track
track_step_angle_x 10

# Angle in degrees the camera moves per step on the Y-axis with auto-track.
track_step_angle_y 10

# Delay to wait for after tracking movement as number of picture frames.
track_move_wait 10

# Speed to set the motor to (stepper motor option)
track_speed 255

# Number of steps to make (stepper motor option)
track_stepsize 40

# Command to execute to move a camera in generic tracking mode
; track_generic_move value

##############################################################
# Camera config files - One for each camera.
##############################################################
; camera /etc/motion/camera1.conf
##############################################################
# Directory to read '.conf' files for cameras.
##############################################################
; camera_dir /etc/motion/conf.d
tosiara commented 4 years ago

Are you trying to capture sound from the same V4L device that is already in use by motion?

MSC2016 commented 4 years ago

Yes, and it is capturing and encoding andiu and video, the problem happens when is time to close the file and stop recording...

MSC2016 commented 4 years ago

Any more info needed?

tosiara commented 4 years ago

I doubt it is possible to use the same V4L device by two different processes. Unless you are using v4l loopback device. You can try that

MSC2016 commented 4 years ago

movie_extpipe ffmpeg -f alsa -ac 1 -i hw:0 -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -vcodec mpeg4 -f mp4 %f.mp4

The above extpipe works to record video when motion is detected, while its recording i can enter this: "ffmpeg -f alsa -ac 1 -i hw:0 /mnt/S2Portable/alsaout.wav" int the cli command line and start recording audio from the same device but to a different file with no problem, or i can have the next line also in the config file:

"on_movie_start arecord -f S16_LE -r 48000 | lame --preset insane - /mnt/S2Portable/motion/%d%m%Y%H%M%S.mp3" the above line is triggered on movie start just like the name implies and it will also record audio to a different file but its triggered automatticaly. It works.

"; on_movie_end pkill -SIGTERM -f "^lame --preset insane - /mnt/S2Portable/motion/%d%m%Y%H%M%S.mp3"" will be triggered by the movie end and kill the audio recording process when the movie ends, or at the least it should, but sometimes (most of them) it fails to stop the audio recording process, and i get a really long audio file and several video files triggered by motion events.

movie_extpipe ffmpeg -f alsa -thread_queue_size 1024 -ac 1 -i hw:0 -y -f rawvideo -video_size %wx%h -framerate %fps -thread_queue_size 1024 -i pipe:0 -vcodec mpeg4 -f mp4 %f.mp4 The above records and encodes audio and video to the same file, but is also fails to stop recording when the event ends with the Watchdog timeout error...

Like i said, the problem is the watchdog timeout when the event ends, but it works. There if proof of that in the CLI output:

Input #0, alsa, from 'hw:0': Duration: N/A, start: 1594781268.095926, bitrate: 768 kb/s Stream #0:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s Input #1, rawvideo, from 'pipe:0': Duration: N/A, start: 0.000000, bitrate: 55296 kb/s Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 55296 kb/s, 15 tbr, 15 tbn, 15 tbc Stream mapping: Stream #1:0 -> #0:0 (rawvideo (native) -> mpeg4 (native)) Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native)) Output #0, mp4, to '/mnt/S2Portable/motion/15072020024748.mp4': Metadata: encoder : Lavf57.83.100 Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(progressive), 640x480, q=2-31, 200 kb/s, 15 fps, 15360 tbn, 15 tbc Metadata: encoder : Lavc57.107.100 mpeg4 Side data: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s

tosiara commented 4 years ago

The watchdog timeout happens because the second process locks the V4L device. Try to use v4l loopback device, this should work

tosiara commented 4 years ago

Have you had a chance to try video4linux loopback?

MSC2016 commented 4 years ago

Actually no, i havent made any more attempts to fix this. I have came across references to that v4l loopback device while i was trying to fix it, but of the top my head i dont actualy know what it is or how to use it. i need to search that to try the solution you sugested, but for now that issue was pushed down on my to do list. But i will get there and i will post my results when i have them.

Something that just ocured to me now, you said in a previous post that "the second process locks the V4L device", but if i have motion daemon recording video automaticaly when it is triggered by movement in the image, i can manualy start recording audio from cli using that alsa command i posted, and kill it by pressing ctrl+c, regardless of video capture happening at the moment or not, and i have no issues starting or stopping the audio capture that way.

tosiara commented 4 years ago

I tried to reproduce your issue, but extpipe command fails:

[alsa @ 0x5638a675eb40] cannot set channel count to 1 (Invalid argument)
hw:0: Input/output error
[1:ml1:motion] [ERR] [EVT] event_extpipe_put: Error writing in pipe , state error 1: Broken pipe

Can you check that you copied the correct command?

tosiara commented 4 years ago

Ok, removed -ac 1 from you command and I'm able to reach Watchdog timeout

tosiara commented 4 years ago
#0  0x00007ffff47bf297 in __GI___libc_write (fd=10, buf=0x7fffc667b790, nbytes=1382400) at ../sysdeps/unix/sysv/linux/write.c:27
#1  0x00007ffff473a22d in _IO_new_file_write (f=0x7fffc4001290, data=0x7fffc667b790, n=1382400) at fileops.c:1203
#2  0x00007ffff473ab9f in new_do_write (to_do=<optimized out>, data=0x7fffc667b790 '\032' <repeats 16 times>, "\031\031\032\032\032\032\032\032\031\031\031\031\032\032\032\032\031\031\031\031\031\031", '\032' <repeats 12 times>, "\031\031\031\031\031\031\032\032", '\031' <repeats 28 times>, "\032\032\032\032\032\032\031\031\032\032\032\032\032\032\032\032", '\033' <repeats 15 times>, "\034\033\033\032\032\031\031\031\031", '\032' <repeats 12 times>, "\031", '\030' <repeats 11 times>, "\031\031\031\031\031\031\031\031\032\032\032\032\031\031\031\031\032\032\033\033\032\032\032\032\032\032\032\032", '\031' <repeats 12 times>, "\032\032\032\032\032\032\032\032\032\032"..., fp=0x7fffc4001290) at fileops.c:457
#3  0x00007ffff473ab9f in _IO_new_file_xsputn (f=0x7fffc4001290, data=<optimized out>, n=1382400) at fileops.c:1277
#4  0x00007ffff472e9e7 in __GI__IO_fwrite (buf=0x7fffc667b790, size=1382400, count=count@entry=1, fp=0x7fffc4001290) at iofwrite.c:39
#5  0x0000555555582d56 in event_extpipe_put (cnt=0x5555557f81f0, type=<optimized out>, img_data=0x7fffc4010910, dummy1=<optimized out>, dummy2=<optimized out>, tv1=<optimized out>) at event.c:903
#6  0x0000555555583e29 in event (cnt=0x5555557f81f0, type=EVENT_IMAGE_DETECTED, img_data=0x7fffc4010910, filename=0x0, eventdata=0x0, tv1=0x7fffc4010938) at event.c:1431
#7  0x0000555555563fff in process_image_ring (cnt=0x5555557f81f0, max_images=4294967295) at motion.c:644
#8  0x0000555555566663 in mlp_actions (cnt=0x5555557f81f0) at motion.c:2607
#9  0x0000555555566663 in motion_loop (arg=<optimized out>) at motion.c:2966
#10 0x00007ffff4aa76db in start_thread (arg=0x7fffcffff700) at pthread_create.c:463
#11 0x00007ffff47d0a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
tosiara commented 4 years ago

Motion hangs on pclose

The pclose() function waits for the associated process to terminate and returns the exit status of the command as returned by wait4()

https://github.com/Motion-Project/motion/blob/master/src/event.c#L801

tosiara commented 4 years ago

The same issue is reproducible if you use this program for extpipe:

#include<stdio.h>
#include <unistd.h>

void main()
{
    while(1)
        sleep(1000000);
}
tosiara commented 4 years ago

So, the problem is that ffmpeg keeps running even when motion has already closed the extpipe. In such case motion keeps waiting for process to exit and return its value.

tosiara commented 4 years ago

Example of ffmpeg command that keeps recording audio after the stdin is finished:

echo aaaaaaaaaaaaaaaaaaaaaaaa | ffmpeg -f alsa -i hw:0 -f rawvideo -pix_fmt yuv420p -video_size 1x1 -framerate 1 -i pipe:0 -vcodec mpeg4 -y -f mp4 /tmp/a.mp4
vadegdadeg commented 1 year ago

Greetings! Gentlemen, has anyone tried mencoder to implement this task? (recording video and sound at the same time) I have not yet figured out how to attach alsa sound to the rawvideo pipe source. Without a pipe, it turns out to be done with the usual / dev / videoX.