Closed MSC2016 closed 4 years ago
Are you trying to capture sound from the same V4L device that is already in use by motion?
Yes, and it is capturing and encoding andiu and video, the problem happens when is time to close the file and stop recording...
Any more info needed?
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
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
The watchdog timeout happens because the second process locks the V4L device. Try to use v4l loopback device, this should work
Have you had a chance to try video4linux loopback?
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.
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?
Ok, removed -ac 1
from you command and I'm able to reach Watchdog timeout
#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
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
The same issue is reproducible if you use this program for extpipe:
#include<stdio.h>
#include <unistd.h>
void main()
{
while(1)
sleep(1000000);
}
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.
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
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.
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_____:
AT THIS POINT I PRESSED CTRL + C
LOG file_____:
motion.conf file_____: