restreamer
restreamer copied to clipboard
Anyone tried hwaccel vaapi to encode the stream
Hi, first thanks for the work you all put into this. As the title says, did anyone tried transcoding with hwaccel enabled in ffmpeg? I have a synology DS918+ which supports hardware acceleration with device /dev/dri/renderD128 without it the cpu will use up to 25% for one camera stream. Just wanted to know if anyone made progress on this, so I don't have to invent the wheel again, by trying to get it working.
Thanks in advance for any comments.
Just a little followup. I did have some time today and got it working, but it needed the libs and ffmpeg version from synocommunity https://github.com/SynoCommunity/spksrc/tree/master/spk/ffmpeg Cpu usage dropped from 25% to about 6%. I forked this repo and see if I can make an easy docker file for synology NAS devices. If someone needs some more info in the mean time just ask.
Seems to be the easiest way is to use some bind mounts when starting the original container. Just adjust the folders to your needs:
docker run \
--detach \
--rm \
--name restreamer \
-e "RS_USERNAME=admin" -e "RS_PASSWORD=datarhei" \
-v "/volume1/docker/restreamer/db:/restreamer/db" \
-v "/var/packages/ffmpeg/target/bin/ffmpeg:/usr/local/bin/ffmpeg" \
-v "/var/packages/ffmpeg/target/bin/ffprobe:/usr/local/bin/ffprobe" \
-v "/var/packages/ffmpeg/target/lib:/var/packages/ffmpeg/target/lib" \
-v "/volume1/docker/restreamer/conf/live.json:/restreamer/conf/live.json" \
--device /dev/dri:/dev/dri \
-p 8300:8080 \
datarhei/restreamer:latest
Adjust the live.json file see below diff
diff --git a/conf/live.json b/conf/live.json
index 47cabc3..a6af7d1 100644
--- a/conf/live.json
+++ b/conf/live.json
@@ -90,7 +90,9 @@
"-re"
],
"outputOptions": [
- "-codec:v libx264",
+ "-filter_hw_device foo",
+ "-vf format=nv12|vaapi,hwupload",
+ "-codec:v h264_vaapi",
"-preset:v {preset}",
"-b:v {bitrate}k",
"-maxrate {bitrate}k",
@@ -131,8 +133,12 @@
"global": {
"inputOptions": [
"-stats",
- "-loglevel quiet",
- "-err_detect ignore_err"
+ "-loglevel debug",
+ "-err_detect ignore_err",
+ "-init_hw_device vaapi=foo:/dev/dri/renderD128",
+ "-hwaccel vaapi",
+ "-hwaccel_device foo",
+ "-hwaccel_output_format vaapi"
]
},
"video": {
@@ -303,7 +309,7 @@
"name": "RS_DEBUG",
"alias": [],
"type": "bool",
- "defaultValue": false,
+ "defaultValue": true,
"required": false,
"description": "Enables debug reporting."
},
@@ -332,4 +338,4 @@
"description": "Automatically start pulling from this stream on a fresh Restreamer installation."
}
]
-}
+}
\ No newline at end of file
Note that you will need to have the ffmpeg package from synocommunity installed on your NAS https://synocommunity.com/package/ffmpeg before you start the container. Just some things to do see if I can get the latency down. It is now about 5 seconds delay. Also make something so I start/stop the encoding when the stream is not accessed. Solved the start/stop encoding in the mean time with https://github.com/datarhei/restreamer/issues/98#issuecomment-569488342 Still having latency issues #132
@divx118 Thanks for these instructions.
A few notes from trying this out today. The instructions from @divx118 got me very close on some non-synology hardware. With a little tweaking, I have this running on a NUC with an Intel Quick Sync / VAAPI supported CPU. This cut CPU usage per stream down by ~90%.
First I had to pull out the /bin/ffmpeg
/bin/ffprobe
and /lib
folder from the Synology ffmpeg package that was linked, and then I just mapped them as volumes to the docker container. I didn't have to actually install that package on my host:
-v /opt/appdata/restreamer/ffmpeg/bin/ffmpeg:/usr/local/bin/ffmpeg \
-v /opt/appdata/restreamer/ffmpeg/bin/ffprobe:/usr/local/bin/ffprobe \
-v /opt/appdata/restreamer/ffmpeg/lib:/var/packages/ffmpeg/target/lib \
For the edits to /conf/live.json
, the output options are correct, but instead of adding the input options to the global
area, I only put them in the video_code_h264
section. I found this is all that was needed and it keeps from breaking the snapshots. When you put all of those global input switches into the snapshot command it fails. I hope this helps someone else in the future.
@divx118 @LckyLuciano Has this already been tested with the latest version? Would be very interesting!
By the way:
VAAPI is built into the datarhei/restreamer:vaapi-latest
image. Maybe it also works without mounts.
Dear @divx118 and @LckyLuciano We are closing your issue #128
This may be due to the following reasons:
- Problem/inquiry has been solved
- Ticket remained unanswered by you for a longer period
- Problem was explained and handled in another ticket
You can reopen this ticket at any time!
Please only open related tickets once! Always answer/ask in the original ticket with the same issue!
💛 If you were satisfied with the support and we could help you, please rate us on Google.
With kind regards, Your datarhei team