home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.14k stars 29.81k forks source link

ffmpeg transcoding of mjpeg stream used for homekit cameras has very low quality due to low bitrate #100768

Open duhanebel opened 11 months ago

duhanebel commented 11 months ago

The problem

I've added a mjpeg camera to home assistant, and then shared it as a homekit accessory from the UI. When I look at the ffmpeg process that is generating the h264 stream for homekit I can see the max bitrate has been set to a very low number: ffmpeg -i http://[server]/stream -hide_banner -nostats -map 0:v:0 -an -c:v libx264 -profile:v high -tune zerolatency -pix_fmt yuv420p -r 30 -b:v 299k -bufsize 299k -maxrate 299k ...

I've looked at the code and I found this line that contains the ffmpeg parameters.

I tried hardcoding a high number (9999k) instead of v_max_bitrate and that seems to produce a way better stream on homekit. Unfortunately I couldn't understand where v_max_bitrate comes from, as it seems to be passed to start_stream in the dictionary stream_config here.

Is this something that is configurable from configuration.yaml? If I knew where stream_config is coming from I might be able to fix this myself. Can anybody help me?

Thanks!

What version of Home Assistant Core has the issue?

core-2023.9.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

homekit

Link to integration documentation on our website

https://www.home-assistant.io/integrations/homekit/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 11 months ago

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (homekit) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `homekit` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign homekit` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


homekit documentation homekit source (message by IssueLinks)

issue-triage-workflows[bot] commented 8 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment πŸ‘ This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

codyc1515 commented 8 months ago

Still current. It's not at all clear to me why that HomeKit cameras are deliberately downgrade in quality.

issue-triage-workflows[bot] commented 5 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment πŸ‘ This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

codyc1515 commented 5 months ago

Current

bdraco commented 5 months ago

iOS is going to request a lower bit rate based on the connection. While you can override it and force a better bitrate its likely going to break streaming for users with slower connections if we did that.

duhanebel commented 3 months ago

That makes sense.. but in my experience with other cameras, the streaming starts on a low bitrate and slowly improves (if there's bandwidth). I don't see the same behaviour with HA.

issue-triage-workflows[bot] commented 3 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment πŸ‘ This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

codyc1515 commented 3 weeks ago

Current