As almost no browsers support native H265 (https://caniuse.com/hevc) i am unable to view H265 stored camera footage via zm web interface (from events). I am currently re-encoding my footage to H264 as that is supported in my browsers (firefox, chromium) but it takes more disk space.
All browsers support AV1 (https://caniuse.com/av1), and therefore i would like to encode my stored camera footage as AV1 instead so that i can view that via zm web interface while keeping disk usage low.
Seeing as zm already has support for multiple encoders i assume this would not be too difficult to add and i am willing to do the work myself but i would need some pointers for where to look in the zoneminder code. Ffmpeg supports AV1 via libsvtav1.
It looks like i need to add a line for AV1 to VideoStore::codec_data in https://github.com/ZoneMinder/zoneminde ... ostore.cpp. with:
"{ AV_CODEC_ID_AV1, "av1", "libsvtav1", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },"
I think i also need to add it to web/skins/classic/views/monitor.php videowriter_codecs array with value 226 for AV_CODEC_ID_AV1 if i am counting right, and libsvtav1 to videowriter_encoders. And the graying out code in web/skins/classic/views/js/monitor.js for encoder_dropdown line 180.
Is there anything else that would need more changes too? It looked to me like event playback just gave a raw copy of the file to the browser but maybe i missed something.
Support storage encoding AV1
Re: Support storage encoding AV1
That about covers it.
Please note that my ubuntu impish system ffmpeg 4.4 has libaom-av1 as the encoder.
Please note that my ubuntu impish system ffmpeg 4.4 has libaom-av1 as the encoder.
Re: Support storage encoding AV1
Good to know i did not miss anything.
libsvtav1 is faster than libaom-av1 but it seems like libsvtav1 is broken in ffmpeg 4.4.1 so i might use libaom-av1 too. After compiling ffmpeg 5.0 from source they seem to have fixed it but they did some minor changes to the api http://git.videolan.org/?p=ffmpeg.git;a ... 37863e2b46 so now zoneminder does not compile until i fix that too.
-edit-
Yeah no they changed more than just const-ness of structs. I'll just use libaom-av1 for now with ffmpeg 4.4.1.
libsvtav1 is faster than libaom-av1 but it seems like libsvtav1 is broken in ffmpeg 4.4.1 so i might use libaom-av1 too. After compiling ffmpeg 5.0 from source they seem to have fixed it but they did some minor changes to the api http://git.videolan.org/?p=ffmpeg.git;a ... 37863e2b46 so now zoneminder does not compile until i fix that too.
-edit-
Yeah no they changed more than just const-ness of structs. I'll just use libaom-av1 for now with ffmpeg 4.4.1.
Re: Support storage encoding AV1
libaom-av1 is horribly slow. Converting a 2MB camera file took 17 seconds with libaom-av1 vs 3 seconds with libsvtav1. I will continue my effort on adapting the code to ffmpeg 5.
Commands used:
crf 40
17s 350kb: time ffmpeg -i 157-video.mp4 -c:v libaom-av1 -g 150 -crf 40 -b:v 0 -cpu-used 8 -y test.mkv
3s 382kb: time ffmpeg -i 157-video.mp4 -c:v libsvtav1 -g 150 -rc cqp -qp 40 -preset 8 -y test.mkv
crf 30
31s 631kb: time ffmpeg -i 157-video.mp4 -c:v libaom-av1 -g 150 -crf 30 -b:v 0 -cpu-used 8 -y test.mkv
3.5s 762kb: time ffmpeg -i 157-video.mp4 -c:v libsvtav1 -g 150 -rc cqp -qp 30 -preset 8 -pix_fmt yuv420p10le -y test.mkv
libaom-av1 compresses slightly better but at a massive time cost compared to libsvtav1.
-edit-
I should have based this work on master instead of 1.36.12 as i see some of ffmpeg 5 stuff is already fixed there >.<
Commands used:
crf 40
17s 350kb: time ffmpeg -i 157-video.mp4 -c:v libaom-av1 -g 150 -crf 40 -b:v 0 -cpu-used 8 -y test.mkv
3s 382kb: time ffmpeg -i 157-video.mp4 -c:v libsvtav1 -g 150 -rc cqp -qp 40 -preset 8 -y test.mkv
crf 30
31s 631kb: time ffmpeg -i 157-video.mp4 -c:v libaom-av1 -g 150 -crf 30 -b:v 0 -cpu-used 8 -y test.mkv
3.5s 762kb: time ffmpeg -i 157-video.mp4 -c:v libsvtav1 -g 150 -rc cqp -qp 30 -preset 8 -pix_fmt yuv420p10le -y test.mkv
libaom-av1 compresses slightly better but at a massive time cost compared to libsvtav1.
-edit-
I should have based this work on master instead of 1.36.12 as i see some of ffmpeg 5 stuff is already fixed there >.<
Re: Support storage encoding AV1
You should add them both in videostore.cpp as either one may be present.
1.36.13 will contain the ffmpeg fixes, they are trivial.
Still your work should be based on master as it is unlikely to get into 1.36.
Yeah even h265 is prohibitively expensive in terms of cpu. av1 is going to be worse. gpu should help eventually.
1.36.13 will contain the ffmpeg fixes, they are trivial.
Still your work should be based on master as it is unlikely to get into 1.36.
Yeah even h265 is prohibitively expensive in terms of cpu. av1 is going to be worse. gpu should help eventually.
Re: Support storage encoding AV1
I disagree the ffmpeg fixes are trivial it is not just the const changes, master does not build with ffmpeg 5.0 either.
I am not adding libaom, it is 5-10x as slow for 10% gain.
I am however adding vp9 too as that is also supported on all browsers and decently fast too.
I am not adding libaom, it is 5-10x as slow for 10% gain.
I am however adding vp9 too as that is also supported on all browsers and decently fast too.
Re: Support storage encoding AV1
I got the master branch building with ffmpeg 5 now (crudely) https://github.com/exuvo/zoneminder/commits/master.
vp9 works well but av1 is giving me some error. For both however i have the problem that the web part is still sending metadata to the webbrowser as if the file was mp4 which it no longer is. Need to figure out where to change that.
vp9 works well but av1 is giving me some error. For both however i have the problem that the web part is still sending metadata to the webbrowser as if the file was mp4 which it no longer is. Need to figure out where to change that.
Re: Support storage encoding AV1
VP9 is working now for me in the browser. I just left OutputContainer column in Monitors empty which defaults to mp4 and works. The video file is being named 123-video.vp9.mp4 but that does not really matter.
Video controls are not working but that i don't need that, i can just refresh to restart the current event from the beginning or access the file directly via the network if i need any frame by frame things.
Encoder set to libvpx-vp9 and encoding parameters crf=30.
I have yet to update to master but this is the only commit needed https://github.com/exuvo/zoneminder/com ... 32abf95ebd .
If i get more free time and energy i will test more with av1.
Video controls are not working but that i don't need that, i can just refresh to restart the current event from the beginning or access the file directly via the network if i need any frame by frame things.
Encoder set to libvpx-vp9 and encoding parameters crf=30.
I have yet to update to master but this is the only commit needed https://github.com/exuvo/zoneminder/com ... 32abf95ebd .
If i get more free time and energy i will test more with av1.
Last edited by exuvo on Mon May 30, 2022 11:52 pm, edited 1 time in total.
Re: Support storage encoding AV1
Oh i see my change is already in the master now. I must have missed when that happened.
Re: Support storage encoding AV1
I just built from master and now the video player controls are working but zmc crashes when it tries to record
Re: Support storage encoding AV1
How about posting some logs?
We can get this working, but I can't do it all on my own, and neither can you..
We can get this working, but I can't do it all on my own, and neither can you..