viseron icon indicating copy to clipboard operation
viseron copied to clipboard

Issue with vf transpose in Recorder

Open olekenneth opened this issue 2 years ago • 11 comments

Since my camera is mounted sideways I have to rotate the image. After a lot of trail and an error I found out how to do with with this config:

recorder:
  lookback: 3
  timeout: 3
  retain: 7
  filter_args:
    - '-vf'
    - "transpose=2"
Rest of config
...
object_detection:
  type: darknet
  labels:
    - label: person
      confidence: 0.9
    - label: truck
      confidence: 0.9
    - label: car
      confidence: 0.9

mqtt:
 # redacted

logging:
  level: debug

cameras:
  - name: Ute
    mqtt_name: ute
    host: 192.168.0.x
    port: 554
    username: admin
    password: "..."
    path: '/h264'
    height: 2592
    width: 1944
    fps: 5
    audio_codec: aac
    publish_image: true
    filter_args:
      - '-vf'
      - "transpose=2"
    object_detection:
      interval: .2
      mask:
        - points:
          - x: 7
            y: 515
          - x: 152
            y: 453
          - x: 101
            y: 403
          - x: 30
            y: 445
    substream:
      path: '/h264cif'
      port: 554
      height: 704
      width: 576
      fps: 5
      filter_args:
        - '-vf'
        - "transpose=2"
    static_mjpeg_streams:
      small:
        width: 100
        height: 100

But after the motion and object detection has run I get this error and no mp4-file.

file 'file:/segments/Ute/20211123140136.mp4'
file 'file:/segments/Ute/20211123140148.mp4'
file 'file:/segments/Ute/20211123140200.mp4'
file 'file:/segments/Ute/20211123140212.mp4'
outpoint 5
Filtergraph 'transpose=2' was defined for video output stream 0:0 but codec copy was selected.
Filtering and streamcopy cannot be used together.
[2021-11-23 14:02:46] [ERROR   ] [viseron.recorder.ute    ] - Failed to concatenate segments: Command '['ffmpeg', '-hide_banne\
r', '-loglevel', 'error', '-y',
'-protocol_whitelist', 'file,pipe', '-f', 'concat', '-safe', '0', '-i', '-', '-c:v', 'copy', '-c:a', 'copy', '-vf', 'transpose\
=2', '-movflags', '+faststart',
'/recordings/2021-11-23/Ute/11:49:43.mp4']' returned non-zero exit status 1.

If I remove the -vf transpose=2 from the recorder it works, but then my recording is stored with the original format (sideways)

olekenneth avatar Nov 23 '21 15:11 olekenneth

You can probably solve this by adding a codec like h264 to your recorder config.

roflcoopter avatar Nov 25 '21 06:11 roflcoopter

Ok, let me try that. But also now that I have more than one camera, I really would need to specify this per camera level and not the global recorder:

olekenneth avatar Nov 26 '21 12:11 olekenneth

That is coming in the next release. I am working on a huge rewrite of Viseron entirely, thats why there has not been any releases in a while.

It focuses on decoupling things, making it super easy to implement new functionality using components similar to Home Assistant if you are familiar with that

roflcoopter avatar Nov 26 '21 13:11 roflcoopter

That's awesome to hear. I'm very familiar with Home Assistant, so that seems like a good approach.

You might also consider to hot reload the config for faster change time.

And while we talk about feature requests, I really would love to control the states from MQTT/Home Assistant. At the moment, since my camera is overlooking the driveway where I park my cars, it never stops recording. So for me - since I have the rule engine/state machine/automation engine in HA, I could automate start/stop based on motion sensors or when the person is not detected anymore.

olekenneth avatar Nov 26 '21 14:11 olekenneth

You can kinda do this already by using require_motion on the tracked label. By using that, stationary objects, like parked cars, wont keep the recorder going forever.

You can also use the MQTT switch enity in Home Assistant to completely shut off a camera, bascially disarming it until you turn it back on again

roflcoopter avatar Nov 26 '21 15:11 roflcoopter

So back to the first problem. Did what you said with setting the codec, but now I getting the container killed. See logs:

