save_clips doesnt work with rtmp stream from reolink
See original GitHub issueDescribe the bug ffmpeg can not handle the rtmp stream from my reolink camera and it appears to be related to the “-map 0” option appended as part of save clips.
Searching for that “moov atom not found” error led me to this vague question/answer: https://www.gitmemory.com/issue/blakeblackshear/frigate/251/715437715 Where they suggested removing save_clips and specifically -map 0. Removing -map 0 from the manual running of the command line option seems to at least let ffmpeg run.
If I run the ffmpeg command on my host PC it works flawlessly but if I connect to the docker container and run it there I get the following:
root@3362fbed6b1d:/opt/frigate# ffmpeg -hide_banner -loglevel debug -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0\&stream=0\&user=admin\&password=************ -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c copy -an -map 0 /cache/front-%Y%m%d%H%M%S.mp4 -r 20 -f rawvideo -pix_fmt yuv420p pipe:
Splitting the commandline.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-avoid_negative_ts' ... matched as AVOption 'avoid_negative_ts' with argument 'make_zero'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument 'nobuffer'.
Reading option '-flags' ... matched as AVOption 'flags' with argument 'low_delay'.
Reading option '-strict' ...Routing option strict to both codec and muxer layer
matched as AVOption 'strict' with argument 'experimental'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument '+genpts+discardcorrupt'.
Reading option '-use_wallclock_as_timestamps' ... matched as AVOption 'use_wallclock_as_timestamps' with argument '1'.
Reading option '-i' ... matched as input url with argument 'rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=*************'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'segment'.
Reading option '-segment_time' ... matched as AVOption 'segment_time' with argument '10'.
Reading option '-segment_format' ... matched as AVOption 'segment_format' with argument 'mp4'.
Reading option '-reset_timestamps' ... matched as AVOption 'reset_timestamps' with argument '1'.
Reading option '-strftime' ... matched as AVOption 'strftime' with argument '1'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-an' ... matched as option 'an' (disable audio) with argument '1'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0'.
Reading option '/cache/front-%Y%m%d%H%M%S.mp4' ... matched as output url.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '20'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'rawvideo'.
Reading option '-pix_fmt' ... matched as option 'pix_fmt' (set pixel format) with argument 'yuv420p'.
Reading option 'pipe:' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option hide_banner (do not show program banner) with argument 1.
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=***********.
Successfully parsed a group of options.
Opening an input file: rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=*************.
[NULL @ 0x555f97141c80] Opening 'rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=*************' for reading
[rtmp @ 0x555f971429c0] No default whitelist set
[tcp @ 0x555f97143280] No default whitelist set
[tcp @ 0x555f97143280] Original list of addresses:
[tcp @ 0x555f97143280] Address 192.168.1.240 port 1935
[tcp @ 0x555f97143280] Interleaved list of addresses:
[tcp @ 0x555f97143280] Address 192.168.1.240 port 1935
[tcp @ 0x555f97143280] Starting connection attempt to 192.168.1.240 port 1935
[tcp @ 0x555f97143280] Successfully connected to 192.168.1.240 port 1935
[rtmp @ 0x555f971429c0] Handshaking...
[rtmp @ 0x555f971429c0] Type answer 3
[rtmp @ 0x555f971429c0] Server version 13.14.10.13
[rtmp @ 0x555f971429c0] Proto = rtmp, path = /bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=*********, app = bcs, fname = channel0_main.bcs?channel=0&stream=0&user=admin&password=*********
[rtmp @ 0x555f971429c0] Window acknowledgement size = 5000000
[rtmp @ 0x555f971429c0] Max sent, unacked = 5000000
[rtmp @ 0x555f971429c0] New incoming chunk size = 4096
[rtmp @ 0x555f971429c0] Creating stream...
[rtmp @ 0x555f971429c0] Sending play command for 'channel0_main.bcs?channel=0&stream=0&user=admin&password=**************'
[flv @ 0x555f97141c80] Format flv probed with size=2048 and score=100
[flv @ 0x555f97141c80] Before avformat_find_stream_info() pos: 13 bytes read:33088 seeks:0 nb_streams:0
[flv @ 0x555f97141c80] Unknown type |RtmpSampleAccess
[NULL @ 0x555f97147800] nal_unit_type: 7(SPS), nal_ref_idc: 3
[NULL @ 0x555f97147800] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x555f97147800] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x555f97147800] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x555f97147800] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x555f97147800] Format yuv420p chosen by get_format().
[h264 @ 0x555f97147800] Reinit context to 2560x1920, pix_fmt: yuv420p
[h264 @ 0x555f97147800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
Last message repeated 5 times
[flv @ 0x555f97141c80] Non-increasing DTS in stream 2: packet 4 with DTS 1606534904907, packet 5 with DTS 1606534904907
[flv @ 0x555f97141c80] All info found
[flv @ 0x555f97141c80] After avformat_find_stream_info() pos: 1974122 bytes read:1974122 seeks:0 frames:73
Input #0, flv, from 'rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=************':
Metadata:
displayWidth : 2560
displayHeight : 1920
Duration: 00:00:00.00, start: 1606534904.811000, bitrate: N/A
Stream #0:0, 1, 1/1000: Data: none, 0/1
Stream #0:1, 41, 1/1000: Video: h264, 1 reference frame, yuv420p(progressive), 2560x1920, 0/1, 20 fps, 1k tbr, 1k tbn
Stream #0:2, 31, 1/1000: Audio: aac, 16000 Hz, mono, fltp
Successfully opened the file.
Parsing a group of options: output url /cache/front-%Y%m%d%H%M%S.mp4.
Applying option f (force format) with argument segment.
Applying option c (codec name) with argument copy.
Applying option an (disable audio) with argument 1.
Applying option map (set input stream mapping) with argument 0.
Successfully parsed a group of options.
Opening an output file: /cache/front-%Y%m%d%H%M%S.mp4.
Successfully opened the file.
Parsing a group of options: output url pipe:.
Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 20.
Applying option f (force format) with argument rawvideo.
Applying option pix_fmt (set pixel format) with argument yuv420p.
Successfully parsed a group of options.
Opening an output file: pipe:.
[pipe @ 0x555f9714b9c0] Setting default whitelist 'crypto,data'
Successfully opened the file.
detected 8 logical cores
[h264 @ 0x555f971f4000] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x555f971f4000] nal_unit_type: 8(PPS), nal_ref_idc: 3
[segment @ 0x555f9714bf00] Selected stream id:1 type:video
[segment @ 0x555f9714bf00] Opening '/cache/front-20201128164146.mp4' for writing
[file @ 0x555f971ea7c0] Setting default whitelist 'file,crypto,data'
[mp4 @ 0x555f971ef680] Could not find tag for codec none in stream #0, codec not currently supported in container
[AVIOContext @ 0x555f971eaa00] Statistics: 0 seeks, 0 writeouts
**Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument**
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #0:1 -> #1:0 (h264 (native) -> rawvideo (native))
Last message repeated 1 times
[AVIOContext @ 0x555f97155e40] Statistics: 0 seeks, 0 writeouts
[AVIOContext @ 0x555f97145380] Statistics: 1974122 bytes read, 0 seeks
[rtmp @ 0x555f971429c0] Deleting stream...
And from the host this is abouut the same place where it fails in docker (stream mapping appears different):
[segment @ 0x55a5e39eb480] Selected stream id:0 type:video
[segment @ 0x55a5e39eb480] Opening '/cache/front-20201128165213.mp4' for writing
[file @ 0x55a5e3ad0a00] Setting default whitelist 'file,crypto'
Output #0, segment, to '/cache/front-%Y%m%d%H%M%S.mp4':
Metadata:
displayWidth : 2560
displayHeight : 1920
encoder : Lavf58.20.100
Stream #0:0, 0, 1/16000: Video: h264 (Baseline), 1 reference frame, yuv420p(progressive, left), 2560x1920 (0x0), 0/1, q=2-31, 20 fps, 1k tbr, 16k tbn, 1k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:0 -> #1:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
Last message repeated 1 times
[h264 @ 0x55a5e3a79400] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0x55a5e3a79400] Format yuv420p chosen by get_format().
[h264 @ 0x55a5e3a79400] Reinit context to 2560x1920, pix_fmt: yuv420p
Version of frigate 0.7.3-amd64 (docker stack)
Config file Include your full config file wrapped in triple back ticks.
web_port: 5000
################
## Tell frigate to look for a specific EdgeTPU device. Useful if you want to run multiple instances of frigate
## on the same machine with multiple EdgeTPUs. https://coral.ai/docs/edgetpu/multiple-edgetpu/#using-the-tensorflow-lite-python-api
################
detectors:
coral:
type: edgetpu
device: pci:0
#tensorflow_device: pci:0
mqtt:
host: 192.168.1.100
#port: 1883
topic_prefix: frigate
client_id: frigate # Optional -- set to override default client id of 'frigate' if running multiple instances
user: mqtt # Optional
#################
## Environment variables that begin with 'FRIGATE_' may be referenced in {}.
## password: '{FRIGATE_MQTT_PASSWORD}'
#################
password: '{FRIGATE_MQTT_PASSWORD}' # Optional
################
# Global configuration for saving clips
################
save_clips:
###########
# Maximum length of time to retain video during long events.
# If an object is being tracked for longer than this amount of time, the cache
# will begin to expire and the resulting clip will be the last x seconds of the event.
###########
max_seconds: 300
#################
# Default ffmpeg args. Optional and can be overwritten per camera.
# Should work with most RTSP cameras that send h264 video
# Built from the properties below with:
# "ffmpeg" + global_args + input_args + "-i" + input + output_args
#################
# ffmpeg:
# global_args:
# - -hide_banner
# - -loglevel
# - panic
# hwaccel_args: []
# input_args:
# - -avoid_negative_ts
# - make_zero
# - -fflags
# - nobuffer
# - -flags
# - low_delay
# - -strict
# - experimental
# - -fflags
# - +genpts+discardcorrupt
# - -vsync
# - drop
# - -rtsp_transport
# - tcp
# - -stimeout
# - '5000000'
# - -use_wallclock_as_timestamps
# - '1'
# output_args:
# - -f
# - rawvideo
# - -pix_fmt
# - rgb24
####################
# Global object configuration. Applies to all cameras
# unless overridden at the camera levels.
# Keys must be valid labels. By default, the model uses coco (https://dl.google.com/coral/canned_models/coco_labels.txt).
# All labels from the model are reported over MQTT. These values are used to filter out false positives.
# min_area (optional): minimum width*height of the bounding box for the detected object
# max_area (optional): maximum width*height of the bounding box for the detected object
# min_score (optional): minimum score for the object to initiate tracking
# threshold (optional): The minimum decimal percentage for tracked object's computed score to considered a true positive
####################
objects:
track:
- person
- car
- truck
- bicycle
- motorcycle
- cat
- dog
- bird
filters:
person:
min_area: 5000
max_area: 100000
min_score: 0.5
threshold: 0.85
cameras:
front:
ffmpeg:
################
# Source passed to ffmpeg after the -i parameter. Supports anything compatible with OpenCV and FFmpeg.
# Environment variables that begin with 'FRIGATE_' may be referenced in {}
################
#input: rtmp://admin:{FRIGATE_RTSP_PASSWORD}@192.168.1.240:554/h264Preview_01_main
input: rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password={FRIGATE_RTSP_PASSWORD}
#################
# These values will override default values for just this camera
#################
global_args:
- -hide_banner
- -loglevel
- panic
input_args:
- -avoid_negative_ts
- make_zero
- -fflags
- nobuffer
- -flags
- low_delay
- -strict
- experimental
- -fflags
- +genpts+discardcorrupt
- -use_wallclock_as_timestamps
- '1'
################
## Optionally specify the resolution of the video feed. Frigate will try to auto detect if not specified
################
width: 2560
height: 1920
################
## Specify the framerate of your camera
##
## NOTE: This should only be set in the event ffmpeg is unable to determine your camera's framerate
## on its own and the reported framerate for your camera in frigate is well over what is expected.
################
fps: 20
################
## Optional mask. Must be the same aspect ratio as your video feed. Value is any of the following:
## - name of a file in the config directory
## - base64 encoded image prefixed with 'base64,' eg. 'base64,asfasdfasdf....'
## - polygon of x,y coordinates prefixed with 'poly,' eg. 'poly,0,900,1080,900,1080,1920,0,1920'
##
## The mask works by looking at the bottom center of the bounding box for the detected
## person in the image. If that pixel in the mask is a black pixel, it ignores it as a
## false positive. In my mask, the grass and driveway visible from my backdoor camera
## are white. The garage doors, sky, and trees (anywhere it would be impossible for a
## person to stand) are black.
##
## Masked areas are also ignored for motion detection.
################
mask: "poly,0,379,0,0,2560,0,2560,528,1975,368,1299,296,844,296,383,345,103,472,93,415,53,422,35,359"
################
# Allows you to limit the framerate within frigate for cameras that do not support
# custom framerates. A value of 1 tells frigate to look at every frame, 2 every 2nd frame,
# 3 every 3rd frame, etc.
################
take_frame: 1
################
# The number of seconds to retain the highest scoring image for the best.jpg endpoint before allowing it
# to be replaced by a newer image. Defaults to 60 seconds.
################
best_image_timeout: 60
################
# MQTT settings
################
mqtt:
crop_to_region: True
snapshot_height: 300
################
# Zones
################
zones:
#################
# Name of the zone
################
front_driveway:
####################
# A list of x,y coordinates to define the polygon of the zone. The top
# left corner is 0,0. Can also be a comma separated string of all x,y coordinates combined.
# The same zone name can exist across multiple cameras if they have overlapping FOVs.
# An object is determined to be in the zone based on whether or not the bottom center
# of it's bounding box is within the polygon. The polygon must have at least 3 points.
# Coordinates can be generated at https://www.image-map.net/
####################
coordinates: "378,787,722,583,1294,294,1980,366,1846,778,1568,1673,2560,1841,2560,1920,0,1920,0,968,82,1011,182,920"
################
# Zone level object filters. These are applied in addition to the global and camera filters
# and should be more restrictive than the global and camera filters. The global and camera
# filters are applied upstream.
################
filters:
person:
min_area: 5000
max_area: 100000
threshold: 0.8
car:
min_area: 5000
max_area: 100000
threshold: 0.7
front_leftlawn:
coordinates: "763,302,380,347,66,487,77,523,0,571,0,966,77,1016,446,740,880,505,1292,295"
filters:
person:
min_area: 5000
max_area: 100000
threshold: 0.8
front_rightlawn:
coordinates: "1982,368,2560,519,2560,1849,1563,1670"
filters:
person:
min_area: 5000
max_area: 100000
threshold: 0.8
################
# This will save a clip for each tracked object by frigate along with a json file that contains
# data related to the tracked object. This works by telling ffmpeg to write video segments to /cache
# from the video stream without re-encoding. Clips are then created by using ffmpeg to merge segments
# without re-encoding. The segments saved are unaltered from what frigate receives to avoid re-encoding.
# They do not contain bounding boxes. These are optimized to capture "false_positive" examples for improving frigate.
#
# NOTE: This feature does not work if you have "-vsync drop" configured in your input params.
# This will only work for camera feeds that can be copied into the mp4 container format without
# encoding such as h264. It may not work for some types of streams.
################
save_clips:
enabled: True
#########
# Number of seconds before the event to include in the clips
#########
pre_capture: 3
#########
# Objects to save clips for. Defaults to all tracked object types.
#########
objects:
- person
- car
################
# Configuration for the snapshots in the debug view and mqtt
################
snapshots:
show_timestamp: True
draw_zones: True
################
# Camera level object config. This config is merged with the global config above.
################
objects:
track:
- person
- car
filters:
person:
min_area: 5000
max_area: 100000
min_score: 0.5
threshold: 0.85
car:
min_area: 5000
max_area: 100000
min_score: 0.5
threshold: 0.7
Logs
eating ffmpeg process...,
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -movflags faststart -i rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=**********-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c copy -an -map 0 /cache/front-%Y%m%d%H%M%S.mp4 -r 20 -f rawvideo -pix_fmt yuv420p pipe:,
front: ffmpeg sent a broken frame. something is wrong.,
front: ffmpeg process is not running. exiting capture thread...,
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55657837d140] moov atom not found,
/cache/front-20201128164146.mp4: Invalid data found when processing input,
bad file: front-20201128164146.mp4,
eating ffmpeg process...,
Frigate debug stats
{"detection_fps":0.0,"detectors":{"coral":{"detection_start":0.0,"inference_speed":10.0,"pid":23}},"front":{"camera_fps":0.0,"capture_pid":24,"detection_fps":0.0,"frame_info":{"detect":0.0,"process":0.0},"pid":25,"process_fps":0.0,"skipped_fps":0.0}}
FFprobe from your camera
Run the following command and paste output below
root@3362fbed6b1d:/opt/frigate# ffprobe rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0\&stream=0\&user=admin\&password=*************
ffprobe version 4.3.1 Copyright (c) 2007-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-fontconfig --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxcb --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-postproc --enable-small --enable-version3 --enable-libbluray --enable-libzmq --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-libopenjpeg --enable-libkvazaar --enable-libaom --extra-libs=-lpthread --enable-vaapi --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, flv, from 'rtmp://192.168.1.240/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=*************':
Metadata:
displayWidth : 2560
displayHeight : 1920
Duration: 00:00:00.00, start: 571549.176000, bitrate: N/A
Stream #0:0: Data: none
Stream #0:1: Video: h264, yuv420p(progressive), 2560x1920, 20 fps, 30 tbr, 1k tbn
Stream #0:2: Audio: aac, 16000 Hz, mono, fltp
Unsupported codec with id 0 for input stream 0
Screenshots N/A
Computer Hardware
- OS: Debian 10.6
- Virtualization: Docker
- Coral Version: m2 PCIe
- Network Setup: Wired Camera Info:
- Manufacturer: Reolink
- Model: RLC-422
- Resolution: 2560x1920
- FPS: 20
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
I have 2 reolink cameras and I was becoming crazy about not recording clips. Thanks a lot. I hope @blakeblackshear will configure a reolink option to keep the code unified. I don’t want to modify the py files everytime I make an update. Thanks to both.
Removing the -map 0 arguments from https://github.com/blakeblackshear/frigate/blob/64b63142b130a2942b318ea4f65de420ebb12332/detect_objects.py#L218..L219 fixes this issue for me.