EliasKotlyar / Xiaomi-Dafang-Hacks

4.19k stars 1k forks source link

FFMPEG NOISE Sensor #690

Closed bachoo786 closed 6 years ago

bachoo786 commented 6 years ago

Hi Guys

Can we use the rtsp stream using Home Assistant's component of Binary Sensor and platform ffmpeg noise?

Any help will be appreciated.

Thanks.

jmtatsch commented 6 years ago

What would you like to achieve with that?

bachoo786 commented 6 years ago

Just trying to build a smart monitor following this article:

https://community.home-assistant.io/t/smart-baby-monitor/42656

jmtatsch commented 6 years ago

Wow, very interesting use case. Could work. Why don’t you try it out.

bachoo786 commented 6 years ago

Tried it but doesn't work...the audio doesn't work in tinycam either.

jmtatsch commented 6 years ago

Try different audio settings

bachoo786 commented 6 years ago

How do I do that ?

jmtatsch commented 6 years ago

WebUI->Manage->Settings->Audio...

bachoo786 commented 6 years ago

So pcmu works with tinycampro but home assistant doesn't pick it up using ffmpeg noise.

Another thing I would like to point out is that on tinycanpro I can only listen to the sound when connected to the same network as the dafang camera. Is there anyway I could listen to the camera outside the camera network? I have already set my port forwarding in my router i.e port 80 and 8554 have already been forwarded..

jmtatsch commented 6 years ago

Forward https port. Rtsp & Webserver credentials must be equal.

nik0 commented 6 years ago

@bachoo786, I use MP3 as audio (see in camera settings) The command: ffmpeg -i rtsp://LOGIN:PASSWORD@CAM_IP:8554/unicast -vn -filter:a silencedetect=n=-30dB:d=1 -f null - seems to work (at least I have some output of the "silence detect" plugin) It is not working on the camera directly (avconv need to have this plugin activated) but on another Liniux machine

bachoo786 commented 6 years ago

@nik0 are you using that as ffmpeg noise ?

nik0 commented 6 years ago

Myself no, I just try it as you mentioned it

bachoo786 commented 6 years ago

Nope doesn't work that command on raspberry pi running home assistant.

nik0 commented 6 years ago

Any errors? outputs ? logs ?

bachoo786 commented 6 years ago

The error in homeassistant is just that it cannot connect to the ffmpeg audio. I get the same issue with tinycampro when I am not in the s same network as the camera I cannot listen to anything. But when I connect to the same network as the camera the volume works and sound works too.

I have forwarded all the ports. So what can it be wrong?

nik0 commented 6 years ago

The audio and the video are on the same stream. So if you have the video you should have the audio. Did you try different audio settings? Did you run ffmpeg alone?

bachoo786 commented 6 years ago

Well I don't have video on homeassistant at the moment.

I have tried different audio and pcmu works for me when I am connected to the same network as the camera using tinycampro. Other then that nothing works.

Sorry but how do I run ffmpeg alone?

nik0 commented 6 years ago

To get the audio/video from external network you indeed forward the port (8554 by default). To run ffmpeg, you have to ssh to your machine that will run the baby monitor and type: ffmpeg -i rtsp://LOGIN:PASSWORD@CAM_IP:8554/unicast -vn -filter:a silencedetect=n=-30dB:d=1 -f null -

bachoo786 commented 6 years ago

by the way on VLC the audio is working fine even when I am not connected to the same network as the camera. So I wonder what is the problem?

nik0 commented 6 years ago

Does tiny cam using RTSP ? There are 2 ports:

bachoo786 commented 6 years ago

when I use the command "ffmpeg" it says "-sh: ffmpeg: not found" what could be wrong?

nik0 commented 6 years ago

You need to find where it is installed Or install it, with a command like this: sudo apt-get install ffmpeg

bachoo786 commented 6 years ago

