Event video encoding problem from mjpeg sources.
Posted: Wed Dec 04, 2019 5:07 pm
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:
The important part being:
duration=4294967.281000
Whereas occasionally I get an encode like:
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 ->
If I run that by hand on the same pile of jpgs that produced the gooped duration video, say like this:
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?
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]
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]
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
Code: Select all
/usr/bin/ffmpeg -y -i "%5d-capture.jpg" -pix_fmt yuv420p -strict experimental -movflags faststart -codec h264 monkeybutt.mp4
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?