Page 1 of 1
Save h264 streams directly to disk without any processing
Posted: Fri Mar 25, 2016 5:38 pm
by mattpepin
I'm using the latest git/feature-h264-videostorage version. If I use a ffmpeg camera and enable H264 passthrough recording and use a record monitor, each full-hd stream consumes about 50% CPU. If I save it myself using ffmpeg with this:
ffmpeg -i rtsp://mycam -vcodec copy -acodec copy a.mp4
I get 1-2% CPU usage for the 1080p 25 fps stream.
The thing is, I only want the video for archives. I'd like to have 10 minutes videos with events for each 10-minute period, but I don't need live video (which is what consumes CPU cycles, I assume). I think Zoneminder generates JPEG images from my stream to be able to display it. Is there a way to turn that off and only record the stream (real passthrough)?
I use the second stream of my camera for live video, at a lower resolution/FPS.
Thanks!
Re: Save h264 streams directly to disk without any processing
Posted: Sat Mar 26, 2016 1:12 am
by Toasty
I've been looking for the same thing. I've got 50 cameras to monitor, which when using Zoneminder is impossible due to the high CPU usage (about %25-%35 per stream, which limits me to about 24 or so cameras with my 8 threads). Not to mention I get smearing with ffmpeg pretty bad in web interface (though I haven't found anything in the video files yet).
I also noticed that when viewing the live stream in the web interface, it's actually just an image embedded with the <img> tag whose source is "/zm/cgi-bin/nph-zms?mode=jpeg&scale=100&[additional parameters here]". So Zoneminder is definitely wasting cycles generating images.
Re: Save h264 streams directly to disk without any processing
Posted: Sat Mar 26, 2016 2:48 am
by mattpepin
I'm playing with the source right now. I'm trying to figure out a simple way to disconnect the JPEG image generation. I'll report back.
Re: Save h264 streams directly to disk without any processing
Posted: Sat Mar 26, 2016 3:00 pm
by mattpepin
OK, I did not succeed yet but here's what I tried before playing with the source code.
First, I tried reducing maxfps. It reduced CPU usage but it caused my TCP streams to disconnect every 30s-1min30. I guess the TCP buffer was filling up. It doesn't happen when maxfps is empty. It worked but all my events had a random duration and the videos were short. So I tried switching to UDP. I stopped the disconnects, but now the videos were garbled and played incorrectly (even the JPG preview has problems). I played with various settings (buffer_size, fifo_size, kernel sysconfs) but it didn't help.
So I looked at the code and I saw that frames are always decoded in zm_ffmpeg_camera.cpp. I tried to remove that logic but since no frames are produced, a bunch of other changes are required in zm_monitor.cpp. I'm still figuring it out. Now I get events but no video is recorded. I get this in my log, but nothing after:
Opening new event 1380, section start
I'll keep editing until I make it work and I'll push my branch on github.
Re: Save h264 streams directly to disk without any processing
Posted: Sun Mar 27, 2016 1:13 pm
by mattpepin
Update: It almost works. No analysis is done and videos are saved. It only uses about 1-2% CPU. However, videos recorded this way are corrupt. They play fine and the duration is good, but only keyframes are shown properly. I can only see about the top third of other frames, the rest is blue.
Re: Save h264 streams directly to disk without any processing
Posted: Mon Mar 28, 2016 3:10 am
by mattpepin
Success! I'll clean up my patches and send a pull request.
Re: Save h264 streams directly to disk without any processing
Posted: Mon Mar 28, 2016 9:59 am
by SteveGilvarry
Hopefully you moved away from maxfps as that doesn't work for IP cameras. I have been focusing on keyframe buffer when I get time on the code as I am reliably missing 15 seconds from the start of every video.
Re: Save h264 streams directly to disk without any processing
Posted: Mon Mar 28, 2016 1:00 pm
by mattpepin
Yes. Maxfps has to be blank or else it doesn't work.
Re: Save h264 streams directly to disk without any processing
Posted: Mon Mar 28, 2016 1:46 pm
by mattpepin