ok this command ffmpeg -i rtsp://LOGIN:PASSWORD@CAM_IP:8554/unicast -vn -filter:a silencedetect=n=-30dB:d=1 -f null - does not work with Home Assistant as a binary sensor.

However when I just use it on my raspberry pi, I get the following errors:

ffmpeg version 3.2.10-1~deb9u1+rpt2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version='1~deb9u1+rpt2' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --arch=armhf --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[rtsp @ 0xcdc5c0] UDP timeout, retrying with TCP
[mp3 @ 0xce06e0] Header missing
Input #0, rtsp, from 'rtsp://XXXX:XXXX@XX.XXX.XXX.XXX:8554/unicast':
  Metadata:
    title           : LIVE555 Streaming Media v2017.10.28
    comment         : LIVE555 Streaming Media v2017.10.28
  Duration: N/A, start: 0.131156, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1280x720, 20 fps, 20 tbr, 90k tbn, 40 tbc
    Stream #0:1: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
Output #0, null, to 'pipe:':
  Metadata:
    title           : LIVE555 Streaming Media v2017.10.28
    comment         : LIVE555 Streaming Media v2017.10.28
    encoder         : Lavf57.56.101
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
    Metadata:
      encoder         : Lavc57.64.101 pcm_s16le
Stream mapping:
  Stream #0:1 -> #0:0 (mp3 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[mp3 @ 0xd02600] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[null @ 0xd02a00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 14976 >= 8064
[null @ 0xd02a00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 27135 >= 20223

and this line keeps on repeating until I stop the command:

[null @ 0xd02a00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 35702 >= 33072

nik0 commented 6 years ago

I need to check at home but: Application provided invalid, non monotonically increasing dts ... is a "normal" output (not related to your tests). I don't recall to have [mp3 @ 0xd02600] Header missing At some point I get some messages from "silencedetect" plugin. I will re-test it later and provide you the logs I get.

bachoo786 commented 6 years ago

thank you. I changed the external port to 554 and internal is 8554 to test the audio and video on tinycampro. The video plays fine but no audio at all get a message saying your camera does not support audio. I try the same on VLC in my mobile and everything is working fine i.e. video and audio.

bachoo786 commented 6 years ago

right so I have updates:

my configuration for the binary noise sensor in Home Assistant was incorrect hence why it couldnt detect any noise from the camera. It is working now I had to change the config...

the command ffmpeg -i rtsp://LOGIN:PASSWORD@CAM_IP:8554/unicast -vn -filter:a silencedetect=n=-30dB:d=1 -f null - works fine on raspberry pi too and shows the time lapsed in detecting any noise or sound.

However, I am still struggling to get the audio working in tinycampro app. I have the same issued as mentioned earlier.

Is there a different port for Audio? or?

I have forwarded 8554 to 554 but it still doesnt detect audio and video is working fine.

Any thoughts?

nik0 commented 6 years ago

For the audio you can search on the existing issues and also check this: https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/issues/660

bachoo786 commented 6 years ago

I have searched everywhere for this issue but cannot find any solution. I think tinycampro might need to resolve this as it works with VLC etc.

bachoo786 commented 6 years ago

Do you think it is something to do with channels in the camera and Dafang Hacks?

canaru commented 6 years ago

@bachoo786, I had the same issue on TinyCam. Just trying something different I changed the camera model to "xiaofang" and now I have sound. However PTZ doesn't work with this config. It's only a workaround.

bachoo786 commented 6 years ago

@canaru bloody hell I have been pulling my hair for the audio to work and it just did after I changed the model to "Xiaofang". Thanks alot. Its true that PTZ doesnt work anymore.

Maybe the mods will work on this..

bachoo786 commented 6 years ago

@canaru Change the camera brand to XiaomiHacks and the camera model to DaFang. Everything is working for me now audio and video. Although video is not as great as earlier.

thepuncake commented 3 years ago

bachoo786 currently trying to get ffmpeg-noise to work in home assistant, what did you have to change in your config before it worked? Cheers!