sahilchaddha / homebridge-dafang

Homebridge Plugin for Xiaomi Dafang / Wyze Cam IP Camera => Hey Siri, Start Video Recording
MIT License
204 stars 34 forks source link

[noBUG] - Can't get ffmpeg to work propperly #27

Open x23piracy opened 5 years ago

x23piracy commented 5 years ago

Hi,

i am on a rpi 3 and ffmpeg is always exiting with error code 1 when i try to stream, one frame snapshots are no problem it's only when streaming should start and ffmpeg gets used.

First i tried to install ffmpeg this way: http://jollejolles.com/installing-ffmpeg-with-h264-support-on-raspberry-pi/

Then i decided to try ffmpeg from apt-get but with both no go. homebridge is running under pi user context, is there something i need to adjust?

Also i really would like to try to install ffmpeg with brew like suggested in this project but i can'T get linuxbrew to run, i followed their instruction but i cannot type brew in command line, command not found.

Can someone help me to get ffmpeg running propper? Is someone here were it's working with an rpi?

Regards Jens

renedivx commented 5 years ago

Hi, i have same problem like you before. This solves my problem

  1. install build tools sudo apt-get install pkg-config autoconf automake libtool libx264-dev

  2. download and build fdk-aac git clone https://github.com/mstorsjo/fdk-aac.git cd fdk-aac ./autogen.sh ./configure --prefix=/usr/local --enable-shared --enable-static make -j4 sudo make install sudo ldconfig cd ..

  3. download and build ffmpeg git clone https://github.com/FFmpeg/FFmpeg.git cd FFmpeg ./configure --prefix=/usr/local --arch=armel --target-os=linux --enable-omx-rpi --enable-nonfree --enable-gpl --enable-libfdk-aac --enable-mmal --enable-libx264 --enable-decoder=h264 --enable-network --enable-protocol=tcp --enable-demuxer=rtsp make -j4 sudo make install

It takes some times.

Than make sure that your dafang video and audo settings are correct.

video settings video format: FixedQp Size: 1280x720 FrameRate: 21 BitRate 299

Audio settings audio format: mp3 filter: filter 2 in rate 16000 out rate 16000

with this settings all works fine for me, maybe it will solve your problem too.

best regards rene

x23piracy commented 5 years ago

Hey good morning,

thank you for the detailed answer :) I am currently trying these steps.

Since i already compiled my own ffmpeg and also installed it by at-get, is there something i need to uninstall first?

Before i tried the apt-get ffmpeg i triggered "sudo make uninstall" for both lib h264 and ffmpeg after that i installed ffmpeg by apt-get and its currently installed.

Should i remove ffmpeg with apt-get first?

The video settings you are talking about need to be applied to config.json? EDIT: Ok got it, webcam webif settings for AV... ;)

idk why but rene sounds german? :)

Regards X23

renedivx commented 5 years ago

No problem ;-)

That is also a good question for me. I am also not expert with this things. I search and try different things to solve my problem. What i write before works great for me.

But i think its no problem if you install it without remove the old install. If you use a Raspberry for it, you can make with PiBaker a backup. If you make this frist you can test, if not working you can flash your sd card back with the backup. Like this i do it many times until all works ;-)

Yes i am german, you too?

Best regards rene

x23piracy commented 5 years ago

Hi,

ok i applied all and now i can stream but its not really running smooth, not really moving pictures ;) and then it stucks somehow and breaks or is just insanely bad perfoming but hey thats more then before :)

I am a german too. Prost

Regards X23

renedivx commented 5 years ago

Here is my Config. Maybe that help you too. But htere i use a own MQTT Server. If you dont have, you must change this settings.

{ "platform": "Dafang", "mqtt": { "hostBroker": false, "port": 1883, "host": "192.168.22.104", "debug": true }, "cameras": [ { "cameraName": "terrasse", "cameraRTSPStreamUrl": "rtsp://192.168.22.69:8554/unicast", "mqttTopic": "haus/terrasse/#", "folder": "/home/pi/kamera/", "recordingDirectoryPathFormat": "DD-MM-YYYY", "recordingFilenameFormat": "DD-MM-YYYY-kk-mm-ss", "accessories": [ { "name": "Bewegungssensor", "type": "richMotionSensor", "threshold": 100000 }, { "name": "Auto Bewegung", "type": "autoMotionTrackingSwitch" }, { "name": "Nachtsichtsensor", "type": "nightVisionSensor", "threshold": 0 }, { "name": "Nachtsicht", "type": "nightVisionSwitch" }, { "name": "Auto Nachtsicht", "type": "autoNightVisionSwitch" }, { "name": "Links", "type": "moveCamera", "axis": "horizontal", "direction": "left" }, { "name": "Rechts", "type": "moveCamera", "axis": "horizontal", "direction": "right" }, { "name": "Hoch", "type": "moveCamera", "axis": "vertical", "direction": "up" }, { "name": "Runter", "type": "moveCamera", "axis": "vertical", "direction": "down" }, { "name": "Video aufnehmen", "type": "recordVideo" }, { "name": "Audio aufnehmen", "type": "recordAudio" }, { "name": "Bild aufnehmen", "type": "captureImage" }, { "name": "RPi Speicher", "type": "storageSensor" }, { "name": "Speicher bereinigen", "type": "clearStorage" }, { "name": "Stream zurücksetzen", "type": "resetFFMPEG" }, { "name": "Helligkeit", "type": "brightness" }, { "name": "Neustarten", "type": "restartSwitch" }, { "name": "Kalibrieren", "type": "recalibrateSwitch" } ], "videoConfig": { "source": "-rtsp_transport tcp -re -i rtsp://192.168.22.69:8554/unicast", "stillImageSource": "-i http://root:ismart12@192.168.22.69/cgi-bin/currentpic.cgi", "maxStreams": 2, "maxWidth": 1280, "maxHeight": 720, "maxFPS": 21, "maxBitrate": 299, "vcodec": "h264_omx", "audio": false, "packetSize": 188 } } ] },

