Event video encoding problem from mjpeg sources.

Forum for questions and support relating to 1.33.x development only.
Locked
finegan
Posts: 3
Joined: Wed Dec 04, 2019 4:25 pm

Event video encoding problem from mjpeg sources.

Post by finegan »

So I was super excited when I noticed that Zoneminder 1.3x had started doing video encoding for me on events.

The problem I have is that the video generated tends to be encoded a bit broken.

This is the same problem with 5 different monitors all running mjpeg_server, modetect. They're all just Pis with either raspicams or USB cameras. They all typically monitor around 20+ FPS.

The ZM server is debian buster, running 1.33.15 from the https://zmrepo.zoneminder.com/debian/master repo as a fresh install, nothing terribly special.

So the videos encoded by ZM about 3/4s of the time aren't playable. I end up with weird durations in the encode, stuff like:

Code: Select all

fin@sandman:/var/cache/zoneminder/events/1/2019-12-04/14299#  ffprobe -v error -show_format -show_streams 14299-video.mp4 
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=Main
codec_type=video
codec_time_base=1777/66800
codec_tag_string=avc1
codec_tag=0x31637661
width=1280
height=720
coded_width=1280
coded_height=720
has_b_frames=10
sample_aspect_ratio=N/A
display_aspect_ratio=N/A
pix_fmt=yuv420p
level=31
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=1000/1
avg_frame_rate=33400/1777
time_base=1/1000
start_pts=-1202
start_time=-1.202000
duration_ts=8885
duration=8.885000
bit_rate=2016813
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=167
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:creation_time=2019-12-04T16:20:09.000000Z
TAG:language=und
TAG:encoder=JVT/AVC Coding
[/STREAM]
[FORMAT]
filename=14299-video.mp4
nb_streams=1
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=-1.202000
duration=4294967.281000
size=2243560
bit_rate=4
probe_score=100
TAG:major_brand=mp42
TAG:minor_version=0
TAG:compatible_brands=mp42isom
TAG:creation_time=2019-12-04T16:20:09.000000Z
[/FORMAT]
The important part being:
duration=4294967.281000

Whereas occasionally I get an encode like:

Code: Select all

fin@sandman:/var/cache/zoneminder/events/1/2019-12-04/14298#  ffprobe -v error -show_format -show_streams 14298-video.mp4 
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=Main
codec_type=video
codec_time_base=643/18400
codec_tag_string=avc1
codec_tag=0x31637661
width=1280
height=720
coded_width=1280
coded_height=720
has_b_frames=2
sample_aspect_ratio=N/A
display_aspect_ratio=N/A
pix_fmt=yuv420p
level=31
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=181/12
avg_frame_rate=9200/643
time_base=1/1000
start_pts=136
start_time=0.136000
duration_ts=9645
duration=9.645000
bit_rate=1745659
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=138
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:creation_time=2019-12-04T16:17:19.000000Z
TAG:language=und
TAG:encoder=JVT/AVC Coding
[/STREAM]
[FORMAT]
filename=14298-video.mp4
nb_streams=1
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.136000
[b]duration=9.645000[/b]
size=2107704
bit_rate=1748225
probe_score=100
TAG:major_brand=mp42
TAG:minor_version=0
TAG:compatible_brands=mp42isom
TAG:creation_time=2019-12-04T16:17:19.000000Z
[/FORMAT]
That one is: duration=9.645000, plays in browers normally.

So I figured let's change the FFMPEG options. So in the config I set:

Options -> Images ->

Code: Select all

FFMPEG_INPUT_OPTIONS: -y 
FFMPEG_OUTPUT_OPTIONS: -pix_fmt yuv420p -strict experimental -movflags faststart -codec h264
PATH_FFMPEG: /usr/bin/ffmpeg
If I run that by hand on the same pile of jpgs that produced the gooped duration video, say like this:

Code: Select all

/usr/bin/ffmpeg -y -i "%5d-capture.jpg" -pix_fmt yuv420p -strict experimental -movflags faststart -codec h264 monkeybutt.mp4
The result is that monkeybutt.mp4 is viable, 6 seconds long, 169 jpgs went into it, bounces around 25fps, its normal. (I could cut and paste the ffprobe dump but that seems like overkill.

I figured after fiddling with ffmpeg options in ZM's control panel a few times that maybe... ZM isn't even using them?

Then I changed the ffmpeg path in ZM to /usr/local/bin/ffmpeg and then made that a bash script that would just echo the arguments it was fed to a file in tmp. ZM just kept making mp4s.

So I chmod'd /usr/bin/ffmpeg to 644, made sure there wasn't a different ffmpeg around, and then forced an event and it still produces mp4s.

Okay, what's encoding these mp4s? I assume its something in Zoneminder, and where can I feed it options to debug this?
User avatar
iconnor
Posts: 2882
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Event video encoding problem from mjpeg sources.

Post by iconnor »

Correct it is not using those settings. Those are for generating a video from the stored jpegs after the event has been recorded.

The settings you want go in the actual Monitor -> Storage Optional Encoder Parameters

I'll have a look and see if I can reproduce it. This code doesn't use ffmpeg, it uses libx264 and is deprecated. It will likely be replaced with an ffmpeg based recorder in 1.35.
finegan
Posts: 3
Joined: Wed Dec 04, 2019 4:25 pm

Re: Event video encoding problem from mjpeg sources.

Post by finegan »

Thanks for the quick reply.

I know bugger all about video encoding, but I've been trying random flags. Just want to make sure I've got the format right so these parse correctly. One per line?

# Lines beginning with # are a comment
# For changing quality, use the crf option
# 1 is best, 51 is worst quality
crf=2
bframes=2
ref=3

Also, and good source of truth for what the underlying libx264 options are? The best bit of documentation I can find is:
https://help.encoding.com/knowledge-bas ... deo-codec/
finegan
Posts: 3
Joined: Wed Dec 04, 2019 4:25 pm

Re: Event video encoding problem from mjpeg sources.

Post by finegan »

Still futzing with this. In reaction to my own last question, yeah that's the format as far as I can tell. One per line, flag=value, but as for the possible flags to meddle with, I'm still at a loss.

Also, I should have checked this before, but the durations of all the "garbage" videos almost match.

@sandman:/var/cache/zoneminder/events/1# cat /tmp/deux-events | grep 4294967
duration=4294967.229000
duration=4294967.221000
duration=4294967.218000
duration=4294967.243000
duration=4294967.226000
duration=4294967.268000
duration=4294967.216000
duration=4294967.171000
duration=4294967.195000
duration=4294967.284000
duration=4294967.237000
duration=4294967.153000
duration=4294967.221000
duration=4294967.236000
duration=4294967.267000
duration=4294967.203000
duration=4294967.224000
duration=4294967.192000
duration=4294967.167000
duration=4294967.237000
duration=4294967.238000
duration=4294967.226000
duration=4294967.163000
duration=4294967.214000
duration=4294967.231000
duration=4294967.234000
duration=4294967.223000
duration=4294967.220000
duration=4294967.281000
duration=4294967.294000
duration=4294967.225000
duration=4294967.226000
duration=4294967.236000
duration=4294967.229000
duration=4294967.223000
duration=4294967.226000
duration=4294967.288000
duration=4294967.200000
duration=4294967.225000
duration=4294967.220000
duration=4294967.230000
duration=4294967.235000
duration=4294967.219000

Out of the 114 videos I had on-hand from that one camera, 43 of them had the above durations. Also that duration is weirdly close to 4,294,967,295 (2^32 - 1)

Anyway, continuing random flag guesses
Locked