question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Substreams that stretch the source aspect ratio should output clips of the source aspect ratio

See original GitHub issue

Describe the bug I have a couple of cameras that are running 1920x1080 (or larger, 16:9 aspect ratio). Their substreams output 640x480 of the same view, but that’s a 4:3 aspect ratio. So when a snapshot is created due to detect rule on the substream, the snapshot still ends up stretched because the snapshot is of the substream 640x480.

Example output image: best

What I would prefer to see is the image converted to the aspect ratio of the main source stream: best2

Because the current configuration wants you to set the width and height properties on the main part of the camera but not per ffmpeg input, there isn’t any way to ensure that this happens reliably.

Version of frigate What version are you using? 0.8.0-beta2

Config file Include your full config file wrapped in triple back ticks.

detectors:
  coral:
    type: edgetpu
    device: usb
mqtt:
  host: core-mosquitto.local.hass.io
  user: mqtt
  password: unhook-kick-flabby
ffmpeg:
  hwaccel_args:
    - '-hwaccel'
    - qsv
    - '-qsv_device'
    - /dev/dri/renderD128
cameras:
  front:
    ffmpeg:
      inputs:
        - path: rtsp://<REDACTED>/videoMain
          roles:
            - record
            - clips
        - path: rtsp://<REDACTED>/videoSub
          roles:
            - rtmp
            - detect
    fps: 5
    height: 480
    width: 640
# other cameras redacted
objects:
  track:
    - person
    - dog
    - cat
    - deer
    - bicycle

Logs n/a

Frigate debug stats

{"detection_fps":0.0,"detectors":{"coral":{"detection_start":0.0,"inference_speed":9.17,"pid":51}},"front":{"camera_fps":5.0,"capture_pid":62,"detection_fps":0.0,"pid":56,"process_fps":5.0,"skipped_fps":0.0},"kitchen":{"camera_fps":5.0,"capture_pid":65,"detection_fps":0.0,"pid":58,"process_fps":5.0,"skipped_fps":0.0},"living":{"camera_fps":5.0,"capture_pid":70,"detection_fps":0.0,"pid":60,"process_fps":5.0,"skipped_fps":0.0},"turret":{"camera_fps":5.1,"capture_pid":61,"detection_fps":0.0,"pid":54,"process_fps":5.1,"skipped_fps":0.0}}

FFprobe from your camera

Run the following command and paste output below

$ ffprobe rtsp://<REDACTED>/videoMain
Input #0, rtsp, from 'rtsp://<REDACTED>/videoMain':
  Metadata:
    title           : IP Camera Video
    comment         : videoMain
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuvj420p(pc, progressive), 2304x1536, 90k tbr, 90k tbn, 180k tbc
    Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s

# -------

$ ffprobe rtsp://<REDACTED>/videoSub
Input #0, rtsp, from 'rtsp://<REDACTED>/videoSub':
  Metadata:
    title           : IP Camera Video
    comment         : videoSub
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuvj420p(pc, progressive), 640x480, 20.17 tbr, 90k tbn, 180k tbc
    Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s

Screenshots See bug

Computer Hardware

  • OS: Home Assistant
  • Virtualization: HA Addon (docker)
  • Coral Version: USB
  • Network Setup: WiFi camera

Camera Info:

  • Manufacturer: Foscam, Amcrest
  • Model: Foscam VZ4, Amcrest IP3M-943W
  • Resolution: 640x480 for substream, 2k 3MP for main stream
  • FPS: 5

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:27 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
blakeblackshearcommented, Dec 21, 2020

For RTMP, I would expect the resolution to show 640x480. We are trying to get the RTMP endpoint to behave the same way it does when you connect directly to the camera with VLC. I am sure it shows 640x480 there too, but there is some extra metadata that tells it to stretch the image. If you have to resize the image, you will have to use CPU to re-encode the video again and we are trying to avoid that.

Let’s see if this config fixes the detect stream (mjpeg in frigate).

cameras:
  turret:
    ffmpeg:
      inputs:
        - path: 'rtsp://REDACTED/videoMain'
          roles:
            - record
            - clips
        - path: 'rtsp://REDACTED/videoSub'
          roles:
            - rtmp
            - detect
      output_args:
        detect: -vf scale=720:480 -f rawvideo -pix_fmt yuv420p
        rtmp: -aspect 720:480 -c copy -f flv
    fps: 5
    save_clips:
      enabled: false
    objects:
      track: []
    height: 480
    width: 720
2reactions
scottlambcommented, Dec 21, 2020

+1. For reference, these streams are called anamorphic. All of my cameras are 16:9 and have anamorphic 704x480 sub streams. My Dahua ones declare themselves as such properly in the H.264 VUI parameters. (I don’t remember off the top of my head if there’s a way to get ffprobe to tell you that.) My older Hikvision ones don’t, and so look wrong when I view them in VLC and the like (directly, so not due to any problem with frigate). So some autodetection + knob for manual override might be best.

[edit: Looks like I was partially mistaken about my Dahua cameras doing the right thing. My Dahua IPC-HDW5231R-Z declares its aspect ratio properly (last I checked; it’s not plugged in right now). My brand-new Dahua IPC-HDW5442TP-ZE cameras don’t.]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combine Video Stream, Substream with Different Aspect Ratios
This topic shows how the video stream, video substream, and background color are combined with different aspect ratios.
Read more >
Understanding Aspect Ratio - OBS Studio
You have the option of "stretching" the content to fit, but this will warp and distort the source/image, and is generally not recommended....
Read more >
tencentcloud_vod_adaptive_dyn...
The following fill types are supported: stretch : stretch. The screenshot will be stretched frame by frame to match the aspect ratio of...
Read more >
How to modify the Aspect Ratio of a video in Vegas Pro ...
How to push in the sides of a wide video that was captured in the 4:3 aspect ratio.Instead of 1920 x 1080 use...
Read more >
ffmpeg Documentation
The transcoding process in ffmpeg for each output can be described by the following diagram: ... Set the video display aspect ratio specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found