Skip to content

Commit

Permalink
rtmp for windows wsl support?
Browse files Browse the repository at this point in the history
  • Loading branch information
steveseguin authored Aug 28, 2024
1 parent b396973 commit 7cb651a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,9 @@ async def main():

if args.av1:
args.h264 = False

if args.rtmp and not args.h264:
args.h264 = True

h264 = None
if args.omx and check_plugins('omxh264enc'):
Expand All @@ -2068,16 +2071,20 @@ async def main():
h264 = 'vtenc_h264_hw'
elif check_plugins('omxh264enc'):
h264 = 'omxh264enc'
elif check_plugins('avenc_h264_omx'):
h264 = 'avenc_h264_omx'
elif check_plugins('x264enc'):
h264 = 'x264enc'
elif check_plugins('openh264enc'):
h264 = 'openh264enc'
elif check_plugins('avenc_h264_omx'):
h264 = 'avenc_h264_omx'
else:
print("Couldn't find an h264 encoder")
elif args.omx or args.x264 or args.openh264 or args.h264:
print("Couldn't find the h264 encoder")

if h264:
print("H264 encoder that we will try to use: "+h264)


if args.hdmi:
args.v4l2 = '/dev/v4l/by-id/usb-MACROSILICON_*'
Expand Down Expand Up @@ -2277,29 +2284,28 @@ async def main():
pipeline_video_input += f' ! nvvidconv ! video/x-raw(memory:NVMM) ! omxh264enc bitrate={args.bitrate}000 control-rate="constant" name="encoder" qos=true ! video/x-h264,stream-format=(string)byte-stream'
elif args.rpicam:
pass
elif args.rpi:
if h264 == "omxh264enc":
pipeline_video_input += f' ! v4l2convert ! video/x-raw,format=I420{timestampOverlay} ! omxh264enc name="encoder" target-bitrate={args.bitrate}000 qos=true control-rate="constant" ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?
elif h264 == "x264enc":
pipeline_video_input += f' ! v4l2convert ! video/x-raw,format=I420{timestampOverlay} ! queue max-size-buffers=10 ! x264enc name="encoder1" bitrate={args.bitrate} speed-preset=1 tune=zerolatency qos=true ! video/x-h264,profile=constrained-baseline,stream-format=(string)byte-stream'
elif h264 == "openh264enc":
pipeline_video_input += f' ! v4l2convert ! video/x-raw,format=I420{timestampOverlay} ! queue max-size-buffers=10 ! openh264enc name="encoder" bitrate={args.bitrate}000 complexity=0 ! video/x-h264,profile=constrained-baseline,stream-format=(string)byte-stream'

elif args.format in ["I420", "YV12", "NV12" "NV21", "RGB16", "RGB", "BGR", "RGBA", "BGRx", "BGRA", "YUY2", "YVYU", "UYVY"]:
elif h264 == "omxh264enc" and args.rpi:
pipeline_video_input += f' ! v4l2convert ! video/x-raw,format=I420{timestampOverlay} ! omxh264enc name="encoder" target-bitrate={args.bitrate}000 qos=true control-rate="constant" ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?
elif h264 == "x264enc" and args.rpi:
pipeline_video_input += f' ! v4l2convert ! video/x-raw,format=I420{timestampOverlay} ! queue max-size-buffers=10 ! x264enc name="encoder1" bitrate={args.bitrate} speed-preset=1 tune=zerolatency qos=true ! video/x-h264,profile=constrained-baseline,stream-format=(string)byte-stream'
elif h264 == "openh264enc" and args.rpi:
pipeline_video_input += f' ! v4l2convert ! video/x-raw,format=I420{timestampOverlay} ! queue max-size-buffers=10 ! openh264enc name="encoder" bitrate={args.bitrate}000 complexity=0 ! video/x-h264,profile=constrained-baseline,stream-format=(string)byte-stream'
elif check_plugins("v4l2h264enc") and args.rpi:
if args.format in ["I420", "YV12", "NV12" "NV21", "RGB16", "RGB", "BGR", "RGBA", "BGRx", "BGRA", "YUY2", "YVYU", "UYVY"]:
pipeline_video_input += f' ! v4l2convert ! videorate ! video/x-raw{timestampOverlay} ! v4l2h264enc extra-controls="controls,video_bitrate={args.bitrate}000;" qos=true name="encoder2" ! video/x-h264,level=(string)4'
else:
pipeline_video_input += f' ! v4l2convert ! videorate ! video/x-raw,format=I420{timestampOverlay} ! v4l2h264enc extra-controls="controls,video_bitrate={args.bitrate}000;" qos=true name="encoder2" ! video/x-h264,level=(string)4' ## v4l2h264enc only supports 30fps max @ 1080p on most rpis, and there might be a spike or skipped frame causing the encode to fail; videorating it seems to fix it though

elif h264=="x264enc":
pipeline_video_input += f' ! videoconvert{timestampOverlay} ! queue max-size-buffers=10 ! x264enc bitrate={args.bitrate} name="encoder1" speed-preset=1 tune=zerolatency qos=true ! video/x-h264,profile=constrained-baseline'
elif h264=="avenc_h264_omx":
pipeline_video_input += f' ! videoconvert{timestampOverlay} ! queue max-size-buffers=10 ! avenc_h264_omx bitrate={args.bitrate}000 name="encoder" ! video/x-h264,profile=constrained-baseline'
elif check_plugins("v4l2convert") and check_plugins("omxh264enc"):
pipeline_video_input += f' ! v4l2convert{timestampOverlay} ! video/x-raw,format=I420 ! omxh264enc name="encoder" target-bitrate={args.bitrate}000 qos=true control-rate=1 ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?
elif check_plugins("v4l2convert"):
pipeline_video_input += f' ! v4l2convert{timestampOverlay} ! video/x-raw,format=I420 ! openh264enc name="encoder" bitrate={args.bitrate}000 ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?
pipeline_video_input += f' ! v4l2convert{timestampOverlay} ! video/x-raw,format=I420 ! {h264} name="encoder" bitrate={args.bitrate}000 ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?
else:
pipeline_video_input += f' ! videoconvert{timestampOverlay} ! video/x-raw,format=I420 ! openh264enc name="encoder" bitrate={args.bitrate}000 ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?
pipeline_video_input += f' ! videoconvert{timestampOverlay} ! video/x-raw,format=I420 ! {h264} name="encoder" bitrate={args.bitrate}000 ! video/x-h264,stream-format=(string)byte-stream' ## Good for a RPI Zero I guess?

if args.rtmp:
pipeline_video_input += f' ! queue ! h264parse'
Expand Down

0 comments on commit 7cb651a

Please sign in to comment.