WebRTC icon indicating copy to clipboard operation
WebRTC copied to clipboard

Correct Camera Stream to 16:9

Open sumur1au opened this issue 4 years ago • 31 comments

The stream is displayed in 4:3 when the camera records in 16:9 is it possible to correct the aspect ratio in the configuration card?

sumur1au avatar Apr 19 '21 01:04 sumur1au

iPhone?

AlexxIT avatar Apr 19 '21 04:04 AlexxIT

Chrome on Windows and Android

On Mon, Apr 19, 2021 at 2:11 PM Alex X @.***> wrote:

iPhone?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AlexxIT/WebRTC/issues/21#issuecomment-822152464, or unsubscribe https://github.com/notifications/unsubscribe-auth/APXG5UU7GPAH6IRUTAKO7DLTJOUOXANCNFSM43E2U42Q .

sumur1au avatar Apr 19 '21 04:04 sumur1au

Please show screen. You may blur image.

AlexxIT avatar Apr 19 '21 04:04 AlexxIT

Camera Stream

This is the steam from the WebRTC addon

sumur1au avatar Apr 23 '21 09:04 sumur1au

It seems to be displayed correctly. Or is the picture compressed horizontally?

AlexxIT avatar Apr 23 '21 13:04 AlexxIT

The picture is compressed, it should be spread vertically.

On Fri, Apr 23, 2021 at 11:52 PM Alex X @.***> wrote:

It seems to be displayed correctly. Or is the picture compressed horizontally?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AlexxIT/WebRTC/issues/21#issuecomment-825673937, or unsubscribe https://github.com/notifications/unsubscribe-auth/APXG5UTLQASP2RLCT6UPNLLTKF3SNANCNFSM43E2U42Q .

sumur1au avatar Apr 26 '21 00:04 sumur1au

I have the same with a RTSP stream from a Reolink camera.

giggo avatar May 13 '21 22:05 giggo

Does the stream out of the camera have the right aspect ratio? I had to adjust my substream from 640x480 to 640x360 to get 16:9 aspect ratio...

kp-bit avatar May 20 '21 06:05 kp-bit

I'm using a hikvision camera and WebRTC stretches the image to 4:3. The same rtsp URL shows the correct aspect ratio in VLC. I'm using Chrome on Windows and the Home Assistant app on Android. Both show the same vertically stretched stream.

brianewman avatar May 20 '21 22:05 brianewman

Here is the same camera feed in a picture-entity card (top) and a WebRTC card (bottom). Screenshot 2021-05-20 180027

brianewman avatar May 20 '21 23:05 brianewman

I have the same problem. in VLC, the stream is displayed correctly as 16: 9. Just like brianewman

majdzik84 avatar Jul 06 '21 19:07 majdzik84

Any ideas how to get the correct 16: 9 format?

majdzik84 avatar Aug 05 '21 15:08 majdzik84

Same Here :( Add option to change Resolutions of source image!

When i change from 1080N to 960H is all 16:9 now, but is in lower res :/

JaCoLJcL avatar Aug 10 '21 21:08 JaCoLJcL

@AlexxIT Will this help with the scaling problem?

https://www.home-assistant.io/blog/2021/09/01/release-20219/ image

majdzik84 avatar Sep 01 '21 20:09 majdzik84

I think this is some problem with camera codec. But on my cameras the problem does not happen, I can't debug.

AlexxIT avatar Sep 02 '21 14:09 AlexxIT

Have this problem with my Amcrest camera too. I've tried various card-mod CSS styles to no avail. Anyone else try Card mod? padding-top 56.25% !important; and aspect-ratio: 1.77 !important;

mckochan avatar Sep 05 '21 21:09 mckochan

Can someone provide public access to their RTSP-stream? You can send link in private message in Telegram @AlexxIT or Hass community

AlexxIT avatar Sep 06 '21 07:09 AlexxIT

Can anyone share the stream? I've been struggling with it for 3 hours but unfortunately something is wrong with me. (My network is shared and I have some limitations). If someone sends a stream to Alex, please let me know so I don't get tired :)

majdzik84 avatar Sep 06 '21 11:09 majdzik84

Thanks to @majdzik84 - I found the problem

Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 640x480 [SAR 4:3 DAR 16:9], 15 fps, 100 tbr, 90k tbn, 30 tbc

Component doesn't supported display aspect ratio. And shows picture in original size. I will try to find a solution.

