Solved! Audio record problem with camera passthrough

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
tra
Posts: 19
Joined: Tue Jan 10, 2017 10:56 am

Solved! Audio record problem with camera passthrough

Post by tra »

Camera Passthrough storage is great with h264 cameras, thank you very much of this new feature!

But how can I record audio to mp4-video with camera when audio is not valid for mp4-container?

I have several cameras, audio format is pcm_mulaw. Works fine with ffmpeg, I can get audio if I capture video (vithout encoding) using
pure ffmpeg, for example to mkv container. Problem is that pcm_mulaw is not valid for mp4 container like aac.
I tried to add -c:a aac
to Optional Encoder Parameters but no luck.

What I want, passthrough only video from camera but encode audio to aac.
Is it possible?
Last edited by tra on Sat Dec 08, 2018 10:43 pm, edited 1 time in total.
User avatar
iconnor
Posts: 2881
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Audio record problem with camera passthrough

Post by iconnor »

ZM will automatically encode the audio to aac when saving to .mp4.
jedix
Posts: 15
Joined: Thu Aug 16, 2018 2:06 pm

Re: Audio record problem with camera passthrough

Post by jedix »

Be sure you have the necessary library installed to encode aac. Perhaps enable debug logs to check for any error messages from ffmpeg?
tra
Posts: 19
Joined: Tue Jan 10, 2017 10:56 am

Re: Audio record problem with camera passthrough

Post by tra »

iconnor wrote: Fri Oct 05, 2018 6:00 pm ZM will automatically encode the audio to aac when saving to .mp4.
OK, but somehow it does not work, I do not know why.

I can capture video/audio to mp4 from camera, so I think I do have necessary libraries.
/usr/bin/ffmpeg -i rtsp://admin:123456@192.168.0.125:554/mpeg4 -c:v copy -c:a aac foo.mp4

works fine with audio.

But with ZM i can not get audio track at all. Camera which originally output audio too aac works fine (with audio, it has some other problems with invalid alarms from video).
Zonemider version is (distro Fedora 28):
zoneminder.x86_64 1.32.0-1.fc28 @rpmfusion-free-updates

From datalog I have some errors related to this after put debug on from options. Maybe these can help how to fix this?
Maybe this is why it does not work, but why? "ERR-zm_videostore.cpp/587 [could not open codec (-22) (Invalid argument)"

Code: Select all

