-
Notifications
You must be signed in to change notification settings - Fork 908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable hwaccel h264 encoding on raspberry pi #998
Enable hwaccel h264 encoding on raspberry pi #998
Conversation
Enable hardware accelerated H264 and MPEG4 video encoding on raspberry pi via libopenmax.
I'll look into this but we really need to test this thoroughly before merging it. We need to make sure things don't break when using USB cameras or netcams or anything else. |
Yes, if someone can help test this, that would be great. I have only tested this on a Pi, so very limited testing done on my end as I don't have other hardware. |
Can this method be used at motioneye (in a normal pc)? |
I don't see why it can't be used on a normal PC, as long as the PC has these libraries installed: libOMX_Core.so, libOmxCore.so |
motion prefers OMX H264 encoder, but falls back to software encoder.
The new version of motion has slightly cleaner code, attempts to apply quality settings to encoders, so I bumped ours up to the newer version and applied patches to support omx encoder. |
All this looks amazing but before we do the merge (with master) and release it, we should wait for the motion project to come up with a release (be it beta or something). Otherwise it may start raining with bug reports here on motionEyeOS and I can't possibly deal with them. |
@ccrisan Yes, wait for the latest motion release. This feature requires a lot more testing before merging, and I only have raspberry pis, only very limited testing is done. We should test this against all supported hardware, with various setup. Any volunteers? I've compiled these patches into binaries if anyone is interested in testing. |
Using your binary |
@owenthewizard Use |
I'm able to test with my Pine64 and AXIS IP cameras, and a PELCO IP camera. Would also like to see remote storage to a NAS if possible. Most of these single board's won't have the thruput to HDD to support more than 2 cameras. |
I have the PiZeroW working with this hwaccel distro but even with the settings (jasaw) suggested. I don't get the kind of high performance I had expected. With the 20fps I only get at best 15fps. That is only when I have the overclocking set to turbo. Is it a wifi issue on my network or am I missing something? |
It's the encoders they are using. Very low frame rate and recording rates. It's a fairly young endeavor so they will get better. I'm trying the AXIS companion now as it's more the level I'm used to being at.
…________________________________
From: chappy1978 <notifications@github.com>
Sent: Sunday, July 9, 2017 4:27:41 PM
To: ccrisan/motioneyeos
Cc: DruidKin; Comment
Subject: Re: [ccrisan/motioneyeos] Enable hwaccel h264 encoding on raspberry pi (#998)
I have the PiZeroW working with this hwaccel distro but even with the settings (jasaw) suggested. I don't get the kind of high performance I had expected. With the 20fps I only get at best 15fps. That is only when I have the overclocking set to turbo. Is it a wifi issue on my network or am I missing something?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#998 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AcouOIYcMUIsEG1EH3Zyuse5vNZJ7S0Aks5sMTe9gaJpZM4N6xDP>.
|
@chappy1978 What tool did you use to determine the frame rate? I'm not sure if there's a standard tool that everyone uses, but I'm using ffprobe to get the average frame rate.
The above is one sample of my recorded movie, recorded at 20 fps. The average frame rate turns out to be 21.906 fps. I noticed when there's gap in the movie (i.e. during motion gap), the average frame rate becomes very high and it's noticeable during playback (lots of movements within one second). I don't know what can be done to fix that. Also, with Pi Zero W, you shouldn't need to overclock it because it's already clocked at 1GHz by default. |
@jasaw Ive been working with the Motioneye web interface and am using a battery system so overclocking is a factor. I been testing lower Ghz settings to mAh low. Ive also been getting my frame rates from MotionEye web interface (i.e. click on the video stream and a fps pops up on the bottom left of the screen). What I have noted was that when Im streaming from port 8081 there is a marked increase in the frame rate but still not close 20fps more like 3-12 fps. |
@chappy1978 If you're going to underclock the hardware, you should watch the CPU usage, make sure you're not pegged at 100% in all scenarios. Streaming video via MotionEye web interface, plus motion detection, plus recording a movie, will load up your CPU. |
OK Ill test it out with ffprobe |
motion interfacing with ffmpeg C API proved to be unstable.
@ccrisan What are you thoughts on motion using extpipe to call ffmpeg for encoding movie using h264_omx encoder? This means when H264 output format is selected from web UI, motioneye will have to change the generated motion config file to use extpipe. Reasons for using extpipe to ffmpeg:
Should we create a new branch for testing this stuff and I can point my pull-request to this new branch? |
@ccrisan I've committed changes to motioneye in this branch so you can see what the intent is when I say use extpipe. Thoughts? Just a note: recording movie may fail with certain configuration. The fix should be merged into motion master any minute now. |
@ccrisan Keep in mind that the new motion config patch hasn't been accepted into motion master yet. Summary of motion config file change:
MotionEye changes needed:
|
@jasaw this is exactly what I needed. I'll add required support to motionEye will keep you posted. |
@jasaw I added support for h264_omx in motionEye: motioneye-project/motioneye@1744cfa. It's on a separate branch (rpi-omx). I have also created a rpi-omx branch in motionEyeOS and updated this PR accordingly. I'll make sure to fix any conflicts and no-longer-necessary changes before merging it. |
@jasaw I hope you don't mind that I went my way with implementing the preferred codec support in motionEye. Instead of adding a separate UI setting for this purpose, I thought it would be best to have separate movie format options for both accelerated and normal methods. If the accel one causes troubles to a user, they can simply change it to the old one. The codec is also used by the timelapse command and is chosen by default on platforms that support it. There's a new |
@jasaw it seems my |
@ccrisan No worries regarding the motionEye preferred_codec implementation. My motionEye patch was more of an example of how it may be implemented. You're the best person to implement motionEye side of things. :-) Let me know when |
@ccrisan Please delete package/motion/temp-fix-for-extpipe-subdir-creation.patch (provided you bump the motion version to latest master). |
@jasaw the obsolete patch has been removed, motion has been updated to latest master commit and motionEye ffmpeg codec detection has been fixed. The rpi-omx branch can be compiled and tested. I compiled myself the OS and ran some tests. While the CPU usage was significantly lower than in software encoding mode, the video quality was horrible. Is there some issue with quality passing from motion to libav? I tested using the defaults provided by motionEye (75%). |
@ccrisan To control video quality, h264_omx takes bit_rate rather than CRF, which is covered by this patch file: package/motion/tune-h264-encode-quality.patch. You'll get horrible blocky video without this patch. Can you please check the buildroot output/raspberrypi/build/motion-d23e263490a54329329b64883f1860ada5e5920b/.applied_patches_list file to make sure it's already patched? |
Yes, the patch is there:
|
What is your generated thread-1.conf file? It should have this:
I'll try to compile and test the latest rpi-omx branch tomorrow when I get some free time, see whether I can reproduce the problem. Just FYI, h264_omx bit_rate works like this: |
I read your patch and it makes sense. However I'm puzzled by the fact that the same codec (h264) has different quality config requirements for different encoders. P.S. yes, that's the way my thread-1.conf looks like. |
@ccrisan The latest rpi-omx appears to suffer from performance issue where frame rate is lower than what I've tested. I haven't worked out which software introduced this. Another thing, rpi-omx branch motionEye UI is greyed out after I log in as admin. I've been modifying thread-1.conf file by hand to test. |
|
I dont know motion-ab9e800d5984f2907f00bebabc794d1dba9682ad is which release version of motion, 4.0.1 or not. We can fallback to motion-ab9e800d5984f2907f00bebabc794d1dba9682ad since that's the version that I know works. You'll also need to restore back the extpipe patch. I'll test rpi-omx branch with motion-ab9e800d5984f2907f00bebabc794d1dba9682ad tomorrow to verify that it's the latest motion issue. I'll also try clearing my browser cache. |
@ccrisan It's not motion software that is causing the performance issue. I ran motion-ab9e800d5984f2907f00bebabc794d1dba9682ad on rpi-omx branch and get the same performance issue. |
Rolling rpi-userland version back to cdb5da59f939eb4078e90ed0e3c231c498ba9957 seems to fix the performance issue. Next is to find out the offending commit from rpi-userland. |
I've rolled rpi-userland version back to 9aab1498b531b50585b206232d6baea64c0789f7, and it's still OK. Haven't tried later commits. |
Is the performance issue present on 20170827? It uses the most recent rpi-userland commit as of the time of writing. |
I haven't tested 20170827. I'll investigate a bit more first before I try 20170827. Will keep you updated. |
@ccrisan I can't reproduce the performance issue anymore. I'm happy with it in its current state. Have you done any testing? |
@jasaw by "anymore" do you mean that 20170827 doesn't suffer from the performance issue? Or did you find a fix for the rpi-omx branch? |
@ccrisan I couldn't find the problem, and repeated my steps to reproduced the problem but couldn't reproduce the problem. It may very well be my fault when I edit the thread-1.conf by hand. |
@jasaw I'll be busy the next week with other stuff but I'll run more thorough tests afterwards and get back to you. I think we're getting close to a merge. |
@jasaw I have run some more detailed tests on the current rpi-omx and I have good news:
In conclusion, things are looking great and I must say your work here is amazing. I have yet to run some tests with a regular USB camera and a network camera. I'd also like to run these tests on a 1st generation RPi. |
Enable hardware accelerated H264 and MPEG4 video encoding on raspberry
pi via libopenmax.
Description:
This is my first attempt at enabling hwaccel properly. Any feedback welcomed.