B4J Video Conference / Video Streaming (RTSP H.264) / and webRTC

Star-Dust

Expert
Licensed User
Longtime User
This is my umpteenth videoconference production between two PCs.

In the past I have tried streaming moving images in MPEG and streaming separate audio. It was running very slow and only suitable for local networks.
Now I'm testing with H264 audio / video compression and the transmission is faster. But it has a 2.5 second delay / cache.

Previously, to get the H264 compression in sending the video to the PC, I connected IPCAM lan and sent audio / video to the second computer.
Now I can use a normal cam installed on the laptop and do the sw compression.

I have to thank @moster67 for his bookshop and his suggestions

1662031980919.png


1662068624382.png
 
Last edited:

ilan

Expert
Licensed User
Longtime User
looks really good. how about security? is the transfer secured? is it for desktop only?
 

Star-Dust

Expert
Licensed User
Longtime User
looks really good. how about security? is the transfer secured? is it for desktop only?
The prototype is for Desktop. There is an audio / video send (h264) and a reception that can be obtained with any class to produce streaming video. (eg. VLC)

But obviously in reception it also works on other platforms, because libraries to achieve this are also available in B4A (eg. MediaPlayer, or this, )
In B4I I do not know, above all I doubt that there is sending audio video in streaming
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I was able to share the DESKTOP with H264 compression as well.
I have to thank for some @moster67 tips that paved the way for me

1662132006043.png


I am quite satisfied.

Some time ago someone boasted that they had created an alternative to Skype or TeamViewer and then in reality did nothing but transmit a sequence of MPEG images (there is also an example of @Erel for CCTV) with poor compression obviously and an unthinkable slowness.
All serious audio / video transmission or desktop sharing sws (Skype, Zoom, TeamViewer, Supremo, AnyDesk to name a few) use strong compression to take up little bandwidth and be smooth in operation.

Sometimes some get excited for a little, just see a beautiful graphics and a fascinating intro but they do not see the technical characteristics that make a product usable.

Today's attempts have satisfied me, it is still not a useful product but I have taken a step to get closer
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
As you read in the title it is RTSP h.264 then MP4. I don't use openCV.
 

Star-Dust

Expert
Licensed User
Longtime User
Some internal "manual" decoding ? Without extra libs ?
Manual coding is difficult, it takes a very large abacus. ? i joke

I used a library on the forum
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Some internal "manual" decoding ? Without extra libs ?
Now I can give some details. I used a @moster67 library, I asked for a small extension to get the stream.

Now thanks to his suggestions, in addition to extending a function, I was able to rewrite a class of the library to make streaming in broadcasting easier.

The library required the creation of custom fxml files to load into the layout. I was able to create the Layout files in runtime and load them into the Layout without saving them to the Assets which makes transparent some of the work that the developer would have to do manually.

The result is very satisfying.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Nice and well done
Just a correction: I am not @Monster ?
it should be @moster67
and I also checked it. :rolleyes: I wrote with my mobile phone and it often modify the text.

I don't think my device liked you ????
 

Star-Dust

Expert
Licensed User
Longtime User
I am attaching a sample code of how it works. I still have to solve two small technical problems to finish the library


B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
 
    Private LocalSocket As ServerSocket 'ignore
    Private LocalIP As String
 
    ' Streaming Class (Send and Play)
    Private VideoStream As SD_VideoStream
    Private VideoRemotePlay As SD_VideoStream
    Private VideoLocalPlay As SD_VideoStream
    ' Pane Base to Play - Add on Design
    Private BaseRemoteVideo As Pane
    Private BaseLocalVideo As Pane
    ' Node Base (into pane) - don't add by design
    Private NodeRemotePlay As Node
    Private NodeLocalPlay As Node
 
    ' Other
    Private TextRemote As B4XView
    Private CheckBoxRotate As CheckBox
    Private LabelInfo As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
 
    If StreamSetup.vlcInstalled = False Then
        Log("VLC must be installed on the computer to run this program.")
        ExitApplication
    End If
         
    VideoStream.Initialize(Me,"VideoStream")
    VideoLocalPlay.Initialize(Me,"VideoLocalPlay")
    VideoRemotePlay.Initialize(Me,"VideoRemotePlay")
 
    ' load Layout with pane for VideoPlay
    MainForm.RootPane.LoadLayout("Layout1")
    ' create layout for node by code
    NodeLocalPlay=StreamSetup.LoadLayoput(BaseLocalVideo,"NodeLocalPlay")
    NodeRemotePlay=StreamSetup.LoadLayoput(BaseRemoteVideo,"NodeRemotePlay")
 
    ' Hook VideoPlay to node
    StreamSetup.HookPlayer(NodeLocalPlay,VideoLocalPlay.Player)
    StreamSetup.HookPlayer(NodeRemotePlay,VideoRemotePlay.Player)

    MainForm.Show
 
    ' load config - Host and degree rotate
    If File.Exists(File.DirData("videostream"),"config.ini") Then
        Dim M As Map = File.ReadMap(File.DirData("videostream"),"config.ini")
        TextRemote.Text=M.Get("Host")
        CheckBoxRotate.Checked=M.Get("r180")
    End If
 
    LocalIP=LocalSocket.GetMyIP
    MainForm.Title="Host: " & LocalIP