x23piracy commented 5 years ago

Thanks :) i have my own mosquitto ;) having sonoffs and other stuff like that. Do you have the 360 one? I first bought the cheaper dafang without movement.

renedivx commented 5 years ago

Hi,

ok i applied all and now i can stream but its not really running smooth, not really moving pictures ;) and then it stucks somehow and breaks or is just insanely bad perfoming but hey thats more then before :)

I am a german too. Prost

Regards X23

Ok great to hear that you can start now the stream. Have you add videoconfig like this to the config.json

"videoConfig": { "source": "-rtsp_transport tcp -re -i rtsp://192.168.22.69:8554/unicast", "stillImageSource": "-i http://root:ismart12@192.168.22.69/cgi-bin/currentpic.cgi", "maxStreams": 2, "maxWidth": 1280, "maxHeight": 720, "maxFPS": 21, "maxBitrate": 299, "vcodec": "h264_omx", "audio": false, "packetSize": 188

My complete settings included this you can above best regards rene

x23piracy commented 5 years ago

Hi,

not yet, i adjusted the settings you told me initally to the cameras webif settings, was that wrong or is that videoconfig part also needed?

renedivx commented 5 years ago

Thanks :) i have my own mosquitto ;) having sonoffs and other stuff like that. Do you have the 360 one? I first bought the cheaper dafang without movement.

Yes i have the dafang with 360 view.

renedivx commented 5 years ago

Hi,

not yet, i adjusted the settings you told me initally to the cameras webif settings, was that wrong or is that videoconfig part also needed?

Ok correct. you need to add this seetings in config.json too. Like this works great for me.

x23piracy commented 5 years ago

Ok i will add this and try :)

renedivx commented 5 years ago

Ok great that i can help you. ;-) Best regards rene

x23piracy commented 5 years ago

Btw. i am always messing up with the hard formatting needs of the config.json when i try to add stuff. I really hate it...meh :)

renedivx commented 5 years ago

Have you install homebridge-config-ui-x v3.9.6? There you can easy edit the confirm and see also directly if something is wrong. Its help me a lot

x23piracy commented 5 years ago

Erm no didnt knew its existing hehe ;)

x23piracy commented 5 years ago

Danke für den Tip :)

renedivx commented 5 years ago

Danke für den Tip :)

Gerne ;-)

x23piracy commented 5 years ago

but i can't get it to work smoothly, i can see movement from time to time but then it stucks, i console i have seen another exit code 1, i removed ffmpeg from repository and installed again from source, lets see if this helps.

x23piracy commented 5 years ago

Its working for some time but in something like slomo then it stops and homekit is telling me no answer from camera... the camera is then useless with home until i reboot it while the webif is normally responding to the camera, strange.

renedivx commented 5 years ago

Ok sorry to hear. maybe you need for your camera other settings like me with the Dafang 360 view. Play something with the settings. maybe this will help.

x23piracy commented 5 years ago

ok i found out that the rtsp server of the cam is crashing, stream to vlc wasn't working until reboot that means the service crashed.

x23piracy commented 5 years ago

hmm i dont understand this, vlc is eating everything applied to the video stream settings (webif) of the camera, why is home such a she-goat ;P regarding to video streams or is this still a ffmpeg issue?

is there anything i can do to debug this to find the problem?

Regards X23

x23piracy commented 5 years ago

Hi,

fun fact, streaming works very good with camera-ffmpeg with the same ffmpeg binary causing problems when trying to stream with dafang plugin.

fun fact two, streaming works but not stillImage :) hehe now i need to combine both plugins. It gets stranger and stranger...

tradziej commented 4 years ago

For people with a similar problem:

You have to remove -rtsp_transport tcp from video configuration, and have it like:

"videoConfig": {
              "source": "-i rtsp://192.168.0.15:8554/unicast",
              "stillImageSource": "-i rtsp://192.168.0.15:8554/unicast -vframes 1 -r 1",
              "maxFPS": 30,
              "maxWidth": 1280,
              "maxHeight": 720,
              "videoFilter": "none",
              "maxBitrate": 1024,
              "packetSize": 188,
              "maxStreams": 2,
              "vcodec": "h264_omx",
              "audio": true,
              "debug": true
          }
Cocco17 commented 4 years ago

FYI - for installations on Raspberry Pi's use:

     sudo apt install ffmpeg -y