show rtsp stream in streamlit web via ffmpeg, You can set the hardware acceleration manually in the code.
sudo apt install ffmpeg
pip3 install streamlit opencv-python
To change the FFmpeg settings in st_rtsp_main.py
, modify lines 20-30 as follows:
If you do not have the relevant hardware or install the relevant drivers, do not modify it.
for intel vaapi(You need to install the relevant drivers yourself)
process = subprocess.Popen(
[
'ffmpeg',
'-hwaccel', 'vaapi',
'-vaapi_device', '/dev/dri/renderD128',
'-i', self.stream.rtsp_url,
'-f', 'rawvideo',
'-pix_fmt', 'bgr24',
'-'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
for nvidia h264(You need to install the relevant drivers yourself)
process = subprocess.Popen(
[
'ffmpeg',
'-hwaccel', 'cuda',
'-hwaccel_device', '0', # Use the first GPU
'-i', self.stream.rtsp_url,
'-c:v', 'h264_nvenc', # Use NVIDIA's H.264 encoder
'-f', 'rawvideo',
'-pix_fmt', 'bgr24',
'-'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
streamlit run test.py
mailbox: [email protected]