mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Add static FFmpeg with rockchip hardware acceleration to rk- image (#8599)
* add static ffmpeg with rockchip hw accel * add ffmpeg presets * fix scaling preset and update docs for rk hwaccel * update usage info in ffmpeg_presets docs * Add note about hardware acceleration support --------- Co-authored-by: MarcA711 <>
This commit is contained in:
parent
266b4099b5
commit
8c7f6d4a76
@ -6,12 +6,13 @@ ARG DEBIAN_FRONTEND=noninteractive
|
|||||||
FROM wheels as rk-wheels
|
FROM wheels as rk-wheels
|
||||||
COPY docker/main/requirements-wheels.txt /requirements-wheels.txt
|
COPY docker/main/requirements-wheels.txt /requirements-wheels.txt
|
||||||
COPY docker/rockchip/requirements-wheels-rk.txt /requirements-wheels-rk.txt
|
COPY docker/rockchip/requirements-wheels-rk.txt /requirements-wheels-rk.txt
|
||||||
RUN sed -i "/https/d" /requirements-wheels.txt
|
RUN sed -i "/https:\/\//d" /requirements-wheels.txt
|
||||||
RUN pip3 wheel --wheel-dir=/rk-wheels -c /requirements-wheels.txt -r /requirements-wheels-rk.txt
|
RUN pip3 wheel --wheel-dir=/rk-wheels -c /requirements-wheels.txt -r /requirements-wheels-rk.txt
|
||||||
|
|
||||||
FROM wget as rk-libs
|
FROM wget as rk-libs
|
||||||
RUN wget -qO librknnrt.so https://github.com/MarcA711/rknpu2/raw/master/runtime/RK3588/Linux/librknn_api/aarch64/librknnrt.so
|
RUN wget -qO librknnrt.so https://github.com/MarcA711/rknpu2/raw/master/runtime/RK3588/Linux/librknn_api/aarch64/librknnrt.so
|
||||||
|
RUN wget -qO ffmpeg https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/latest/ffmpeg
|
||||||
|
RUN wget -qO ffprobe https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/latest/ffprobe
|
||||||
FROM deps AS rk-deps
|
FROM deps AS rk-deps
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
|
|
||||||
@ -21,4 +22,11 @@ RUN --mount=type=bind,from=rk-wheels,source=/rk-wheels,target=/deps/rk-wheels \
|
|||||||
WORKDIR /opt/frigate/
|
WORKDIR /opt/frigate/
|
||||||
COPY --from=rootfs / /
|
COPY --from=rootfs / /
|
||||||
COPY --from=rk-libs /rootfs/librknnrt.so /usr/lib/
|
COPY --from=rk-libs /rootfs/librknnrt.so /usr/lib/
|
||||||
COPY docker/rockchip/yolov8n-320x320.rknn /models/
|
COPY docker/rockchip/yolov8n-320x320.rknn /models/
|
||||||
|
|
||||||
|
RUN rm -rf /usr/lib/btbn-ffmpeg/bin/ffmpeg
|
||||||
|
RUN rm -rf /usr/lib/btbn-ffmpeg/bin/ffprobe
|
||||||
|
COPY --from=rk-libs /rootfs/ffmpeg /usr/lib/btbn-ffmpeg/bin/
|
||||||
|
COPY --from=rk-libs /rootfs/ffprobe /usr/lib/btbn-ffmpeg/bin/
|
||||||
|
RUN chmod +x /usr/lib/btbn-ffmpeg/bin/ffmpeg
|
||||||
|
RUN chmod +x /usr/lib/btbn-ffmpeg/bin/ffprobe
|
||||||
|
@ -22,6 +22,8 @@ See [the hwaccel docs](/configuration/hardware_acceleration.md) for more info on
|
|||||||
| preset-nvidia-mjpeg | Nvidia GPU with mjpeg stream | Recommend restreaming mjpeg and using nvidia-h264 |
|
| preset-nvidia-mjpeg | Nvidia GPU with mjpeg stream | Recommend restreaming mjpeg and using nvidia-h264 |
|
||||||
| preset-jetson-h264 | Nvidia Jetson with h264 stream | |
|
| preset-jetson-h264 | Nvidia Jetson with h264 stream | |
|
||||||
| preset-jetson-h265 | Nvidia Jetson with h265 stream | |
|
| preset-jetson-h265 | Nvidia Jetson with h265 stream | |
|
||||||
|
| preset-rk-h264 | Rockchip MPP with h264 stream | Use image with *-rk suffix and privileged mode |
|
||||||
|
| preset-rk-h265 | Rockchip MPP with h265 stream | Use image with *-rk suffix and privileged mode |
|
||||||
|
|
||||||
### Input Args Presets
|
### Input Args Presets
|
||||||
|
|
||||||
|
@ -319,3 +319,31 @@ ffmpeg:
|
|||||||
If everything is working correctly, you should see a significant reduction in ffmpeg CPU load and power consumption.
|
If everything is working correctly, you should see a significant reduction in ffmpeg CPU load and power consumption.
|
||||||
Verify that hardware decoding is working by running `jtop` (`sudo pip3 install -U jetson-stats`), which should show
|
Verify that hardware decoding is working by running `jtop` (`sudo pip3 install -U jetson-stats`), which should show
|
||||||
that NVDEC/NVDEC1 are in use.
|
that NVDEC/NVDEC1 are in use.
|
||||||
|
|
||||||
|
## Rockchip platform
|
||||||
|
|
||||||
|
Hardware accelerated video de-/encoding is supported on all Rockchip SoCs.
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
Use a frigate docker image with `-rk` suffix and enable privileged mode by adding the `--privileged` flag to your docker run command or `privileged: true` to your `docker-compose.yml` file.
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
Add one of the following ffmpeg presets to your `config.yaml` to enable hardware acceleration:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# if you try to decode a h264 encoded stream
|
||||||
|
ffmpeg:
|
||||||
|
hwaccel_args: preset-rk-h264
|
||||||
|
|
||||||
|
# if you try to decode a h265 (hevc) encoded stream
|
||||||
|
ffmpeg:
|
||||||
|
hwaccel_args: preset-rk-h265
|
||||||
|
```
|
||||||
|
|
||||||
|
:::note
|
||||||
|
|
||||||
|
Make sure that your SoC supports hardware acceleration for your input stream. For example, if your camera streams with h265 encoding and a 4k resolution, your SoC must be able to de- and encode h265 with a 4k resolution or higher. If you are unsure whether your SoC meets the requirements, take a look at the datasheet.
|
||||||
|
|
||||||
|
:::
|
||||||
|
@ -64,6 +64,8 @@ PRESETS_HW_ACCEL_DECODE = {
|
|||||||
"preset-nvidia-mjpeg": "-hwaccel cuda -hwaccel_output_format cuda",
|
"preset-nvidia-mjpeg": "-hwaccel cuda -hwaccel_output_format cuda",
|
||||||
"preset-jetson-h264": "-c:v h264_nvmpi -resize {1}x{2}",
|
"preset-jetson-h264": "-c:v h264_nvmpi -resize {1}x{2}",
|
||||||
"preset-jetson-h265": "-c:v hevc_nvmpi -resize {1}x{2}",
|
"preset-jetson-h265": "-c:v hevc_nvmpi -resize {1}x{2}",
|
||||||
|
"preset-rk-h264": "-c:v h264_rkmpp_decoder",
|
||||||
|
"preset-rk-h265": "-c:v hevc_rkmpp_decoder",
|
||||||
}
|
}
|
||||||
|
|
||||||
PRESETS_HW_ACCEL_SCALE = {
|
PRESETS_HW_ACCEL_SCALE = {
|
||||||
@ -75,6 +77,8 @@ PRESETS_HW_ACCEL_SCALE = {
|
|||||||
"preset-nvidia-h265": "-r {0} -vf fps={0},scale_cuda=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
"preset-nvidia-h265": "-r {0} -vf fps={0},scale_cuda=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
||||||
"preset-jetson-h264": "-r {0}", # scaled in decoder
|
"preset-jetson-h264": "-r {0}", # scaled in decoder
|
||||||
"preset-jetson-h265": "-r {0}", # scaled in decoder
|
"preset-jetson-h265": "-r {0}", # scaled in decoder
|
||||||
|
"preset-rk-h264": "-r {0} -vf fps={0},scale={1}:{2}",
|
||||||
|
"preset-rk-h265": "-r {0} -vf fps={0},scale={1}:{2}",
|
||||||
"default": "-r {0} -vf fps={0},scale={1}:{2}",
|
"default": "-r {0} -vf fps={0},scale={1}:{2}",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +91,8 @@ PRESETS_HW_ACCEL_ENCODE_BIRDSEYE = {
|
|||||||
"preset-nvidia-h265": "ffmpeg -hide_banner {0} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {1}",
|
"preset-nvidia-h265": "ffmpeg -hide_banner {0} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {1}",
|
||||||
"preset-jetson-h264": "ffmpeg -hide_banner {0} -c:v h264_nvmpi -profile high {1}",
|
"preset-jetson-h264": "ffmpeg -hide_banner {0} -c:v h264_nvmpi -profile high {1}",
|
||||||
"preset-jetson-h265": "ffmpeg -hide_banner {0} -c:v h264_nvmpi -profile high {1}",
|
"preset-jetson-h265": "ffmpeg -hide_banner {0} -c:v h264_nvmpi -profile high {1}",
|
||||||
|
"preset-rk-h264": "ffmpeg -hide_banner {0} -c:v h264_rkmpp_encoder -profile high {1}",
|
||||||
|
"preset-rk-h265": "ffmpeg -hide_banner {0} -c:v hevc_rkmpp_encoder -profile high {1}",
|
||||||
"default": "ffmpeg -hide_banner {0} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {1}",
|
"default": "ffmpeg -hide_banner {0} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {1}",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +105,8 @@ PRESETS_HW_ACCEL_ENCODE_TIMELAPSE = {
|
|||||||
"preset-nvidia-h265": "ffmpeg -hide_banner -hwaccel cuda -hwaccel_output_format cuda -extra_hw_frames 8 {0} -c:v hevc_nvenc {1}",
|
"preset-nvidia-h265": "ffmpeg -hide_banner -hwaccel cuda -hwaccel_output_format cuda -extra_hw_frames 8 {0} -c:v hevc_nvenc {1}",
|
||||||
"preset-jetson-h264": "ffmpeg -hide_banner {0} -c:v h264_nvmpi -profile high {1}",
|
"preset-jetson-h264": "ffmpeg -hide_banner {0} -c:v h264_nvmpi -profile high {1}",
|
||||||
"preset-jetson-h265": "ffmpeg -hide_banner {0} -c:v hevc_nvmpi -profile high {1}",
|
"preset-jetson-h265": "ffmpeg -hide_banner {0} -c:v hevc_nvmpi -profile high {1}",
|
||||||
|
"preset-rk-h264": "ffmpeg -hide_banner {0} -c:v h264_rkmpp_encoder -profile high {1}",
|
||||||
|
"preset-rk-h265": "ffmpeg -hide_banner {0} -c:v hevc_rkmpp_encoder -profile high {1}",
|
||||||
"default": "ffmpeg -hide_banner {0} -c:v libx264 -preset:v ultrafast -tune:v zerolatency {1}",
|
"default": "ffmpeg -hide_banner {0} -c:v libx264 -preset:v ultrafast -tune:v zerolatency {1}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user