5

I am writing a webcam recording application using VLCj API. I need some help regarding motion detection in the video stream from the webcam. If there is no motion detected in the video stream, then recording shall stop.

I have tried to use the --video-filter=motion in sout chain but that didn't detected any motion.

My sout chain:

String[] options = {
                    ":sout=#transcode{vcodec=mp2v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display,select=noaudio,video-filter=motion} --video-filter=motion",":input-slave=alsa://hw:0,0"  };

Looking forward to your response. Thanks in advance.

skaffman
  • 381,978
  • 94
  • 789
  • 754
iltaf khalid
  • 8,740
  • 4
  • 27
  • 31

1 Answers1

3

You pass the VLC command option string array incorrectly; it should be as in following example (each VLC command option should treated as an array element):

String[] options = {
    ":rtsp-mcast", 
    ":sharpen-sigma=2.0", 
    ":video-filter=motion",
    ":blur-factor=127", 
    ":ipv4-timeout=3000", 
    ":no-video-title-show", 
    ":loop", 
    ":sout-all",
    ":sout-keep"
};

The option string below won't work since two VLC commands are included together into one String; the :sout command and the --video-filter=motion command:

":sout=#transcode{vcodec=mp2v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display,select=noaudio,video-filter=motion} --video-filter=motion"

It should be as follows:

":sout=#transcode{vcodec=mp2v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display,select=noaudio,video-filter=motion}",
"--video-filter=motion"
ecle
  • 3,761
  • 1
  • 15
  • 20
  • Thank you for the reply. I tried it but it is not working for me. Now the the stream is not even saved to a file. I hope you had read what I am trying to create a cross-platform VLCj app that will record from webcam and stop recording when there is not motion detected in the video. – iltaf khalid Mar 15 '12 at 12:05
  • @iltafkhalid Strange... it does work for me using VLCJ 1.2.0 and libVLC 1.1.11. I see motion detection boxes in a video played using VLCJ `playMedia(mrl, options)` method with `:video-filter=motion` option included. – ecle Mar 15 '12 at 12:29
  • @iltafkhalid The sample code above is just my example. You need to adapt it according to you requirement which should include your `:sout` option for it to work – ecle Mar 15 '12 at 12:31
  • Does your recording stops when there is not motion in the video and is there a way to remove the rectangle ? I am using VLCj 2.0 – iltaf khalid Mar 15 '12 at 13:26
  • @iltafkhalid Yes, it does not show up when there is no motion. Why do you need to activate the motion filter in your recorded video? – ecle Mar 15 '12 at 14:34
  • I tried the sout chain as it is but still it didnt work. Can you please share your code with me, all of it ? – iltaf khalid Mar 15 '12 at 16:24
  • Its an assignment to develop a webcam application which will record only where there is motion in video and stop where there is not motion like 5 sec or any time give for timeout of no motion in the video stream. – iltaf khalid Mar 15 '12 at 16:56
  • I think motion filter will not show up in a recorded video; it only appears on the playback video in display. – ee. Mar 16 '12 at 00:04
  • but recording does not stop even if i let the recording play for 1 minute. Can I configure a time when to stop recording if there is no motion detected in the stream, like can say stop recording after 5 seconds if there is no motion ? – iltaf khalid Mar 16 '12 at 04:58
  • Can you please share your code here as that would make things easier ? – iltaf khalid Mar 16 '12 at 05:24
  • I am able to detect motion with vlc on command line with the following command : 'code' vlc --video-filter=motiondetect a.mpg 'code' or 'code' vlc --video-filter=motion a.mpg 'code' ....................... but the same doesnt work when I try this with VLCj programmatically as explained above. – iltaf khalid Mar 20 '12 at 06:59
  • At last it worked. I had to remove all the libVLC arguments that I was passing and only left : vlcArgs.add("--video-filter=motiondetect"); – iltaf khalid Mar 20 '12 at 10:58
  • But there is one problem, the video recording doesn't stop when there is no motion. I want the video to stop when there is no motion. Please help. – iltaf khalid Mar 21 '12 at 08:16
  • I finally developed the solution to stop video recording when there is no motion. I got an image comparison at [link](http://mindmeat.blogspot.com/2008/07/java-image-comparison.html) and created a thread. But this time I didn't used VLCj mediaplayer rather used DirectMediaPlayer which gave me access to video buffer and hence frames. – iltaf khalid Mar 30 '12 at 14:06