mrayy / mrayGStreamerUnity

GStreamer Integration with Unity using a Native plugin
MIT License
111 stars 38 forks source link

How can I stream appsrc to RTMP server (Wowza)? #40

Open dfarrowUnity opened 2 years ago

dfarrowUnity commented 2 years ago

I am trying to stream RTMP using Test4 scene. I made this update in the CustomVideoStreamer "Pipeline" field:

videoconvert ! video/x-raw,format=I420 ! x264enc name=videoEnc bitrate=5000 tune=zerolatency pass=qual ! video/x-h264 ! queue ! flvmux name=mux ! rtmpsink location=rtmp://192.123.1.45:1935/live_test/myStream

I see my stream appear in Wowza, but I cannot play it back. A very similar commands works for me on the command line:

gst-launch-1.0 gdiscreencapsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc name=videoEnc bitrate=5000 tune=zerolatency pass=qual ! video/x-h264 ! queue ! flvmux name=mux ! rtmpsink location=rtmp://192.168.1.33:1935/live_test/myStream

Can you provide any insight into streaming using RTMP? (Please note, I do have "Run in Background" set on Player settings)

dfarrowUnity commented 2 years ago

I did some further testing and it seems that it is only failing to play when I use the "appsrc", when I alter the plugin so the pipeline is exactly the same except "appsrc" is replaced with "videotestsrc" like this:

videotestsrc name=src do-timestamp=true is-live=true block=true ! video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! videoconvert ! video/x-raw,format=I420 ! x264enc name=videoEnc bitrate=5000 tune=zerolatency pass=qual byte-stream=true threads=4 ! video/x-h264 ! queue ! flvmux streamable=true name=mux ! rtmpsink location=rtmp://192.168.1.33:1935/live_test/unityStream

everything plays as expected. It seems something about the way the appsrc is sending data to Wowza is not working, however Wowza doesn't show any errors in the logs, there is just no playback (the playlist loads but not the chunklists). Do you know how I might get the appsrc working with RTMP?

dfarrowUnity commented 2 years ago

Interestingly, I found if I set the "Fps" to 5 or below on the "CustomVideoStreamer.cs" script, I can actually see a frame of video when I go to play the HLS stream. After a single frame displays the video stops. If I hit play again, I will see another single frame and then it stops. It seems that this gstreamer pipeline is starving the encoder, however Wowza seems to report an acceptable bitrate coming in (~1.930 Mbits/s). Any clue on how to send the data correctly via RTMP? My Pipeline string:

appsrc name=src do-timestamp=true is-live=true block=true ! video/x-raw,format=RGB,width=360,height=240,framerate=4/1 ! videoconvert ! video/x-raw,format=I420 ! x264enc name=videoEnc bitrate=1000 tune=zerolatency pass=qual byte-stream=true threads=4 ! video/x-h264 ! queue ! flvmux streamable=true name=mux ! rtmpsink location=rtmp://127.0.0.1:1935/live_test/myStream