End Sub

private Sub MainForm_CloseRequest (EventData As Event)
    Log("We are closing the mainform")
    VideoStream.stop
    VideoStream.release
 
    VideoRemotePlay.Stop
    VideoRemotePlay.release
    VideoLocalPlay.Stop
    VideoLocalPlay.release
End Sub

private Sub ButtonSender_Click
    Log("Start sender")
    LabelInfo.Text="STARTING"

    VideoStream.StreamCam(LocalIP,"prova.mp4",8554,180)  ' for Internal Cam
    'VideoStream.StreamDesktop(LocalIP,"prova.mp4",8554) ' For Desktop
End Sub

Private Sub ButtonRiceve_Click
    Log("Start connect")
    LabelInfo.Text="Connect"
     
    If VideoRemotePlay.IsPlaying Then VideoRemotePlay.Stop
    VideoRemotePlay.Play($"rtsp://${TextRemote.Text.Trim}:8554/prova.mp4"$)
    VideoRemotePlay.SetVolume(100)
End Sub


Private Sub VideoStream_ReadyToSend
    Log("Start to send")
    If VideoLocalPlay.IsPlaying Then VideoLocalPlay.Stop
    VideoLocalPlay.Play($"rtsp://${LocalIP}:8554/prova.mp4"$)
    VideoLocalPlay.SetVolume(0)
End Sub

Private Sub VideoStream_Finished
    Log("finished send")
End Sub

' --- Send straming

private Sub VideoStream_ReadyToPlay
    Log("Video is ready to send")
End Sub

Private Sub VideoStream_Error
    Log("error to send")
End Sub

Private Sub VideoRemotePlay_Finished
    Log("finished play")
End Sub

' --- remote
Private Sub VideoRemotePlay_ReadyToPlay
    Log("Video is ready to play")
    NodeRemotePlay.PrefWidth=BaseRemoteVideo.PrefWidth
    NodeRemotePlay.PrefHeight=BaseRemoteVideo.PrefHeight
End Sub

Private Sub VideoRemotePlay_Error
    Log("Error to play")
End Sub

' --- Local

Private Sub VideoLocalPlay_Finished
    Log("finished local play")
End Sub

Private Sub VideoLocalPlay_ReadyToPlay
    Log("Video is ready to local play")
    NodeLocalPlay.PrefWidth=BaseLocalVideo.PrefWidth
    NodeLocalPlay.PrefHeight=BaseLocalVideo.PrefHeight
    Log(VideoLocalPlay.Volume)
End Sub

Private Sub VideoLocalPlay_Error
    Log("Error to local play")
End Sub
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
The next step is to record the screen to an FLV file.
A video recorder.

B4X:
    'VideoStream.StreamCam(LocalIP,"test.mp4",8554,180) ' share cam in streaming
    'VideoStream.StreamDesktop(LocalIP,"test.mp4",8554) ' share desktop in streaming
    VideoStream.SaveDesktop("C:\video.flv")


this video was produced with the same library
ezgif.com-gif-maker.gif
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I was able to capture only a portion of the screen, in PCs with multiple screens select the chosen screen.

The next step is to test to stream RTSP H.264 a locally saved file.
 

LucaMs

Expert
Licensed User
Longtime User
I start writing something usable

View attachment 133619
It is not highlighted enough that you are calling Jude, as you only write her name in that label.
You should keep the clicked panel highlighted, on the left, or, with a better aesthetic effect, when you click duplicate the panel and make it "fly" right under the phone icon.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I have created an MQTT server to manage connections and user authentication

ezgif.com-gif-maker.gif


This is only a draft, as LucaMS rightly noted, other graphical improvements need to be made. But I will not post further progress


The next step but for my delight will be to do screen sharing, a SupremoAlternative ... (this idea is perhaps not original ? )
 

LucaMs

Expert
Licensed User
Longtime User
I have created an MQTT server to manage connections and user authentication

View attachment 133644

This is only a draft, as LucaMS rightly noted, other graphical improvements need to be made. But I will not post further progress


The next step but for my delight will be to do screen sharing, a SupremoAlternative ... (this idea is perhaps not original ? )
What are the advantages of creating an MQTT server instead of one based on websockets?

It's a bit annoying to see your progress... without being able to have the source code (right @Xfood? ? )
 

Xfood

Expert
Licensed User
What are the advantages of creating an MQTT server instead of one based on websockets?

It's a bit annoying to see your progress... without being able to have the source code (right @Xfood? ? )
I agree, I hope that as soon as the project completes it makes the source available
 
Top