ffmpeg remove parts without motion

15

8

I have an IP security camera (192.168.0.8) which able to broadcast rtsp content over network.

I'm able to save that (RAW) content without changes using next ffmpeg command from my computer:

ffmpeg -i "rtsp://192.168.0.8/stream=0.sdp" -acodec copy -vcodec copy test-raw.mp4

I'm also able to resize it on the fly:

ffmpeg -i "rtsp://192.168.0.8/stream=0.sdp" -vf  "scale=640:-1" test640.mp4

But how to save only that video which contains motion detection parts only?

I tried to get it solved using ffmpeg's scene change filters, but no luck.

My goal - to have common video monitoring solution, which detects when someone is moving near the camera and save it into the video file. I understand that it might be not possible to do it on the fly from stream, so it is OK for me to save big file firstly, then process it with another ffmpeg command and generate new video file which contains only motion detected parts. If you can give me advice what exactly should I research more, I will be really thankful.

My camera stream is transmitted without sound. So, I can generate set of images from original video, then pick proper images and then save new video from images.

rfedorov

Posted 2015-10-10T17:56:50.540

Reputation: 151

Do you want to implement this system or find a ready to use product? – Woeitg – 2015-11-30T10:54:07.427

@WOEITG I just need any free working solution for Ubuntu 15.04+ – rfedorov – 2015-12-02T16:46:47.053

For Windows, there's a piece of software called ispy, which you can set to record on motion detection. Since you're requesting a Linux solution, http://www.zoneminder.com/ should be a similar product. Unfortunately I don't have a direct answer to your question, but +1 because I'd like an answer too

– MyNameWouldGoHere – 2016-01-04T14:15:37.900

Answers

7

What I'd do, is do exactly like you said, and save a big file of the stream, then use the select FFMPEG filter with the scene expression, that compares the similarity of consecutive frames: select=gt(scene\,0.003) for instance. The higher the number, the more change between frames is ignored, in quick testing you might need to go as low as 0.00001-0.00005 depending on the kind of footage you're dealing with.

Combine that with the setpts filter, that modifies the "start time" of video frames, and you'd end up with something like (for a 25fps video):

ffmpeg -i input.mp4 -vf "select=gt(scene\,0.003),setpts=N/(25*TB)" output.mp4

Mind you, you won't be able to use -vcodec copy when you use video filters.

shinmai

Posted 2015-10-10T17:56:50.540

Reputation: 71