Save h264 streams directly to disk without any processing

Forum for questions and support relating to the 1.29.x releases only.
Locked
mattpepin
Posts: 7
Joined: Fri Mar 25, 2016 5:26 pm

Save h264 streams directly to disk without any processing

Post 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!
Toasty
Posts: 5
Joined: Mon Mar 21, 2016 12:55 pm

Re: Save h264 streams directly to disk without any processing

Post 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.
mattpepin
Posts: 7
Joined: Fri Mar 25, 2016 5:26 pm

Re: Save h264 streams directly to disk without any processing

Post 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.
mattpepin
Posts: 7
Joined: Fri Mar 25, 2016 5:26 pm

Re: Save h264 streams directly to disk without any processing

Post 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.
mattpepin
Posts: 7
Joined: Fri Mar 25, 2016 5:26 pm

Re: Save h264 streams directly to disk without any processing

Post 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.
mattpepin
Posts: 7
Joined: Fri Mar 25, 2016 5:26 pm

Re: Save h264 streams directly to disk without any processing

Post by mattpepin »

Success! I'll clean up my patches and send a pull request.
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: Save h264 streams directly to disk without any processing

Post 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.
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
mattpepin
Posts: 7
Joined: Fri Mar 25, 2016 5:26 pm

Re: Save h264 streams directly to disk without any processing

Post by mattpepin »

Yes. Maxfps has to be blank or else it doesn't work.
Locked