Skip to content

Commit

Permalink
Video: Latency improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed Jan 21, 2024
1 parent eca5321 commit 875193d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions python/rtsp-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ def getPipeline(device, height, width, bitrate, format, rotation, framerate, tim
bitrate*1000, devrotation, ts)
elif "Ubuntu" not in platform.uname().version and not is_debian_bookworm():
# Pi or similar arm platforms running on RasPiOS. Note that bookworm (and Pi5) onwards don't support hardware encoding
s_h264 = "videoconvert ! {1} ! {2}v4l2h264enc extra-controls=\"controls,repeat_sequence_header=1,h264_profile=4,video_bitrate={0},h264_i_frame_period=5\" ! video/x-h264,profile=high,level=(string)4.1 ! h264parse".format(
bitrate*1000, devrotation, ts)
# Only use a higher h264 level if the bitrate requires it. I find that level 4.1 can be a little crashy sometimes.
if bitrate > 20000:
level = "4.1"
else:
level = "4"
s_h264 = "{1} ! {2}v4l2h264enc extra-controls=\"controls,repeat_sequence_header=1,h264_profile=4,video_bitrate={0},h264_i_frame_period=5\" ! video/x-h264,profile=high,level=(string){3} ! h264parse".format(
bitrate*1000, devrotation, ts, level)
else:
# s/w encoder - Pi-on-ubuntu, or RasPiOS Bookworm, due to ...sigh ... incompatibility issues
s_h264 = "videoconvert ! video/x-raw,format=I420 ! queue ! {1} ! {2}x264enc tune=zerolatency bitrate={0} speed-preset=superfast".format(
s_h264 = "videoconvert ! video/x-raw,format=NV12 ! queue ! {1} ! {2}x264enc tune=zerolatency bitrate={0} speed-preset=superfast".format(
bitrate, devrotation, ts)
else:
# s/w encoder - x86, etc
Expand All @@ -109,7 +114,7 @@ def getPipeline(device, height, width, bitrate, format, rotation, framerate, tim
format = "RGBx"
else:
format = "NV12"
s_src = "libcamerasrc camera-name={3} ! capsfilter caps=video/x-raw,width={0},height={1},format={4}{2} ! queue".format(
s_src = "libcamerasrc camera-name={3} ! caps=video/x-raw,width={0},height={1},format={4}{2},interlace-mode=progressive,colorimetry=bt709".format(
width, height, framestr, device, format)
elif format == "video/x-raw":
s_src = "v4l2src device={0} ! videorate ! {3},width={1},height={2}{4} ! queue".format(
Expand Down

0 comments on commit 875193d

Please sign in to comment.