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

[BUG] - recordVideo produces corrupted files #17

Closed machineglow closed 4 years ago

machineglow commented 5 years ago

Describe the bug When trying to initiate recordVideo, the resulting video is corrupted. The top part of the stream (where the OSD is) is fine but the rest is corrupted/empty artifacts.

Expected behavior Expecting an uncorrupted frame/video

Config { "platform": "Dafang", "mqtt": { "hostBroker": true, "port": 1883, "host": "homebridgeIP", "debug": true, "mongoUrl": "mongodb://homebridgeIP:27017/mqtt" }, "cameras": [{ "cameraName": "PanCam", "cameraRTSPStreamUrl": "rtsp://IP:8554/unicast", "mqttTopic": "home/pancam/#", "folder": "/tmp/", "segmentLength": 60, "maxDirSize": 32768, "checkStorageSizeInterval": 14400, "recordingDirectoryPathFormat": "YYYYMMDD", "recordingFilenameFormat": "YYYYMMDD-hhmmss", "accessories": [ { "name": "Motion Sensor", "type": "richMotionSensor", "threshold": 300000 }, { "name": "Auto Motion Tracking Switch", "type": "autoMotionTrackingSwitch" }, { "name": "Night Vision Sensor", "type": "nightVisionSensor", "threshold": 0 }, { "name": "Night Vision Switch", "type": "nightVisionSwitch" }, { "name": "Auto Night Vision Switch", "type": "autoNightVisionSwitch" }, { "name": "Horizontal Left", "type": "moveCamera", "axis": "horizontal", "direction": "left" }, { "name": "Horizontal Right", "type": "moveCamera", "axis": "horizontal", "direction": "right" }, { "name": "Vertical Up", "type": "moveCamera", "axis": "vertical", "direction": "up" }, { "name": "Vertical Down", "type": "moveCamera", "axis": "vertical", "direction": "down" }, { "name": "Record Video", "type": "recordVideo" }, { "name": "Record Audio", "type": "recordAudio" }, { "name": "Capture Image", "type": "captureImage" }, { "name": "RPi Storage Sensor", "type": "storageSensor" }, { "name": "Reset Streaming", "type": "resetFFMPEG" }, { "name": "Motion Detection Switch", "type": "motionDetection" }, { "name": "Restart Switch", "type": "restartSwitch" }, { "name": "Recalibrate Switch", "type": "recalibrateSwitch" }, { "name": "Camera Brightness", "type": "brightness" } ], "videoConfig": { "source": "-rtsp_transport tcp -i rtsp://IP:8554/unicast", "stillImageSource": "-rtsp_transport tcp -i rtsp://IP:8554/unicast -vframes 1 -r 1", "maxStreams": 2, "maxWidth": 1280, "maxHeight": 720, "maxFPS": 25, "maxBitrate": 128, "packetSize": 188, "debug": true

Logs N/A

Screenshots N/A

Desktop (please complete the following information):

Additional context I actually figured out what the issue is.

when recordVideo calls:

ffmpeg -i rtsp://IP:8554/unicast -acodec copy -vcodec copy [file]

It should add -rtsp_transport tcp argument to the command line.

ffmpeg -rtsp_transport tcp -i -i rtsp://IP:8554/unicast -acodec copy -vcodec copy [file]

I can reproduce the corrupted video with the first line but the second command does not produce a corrupted video.

Thanks!

machineglow commented 5 years ago

I see this is due to the lack of arguements in your node_rtsp_recorder module.

Here's a snippet of what I did in the recorder.js

  getChildProcess(fileName) {

    var args = ['-rtsp_transport', 'tcp', '-i', this.url]

    const mediaArgs = this.getArguments()

    mediaArgs.forEach((item) => {

      args.push(item)

    })

    args.push(fileName)

    return childProcess.spawn('ffmpeg',

      args,

      { detached: false, stdio: 'ignore' })

  }

I think ultimately, we should be able to define the rtsp stream url with arguments like how homebridge-camera-ffmpeg does it.

hope this helps!

iwonder-1618 commented 5 years ago

Hey @machineglow , Would appreciate if you can create a PR for node-rtsp-recorder. Looks like a solid fix to many ffmpeg problems.

machineglow commented 5 years ago

Hi!

I'm kind of a newb with this whole git thing... What's a PR?

Automatt commented 5 years ago

https://github.com/sahilchaddha/node-rtsp-recorder/pull/5