10/08/18 14:46:21.395172 zmc_m9[16861].INF-zmc.cpp/223 [Starting Capture version 1.32.0]
10/08/18 14:46:21.396421 zmc_m9[16861].INF-zm_ffmpeg_camera.cpp/163 [Priming capture from rtsp://admin:123456@192.168.0.125:554/mpeg4]
10/08/18 14:46:21.405075 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/342 [Calling avformat_open_input for rtsp://admin:123456@192.168.0.125:554/mpeg4]
10/08/18 14:46:21.520137 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/374 [Opened input]
10/08/18 14:46:21.524613 zmc_m9[16861].INF-zm_ffmpeg_camera.cpp/376 [Stream open rtsp://admin:123456@192.168.0.125:554/mpeg4, parsing streams...]
10/08/18 14:46:22.481373 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/501 [Failed to find decoder (h264_mmal)]
10/08/18 14:46:22.481446 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/512 [Video Found decoder h264]
10/08/18 14:46:22.481464 zmc_m9[16861].DB1-zm_ffmpeg.cpp/266 [Dumping stream index i(0) index(0)]
10/08/18 14:46:22.481480 zmc_m9[16861].DB1-zm_ffmpeg.cpp/271 [    Stream #0:0]
10/08/18 14:46:22.481495 zmc_m9[16861].DB1-zm_ffmpeg.cpp/279 [, frames:28, timebase: 1/90000]
10/08/18 14:46:22.481520 zmc_m9[16861].DB1-zm_ffmpeg.cpp/281 [: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080]
10/08/18 14:46:22.481537 zmc_m9[16861].DB1-zm_ffmpeg.cpp/227 [30 fps, ]
10/08/18 14:46:22.481558 zmc_m9[16861].DB1-zm_ffmpeg.cpp/229 [90k stream tb numerator , ]
10/08/18 14:46:22.481574 zmc_m9[16861].DB1-zm_ffmpeg.cpp/227 [60 codec time base:]
10/08/18 14:46:22.481589 zmc_m9[16861].DB1-zm_ffmpeg.cpp/336 [
]
10/08/18 14:46:22.481603 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/519 [Calling avcodec_open2]
10/08/18 14:46:22.481726 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/542 [HWACCEL not in use]
10/08/18 14:46:22.481770 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/554 [Audio Found decoder]
10/08/18 14:46:22.481788 zmc_m9[16861].DB1-zm_ffmpeg.cpp/266 [Dumping stream index i(1) index(0)]
10/08/18 14:46:22.481804 zmc_m9[16861].DB1-zm_ffmpeg.cpp/271 [    Stream #0:1]
10/08/18 14:46:22.481818 zmc_m9[16861].DB1-zm_ffmpeg.cpp/279 [, frames:24, timebase: 1/8000]
10/08/18 14:46:22.481850 zmc_m9[16861].DB1-zm_ffmpeg.cpp/281 [: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s]
10/08/18 14:46:22.481867 zmc_m9[16861].DB1-zm_ffmpeg.cpp/336 [
]
10/08/18 14:46:22.481881 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/561 [Calling avcodec_open2]
10/08/18 14:46:22.481917 zmc_m9[16861].DB1-zm_ffmpeg_camera.cpp/598 [Calling sws_isSupportedInput]
10/08/18 14:46:22.510787 zmc_m9[16861].INF-zm_monitor.cpp/2478 [Kisakamera_kentta2: images:1 - Capturing at 1000.00 fps, capturing bandwidth 53414bytes/sec]
10/08/18 14:46:24.800752 zmc_m9[16861].INF-zm_videostore.cpp/54 [Opening video storage stream /var/lib/zoneminder/events/9/2018-10-08/278386/278386-video.mp4 format: mp4]
10/08/18 14:46:24.814959 zmc_m9[16861].DB1-zm_ffmpeg.cpp/260 [Dumping codec_context codec_type(0) codec_id(27) width(1920) height(1080)  timebase(0/1) format(yuvj420p)]
10/08/18 14:46:24.815029 zmc_m9[16861].DB1-zm_ffmpeg.cpp/243 [Dumping codecpar codec_type(0) codec_id(27) codec_tag(828601953) width(1920) height(1080) bit_rate(0) format(12 = yuvj420p)]
10/08/18 14:46:24.815878 zmc_m9[16861].ERR-zm_videostore.cpp/587 [could not open codec (-22) (Invalid argument)
]
10/08/18 14:46:24.823550 zmc_m9[16861].DB1-zm_ffmpeg.cpp/266 [Dumping stream index i(0) index(0)]
10/08/18 14:46:24.823579 zmc_m9[16861].DB1-zm_ffmpeg.cpp/271 [    Stream #0:0]
10/08/18 14:46:24.823595 zmc_m9[16861].DB1-zm_ffmpeg.cpp/279 [, frames:0, timebase: 1/90000]
10/08/18 14:46:24.823619 zmc_m9[16861].DB1-zm_ffmpeg.cpp/281 [: Unknown: none]
10/08/18 14:46:24.823633 zmc_m9[16861].DB1-zm_ffmpeg.cpp/336 [
]
10/08/18 14:46:24.824024 zmc_m9[16861].DB1-zm_packetqueue.cpp/187 [Done looking for keyframe.  Deleted 92 frames. Remaining frames in queue: 86 stream of head packet is (0), keyframe (1), distance(1), packets(86)]
10/08/18 14:46:24.824116 zmc_m9[16861].DB1-zm_videostore.cpp/733 [duration calc: pts(150120) - last_pts( 94078119650682) = (-94078119500562)]
10/08/18 14:46:24.824304 zmc_m9[16861].DB1-zm_videostore.cpp/865 [Called writeAudioFramePacket when no audio_out_stream]
10/08/18 14:46:24.824332 zmc_m9[16861].DB1-zm_videostore.cpp/733 [duration calc: pts(153180) - last_pts( 150120) = (3060)]
10/08/18 14:46:24.824368 zmc_m9[16861].DB1-zm_videostore.cpp/865 [Called writeAudioFramePacket when no audio_out_stream]
10/08/18 14:46:24.824388 zmc_m9[16861].DB1-zm_videostore.cpp/733 [duration calc: pts(156150) - last_pts( 153180) = (2970)]
10/08/18 14:46:24.824411 zmc_m9[16861].DB1-zm_videostore.cpp/733 [duration calc: pts(159120) - last_pts( 156150) = (2970)]
10/08/18 14:46:24.824434 zmc_m9[16861].DB1-zm_videostore.cpp/865 [Called writeAudioFramePacket when no audio_out_stream]

... etc....
--
- TRa
tra
Posts: 19
Joined: Tue Jan 10, 2017 10:56 am

Re: Audio record problem with camera passthrough

Post by tra »

Updated 1.32.0 to 1.32.1 but still no audio.

Is there the way somehow debug that more?
This error [could not open codec (-22) (Invalid argument)] does not tell me much.

From debug log you can see audio is available and stream is found. And I can capture it by pure ffmpeg, but it is not working with zoneminder.
I can see also later lines like: [Have audio packet, but not recording atm] what that means?

Code: Select all

10/17/18 15:43:40.404471 zmc_m9[2418].DB2-zm_ffmpeg_camera.cpp/729 [Have change of event.  last_event(284308), our current (0)] 
10/17/18 15:43:40.404479 zmc_m9[2418].DB3-zm_ffmpeg_camera.cpp/765 [Video module initiated with audio stream] 
10/17/18 15:43:40.404528 zmc_m9[2418].INF-zm_videostore.cpp/54 [Opening video storage stream /var/lib/zoneminder/events/9/2018-10-17/284308/284308-video.mp4 format: mp4] 
10/17/18 15:43:40.406509 zmc_m9[2418].DB4-zm_videostore.cpp/63 [Success allocating out format ctx] 
10/17/18 15:43:40.406559 zmc_m9[2418].DB1-zm_ffmpeg.cpp/261 [Dumping codec_context codec_type(0) codec_id(27) width(1920) height(1080)  timebase(0/1) format(yuvj420p)] 
10/17/18 15:43:40.406585 zmc_m9[2418].DB2-zm_videostore.cpp/108 [Success creating video out stream] 
10/17/18 15:43:40.406594 zmc_m9[2418].DB2-zm_videostore.cpp/114 [No codec_tag, setting to 828601953] 
10/17/18 15:43:40.406602 zmc_m9[2418].DB2-zm_videostore.cpp/124 [Success setting parameters] 
10/17/18 15:43:40.406620 zmc_m9[2418].DB1-zm_ffmpeg.cpp/244 [Dumping codecpar codec_type(0) codec_id(27) codec_tag(828601953) width(1920) height(1080) bit_rate(0) format(12 = yuvj420p)] 
10/17/18 15:43:40.406629 zmc_m9[2418].DB3-zm_videostore.cpp/174 [Time bases: VIDEO in stream (1/90000) in codec: (0/1) out stream: (1/90000) out codec (1/1000000)] 
10/17/18 15:43:40.406638 zmc_m9[2418].DB3-zm_videostore.cpp/213 [Have audio stream] 
10/17/18 15:43:40.406662 zmc_m9[2418].DB2-zm_videostore.cpp/226 [Got something other than AAC (Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s)] 
10/17/18 15:43:40.406734 zmc_m9[2418].DB2-zm_videostore.cpp/519 [Have audio out codec] 
10/17/18 15:43:40.407467 zmc_m9[2418].DB2-zm_videostore.cpp/531 [Have audio_out_ctx] 
10/17/18 15:43:40.407526 zmc_m9[2418].DB3-zm_videostore.cpp/561 [Sample rate is good] 
10/17/18 15:43:40.407535 zmc_m9[2418].DB2-zm_ffmpeg.cpp/350 [Not fltp] 
10/17/18 15:43:40.407543 zmc_m9[2418].DB3-zm_videostore.cpp/573 [Encoder does not support sample format s16, setting to FLTP] 
10/17/18 15:43:40.407606 zmc_m9[2418].ERR-zm_videostore.cpp/597 [could not open codec (-22) (Invalid argument) 
] 
tra
Posts: 19
Joined: Tue Jan 10, 2017 10:56 am

Re: Audio record problem with camera passthrough

Post by tra »

I really want to fix this. I downloaded also the source package, but I'm not familiar with zoneminder enough. Could somebody point me the correct source file which defines the actual ffmpeg-command to capture video?
Binary is zmc am I right?

I think it should be quite trivial to find the ffmpeg parameter which causes:
[could not open codec (-22) (Invalid argument)]
I can be also wrong...

Capturing video+audio using command line ffmpeg works fine, so it should work with these cameras.
tra
Posts: 19
Joined: Tue Jan 10, 2017 10:56 am

Re: Solved! Audio record problem with camera passthrough

Post by tra »

Upgrading to version 1.32.2 fixed the problem. Audio works now fine with all my cameras support audio. Thank you very much :D

- TRa
Post Reply