[2021-11-26 19:33:41] [DEBUG   ] [viseron.nvr.ute         ] - Not recording, pausing object detector
[2021-11-26 19:33:41] [DEBUG   ] [viseron.nvr.ute.object  ] - Objects: [{'label': 'car', 'confidence': 0.991, 'rel_width': 0.457, 'rel_height': 0.375, 'rel_x1': 0.173, 'rel_y1': 0.541, 'rel_x2': 0.63, 'rel_y2': 0.916}, {'label': 'car', 'confidence': 0.982, 'rel_width': 0.314, 'rel_height': 0.162, 'rel_x1': 0.505, 'rel_y1': 0.507, 'rel_x2': 0.819, 'rel_y2': 0.669}]
[2021-11-26 19:33:45] [DEBUG   ] [viseron.recorder.ute    ] - /segments/Ute/20211126193340.mp4 is locked. Trying again in 1 second, message repeated 5 times
[2021-11-26 19:33:47] [DEBUG   ] [viseron.recorder.ute    ] - Segment information: {'20211126193328.mp4': {'start_time': 1637951608.0, 'end_time': 1637951614.081}, '20211126193252.mp4': {'start_time': 1637951572.0, 'end_time': 1637951578.002}, '20211126193304.mp4': {'start_time': 1637951584.0, 'end_time': 1637951590.207}, '20211126193258.mp4': {'start_time': 1637951578.0, 'end_time': 1637951584.007}, '20211126193340.mp4': {'start_time': 1637951620.0, 'end_time': 1637951626.071}, '20211126193316.mp4': {'start_time': 1637951596.0, 'end_time': 1637951602.027}, '20211126193334.mp4': {'start_time': 1637951614.0, 'end_time': 1637951620.153}, '20211126193310.mp4': {'start_time': 1637951590.0, 'end_time': 1637951596.089}, '20211126193322.mp4': {'start_time': 1637951602.0, 'end_time': 1637951608.089}}
[2021-11-26 19:33:47] [DEBUG   ] [viseron.recorder.ute    ] - Start event: 1637951582, segment: 20211126193258.mp4
[2021-11-26 19:33:47] [DEBUG   ] [viseron.recorder.ute    ] - End event: 1637951620, segment: 20211126193340.mp4
[2021-11-26 19:33:47] [DEBUG   ] [viseron.recorder.ute    ] - Concatenation command: ['ffmpeg', '-hide_banner', '-loglevel', 'error', '-y', '-protocol_whitelist', 'file,pipe', '-f', 'concat', '-safe', '0', '-i', '-', '-c:v', 'h264', '-c:a', 'copy', '-vf', 'transpose=2', '-movflags', '+faststart', '/recordings/2021-11-26/Ute/19:33:17.mp4']
[2021-11-26 19:33:47] [DEBUG   ] [viseron.recorder.ute    ] - Segment script:
file 'file:/segments/Ute/20211126193258.mp4'
inpoint 4
file 'file:/segments/Ute/20211126193304.mp4'
file 'file:/segments/Ute/20211126193310.mp4'
file 'file:/segments/Ute/20211126193316.mp4'
file 'file:/segments/Ute/20211126193322.mp4'
file 'file:/segments/Ute/20211126193328.mp4'
file 'file:/segments/Ute/20211126193334.mp4'
file 'file:/segments/Ute/20211126193340.mp4'
outpoint 0
./run: line 10:   343 Killed                  justc-envdir /var/run/environment exec s6-setuidgid abc python3 -u -m viseron
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

olekenneth avatar Nov 26 '21 18:11 olekenneth

Kind of odd, will see if i can fix it in #306

roflcoopter avatar Dec 08 '21 09:12 roflcoopter

Tried this on the current release of V2 (roflcoopter/viseron:modularize) and it works as expected for me with this config:

ffmpeg:
  camera:
    camera_1:
      name: Camera 1
      ......
      recorder:
        codec: h264
        filter_args:
          - -vf
          - transpose=2

No crashes or anything. What do you think, can i close this one?

roflcoopter avatar Mar 03 '22 13:03 roflcoopter

image

Trying out the v2 and I got my two cameras running. But trying to rotate the camera didn't work just yet.

ffmpeg: # <-- component
  camera: # <-- domain
    camera_one: #
       ...
       name: Dome
       audio_codec: aac
       height: 2592
       width: 1944
       fps: 5
       filter_args:
         - '-vf'
         - "transpose=2"

olekenneth avatar Mar 04 '22 19:03 olekenneth

image

Trying out the v2 and I got my two cameras running. But trying to rotate the camera didn't work just yet.

ffmpeg: # <-- component
  camera: # <-- domain
    camera_one: #
       ...
       name: Dome
       audio_codec: aac
       height: 2592
       width: 1944
       fps: 5
       filter_args:
         - '-vf'
         - "transpose=2"

Woa that looks odd! Where is that picture from?

roflcoopter avatar Mar 05 '22 11:03 roflcoopter

When I add the mog2 or darknet, the video filter I'm using (-vf transpose=2) gets overwritten.

 [2022-03-05 13:50:24] [DEBUG   ] [viseron.components.ffmpeg.stream.camera_one] - FFmpeg decoder command: ffmpeg_camera_one -hide_banner -loglevel error -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -use_wallclock_as_timestamps 1 -vsync 0 -stimeout 5000000 -c:v h264_cuvid -rtsp_transport tcp -i rtsp://*****:*****@192.168.0.x:554/h264?username=xxxx&password=xxxx -f segment -segment_time 5 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac /segments/camera_one/%Y%m%d%H%M%S.mp4 -vf transpose=2 -filter:v fps=1.0 -f rawvideo -pix_fmt nv12 pipe:1

Config

mog2:
  motion_detector:
    cameras:
      camera_one:
        fps: 1

olekenneth avatar Mar 05 '22 15:03 olekenneth

Closed in v2

roflcoopter avatar Dec 19 '22 14:12 roflcoopter