AlexxIT avatar Sep 13 '21 13:09 AlexxIT

I keep my fingers crossed for it to succeed :)

majdzik84 avatar Sep 13 '21 14:09 majdzik84

Seems like WebRTC doesn't support pixel aspect ratio. Need a JavaScript developer who can stretch the video manually in the browser.

https://chromium.googlesource.com/external/webrtc/+/HEAD/common_video/h264/sps_parser.cc#222

AlexxIT avatar Sep 14 '21 13:09 AlexxIT

Should be a way to just force an aspect ratio for the card and the video will follow, or are you saying then the video will just crop? Default picture_entity card has aspect_ratio setting as does https://github.com/custom-cards/button-card#aspect-ratio

mckochan avatar Sep 14 '21 14:09 mckochan

Should be a way to just force an aspect ratio for the card and the video will follow, or are you saying then the video will just crop? Default picture_entity card has aspect_ratio setting as does https://github.com/custom-cards/button-card#aspect-ratio

Would love to see something like this. I have a few WebRTC cards within a swipe card to flip through my security cameras. One of the cameras is a 4:3 doorbell while the rest are 16:9. I'm being nitpicky but being able to force 16:9 would fix the spacing on my dashboard. :)

saxopwn avatar Oct 24 '21 02:10 saxopwn

I recently opened #227, but it seems like it might be related to this. Is there anyone that experiences this problem who also sees the video frame being cropped on the HomeAssistant iOS app? It shows fine on the desktop (albeit with the wrong aspect ratio), but on iOS part of the video is actually cropped off the sides which makes the card unusable.

kspearrin avatar Dec 23 '21 15:12 kspearrin

Found here, needs lovelace-card-mod, and this little modification.

Can be used to set ratio to 16:9:

style: |
  ha-card {
    --height-cctv: calc(28vh - 40px);
    --width-cctv: calc(var(--height-cctv) / 9 * 16);
    height: var(--height-cctv);
    width: var(--width-cctv);
  }

Has two issues:

  • sets the card size static (acceptable), can be adjusted by changing 28vh parameter
  • renders the full screen function incorrect from ui option. Can go fullscreen from html5 player controls though.

nagyrobi avatar Jan 08 '22 19:01 nagyrobi

@AlexxIT what was the solution? Are we still awaiting a JavaScript developer?

davros123 avatar Apr 13 '22 08:04 davros123

With the PR above, and config like below, it will show nice (tested on Hikvision secondary streams):

  - type: custom:webrtc-camera
    url: >-
      rtsp://user:[email protected]:554/Streaming/Channels/202
    poster: http://192.168.2.10:8123/local/pub/HA_cam_poster3.png
    style: |
      ha-card {
        --height-cctv: calc(32vh - 40px);
        --width-cctv: calc(var(--height-cctv) / 9 * 16);
        height: var(--height-cctv);
        width: var(--width-cctv);
      }
    shortcuts:
      - name: Camera Light Switch
        icon: mdi:track-light
        service: switch.toggle
        service_data:
          entity_id: switch.camera_lights

nagyrobi avatar Apr 13 '22 15:04 nagyrobi

I would make it even simpler for the final user to customize. Something like the Frigate Hass Card do:

dimensions:
  aspect_ratio_mode: static
  aspect_ratio: '16:9'

felipecrs avatar Apr 13 '22 20:04 felipecrs

With the PR above, and config like below, it will show nice (tested on Hikvision secondary streams):

  - type: custom:webrtc-camera
    url: >-
      rtsp://user:[email protected]:554/Streaming/Channels/202
    poster: http://192.168.2.10:8123/local/pub/HA_cam_poster3.png
    style: |
      ha-card {
        --height-cctv: calc(32vh - 40px);
        --width-cctv: calc(var(--height-cctv) / 9 * 16);
        height: var(--height-cctv);
        width: var(--width-cctv);
      }
    shortcuts:
      - name: Camera Light Switch
        icon: mdi:track-light
        service: switch.toggle
        service_data:
          entity_id: switch.camera_lights

does this still work for you? I made the changes and it is still a 4:3 stream using the rtc card

jodyalbritton avatar Sep 13 '22 17:09 jodyalbritton

Yes it works fine here. Clear cache, restart browser.

nagyrobi avatar Sep 13 '22 17:09 nagyrobi