Skip to content

Commit

Permalink
Merge pull request #165 from kopiro/video-codec
Browse files Browse the repository at this point in the history
Video codec
  • Loading branch information
kopiro authored Oct 3, 2024
2 parents b841674 + 524bdd9 commit 63d5e44
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
45 changes: 33 additions & 12 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,62 @@
"description": "Name of the LED toggle",
"placeholder": "LED"
},

"videoMaxWidth": {
"title": "Video Max Width",
"type": "integer",
"description": "Maximum width of the video stream",
"placeholder": 1280
"placeholder": 1280,
"multipleOf": 2,
"minimum": 0,
"description": "The maximum width used for video streamed to HomeKit. If set to 0, or videoCodec is set to 'copy' (default), the resolution of the source is used. If not set, will use any size HomeKit requests."
},
"videoMaxHeight": {
"title": "Video Max Height",
"type": "integer",
"description": "Maximum height of the video stream",
"placeholder": 720
"placeholder": 720,
"multipleOf": 2,
"minimum": 0,
"description": "The maximum height used for video streamed to HomeKit. If set to 0, or videoCodec is set to 'copy' (default), the resolution of the source is used. If not set, will use any size HomeKit requests."
},
"videoMaxFPS": {
"title": "Video Max FPS",
"type": "integer",
"description": "Maximum frames per second of the video stream",
"placeholder": 30
"placeholder": 30,
"minimum": 0,
"description": "The maximum frame rate used for video streamed to HomeKit. If set to 0, or videoCodec is set to 'copy' (default), the framerate of the source is used. If not set, will use any framerate HomeKit requests."
},
"videoMaxBitrate": {
"title": "Video Max Bitrate",
"type": "integer",
"description": "Maximum bitrate of the video stream",
"placeholder": 300
"placeholder": 299,
"minimum": 0,
"description": "The maximum bitrate used for video streamed to HomeKit, in kbit/s. If not set, or videoCodec is set to 'copy' (default), it will use any bitrate HomeKit requests."
},
"videoPacketSize": {
"title": "Video Packet Size",
"type": "integer",
"description": "Size of the video packets",
"placeholder": 1316
"placeholder": 1316,
"multipleOf": 188,
"minimum": 188,
"description": "If audio or video is choppy try a smaller value. If not set, or videoCodec is set to 'copy' (default), it will use any packet size HomeKit requests."
},
"videoForceMax": {
"title": "Force Max Video",
"type": "boolean",
"description": "Force the video stream to use the maximum values, instead of the one provided by the Homekit request. Most likely you don't want this"
"description": "If set, the settings requested by HomeKit will be overridden with any 'maximum' values defined in this config. If videoCodec is set to 'copy' (default), this setting set to true is useless."
},
"videoCodec": {
"title": "Video Codec",
"type": "string",
"placeholder": "copy",
"typeahead": {
"source": [
"libx264",
"h264_omx",
"h264_videotoolbox",
"copy"
]
},
"description": "Set the codec used for encoding video sent to HomeKit, must be H.264-based. You can change to a hardware accelerated video codec with this option, if one is available. By default, we set 'copy' to avoid any video processing happening on the Homebridge server and disregarding any max values set above, but this also means possibly sending more video data to your devices than necessary, and some Homekit clients may not like not receiving the resolutions/fps they asked for. If you select a custom codec and your ffmpeg process is crashing, it most likely can't handle the video codec you've chosen."
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/cameraAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type CameraConfig = {
videoForceMax?: boolean;
videoMaxBirate?: number;
videoPacketSize?: number;
videoCodec?: string;

videoConfig?: VideoConfig;

Expand Down Expand Up @@ -170,20 +171,23 @@ export class CameraAccessory {
Boolean(this.config.lowQuality)
);

const vcodec = this.config.videoCodec ?? "copy";
const config: VideoConfig = {
source: `-i ${streamUrl}`,
audio: true,
videoFilter: "none",
vcodec: "copy",
audio: true, // Set audio as true as most of TAPO cameras have audio
vcodec: vcodec,
maxWidth: this.config.videoMaxWidth,
maxHeight: this.config.videoMaxHeight,
maxFPS: this.config.videoMaxFPS,
maxBitrate: this.config.videoMaxBirate,
packetSize: this.config.videoPacketSize,
forceMax: this.config.videoForceMax,
...(this.config.videoConfig || {}),
// We add this at the end as the user most not be able to override it
source: `-i ${streamUrl}`,
};

this.log.debug("Video config", config);

return config;
}

Expand Down

0 comments on commit 63d5e44

Please sign in to comment.