B4J Library jWebCam (alpha version 0.01)

Using the vlcj library, it is possible to get a live web camera image to display on a Canvas object.

The vlcj library is capable of much more than just displaying a web cam live feed. It can play dvd's , play http streams, stream video and a few more things.

This library (jWebCam) is a very rough implementation of using a web cam.

You will need to know the name of your webcam ( on windows device manager will tell you).
You will need to download three vlc library files.
You also need Videolan VLC installed somewhere on the machine.

When you start the demo prog, it will ask you to find the VLC folder (so it can find the .dll's)
It will save this information in a properties file (jWebCam.properties), and on subsequent runs , won't request the info again.

Two things to be aware of:
1, The mainform_CloseRequest line webcam.release is VERY important. If you don't release the webcam, it will continue in background as it is on a separate thread.
2. The pause button... I was tempted to remove it. During pause, it still buffers the images, the longer you pause, the more memory you will lose. If you leave it on pause, expect to see lots (and I mean lots) of low memory warnings. Leave it paused too long and IT WILL KILL THE VM.

I have included the source for the library in the zip.

(The latest version I am using [will upload soon] works as an excellent media player - trying to find something it can't play :) )

jWebCamLibrary-1:
This has some refinements on the first. Nothing major.
You can do this with it
B4X:
    webcam.Initialize(canvas1,"dshow://","")
    webcam1.Initialize(canvas2,"dshow://","vdev="&Chr(34)&"Live! Cam Vista IM"&Chr(34))

The first line will cause a file selector to appear, just point it at an avi/mkv/divx movie and it will play it in canvas1, whilst showing the input from the webcam in canvas2. Obviously you need to dim 2 jWebCam objects.
VERY IMPORTANT : if you use extra feeds, add the 'release' to MainForm_CloseRequest sub to free up the resources they use.

jWebCamLibrary-2:
new function added
B4X:
webcam.Initialize(canvas1,"movie","E:/")
"movie" is entered as is, not the name of the film etc.
"E:/" is the drive letter of the dvd drive you want to play from.
add a button that calls webcam.playDVD and it will play the dvd in the canvas object.
In debug mode you will see messages from VLC, nothing I can do about them at present.
 

Attachments

  • jWebCamLibrary.zip
    8.9 KB · Views: 746
  • jWebCamLibrary-1.zip
    6.3 KB · Views: 638
  • jWebCamLibrary-2.zip
    6.3 KB · Views: 762
Last edited:

billzhan

Active Member
Licensed User
Longtime User
Daestrum,

I can't load it with B4J 1.06,webcam1.fxml is missing.

Regards,

Bill
 

Daestrum

Expert
Licensed User
Longtime User
As I said in the readme.txt, I don't think I can upload my project as I am not using SceneBuilder v1.1
That's why I included the B4J source, so it could be copy pasted into a new B4J project.
webcam1.fxml, simply contains 5 buttons and a Canvas object.
 

magoandroid

Member
Licensed User
Longtime User
Hi Daestrum,
thanks for sharing.
It all works fine.


MAgo
 

Attachments

  • Screenshot 2014-01-21 02.19.34.png
    Screenshot 2014-01-21 02.19.34.png
    407.8 KB · Views: 770

Daestrum

Expert
Licensed User
Longtime User
A question for Erel

Is there any way to stop B4J doing this to arguments
Could not open C:\B4JSOU~1\Objects\dvd:e: with libdvdcss.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.DirApp returns the user.dir system property which is set by the JVM.

It doesn't modify it in any way.

You can use this code to find the canonical path:
B4X:
Sub AppStart (Args() As String)
   Log(GetCanonicalPath(File.DirApp))
End Sub

Sub GetCanonicalPath(FileName As String) As String
   Dim jo As JavaObject
   Return jo.InitializeNewInstance("java.io.File", Array As Object(FileName)).RunMethod("getCanonicalPath", Null)
End Sub
 

Daestrum

Expert
Licensed User
Longtime User
I will try it. Thank you for the reply.

Found the problem, the docs were wrong
dvd:/// had become dvd:// in the docs.
 
Last edited:

Swissmade

Well-Known Member
Licensed User
Longtime User
Nice done,

How about IP Camera's Stream VLC can do this very good.
 

Daestrum

Expert
Licensed User
Longtime User
I did try the http streaming in, but it was so choppy I never followed it up.
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi Daestrum,or all

webcam1.fxml, simply contains 5 buttons and a Canvas object.

How to add a Canvas object? What is the Canvas object in the screen builder1.1(I don't see it)?
 

Daestrum

Expert
Licensed User
Longtime User
I think with 1.1 you have to create it in code.
dim c as canvas
c.Initialize ...
c.height ...
c.width .... etc

then add to mainform
 

hzytsoft

Member
Licensed User
Longtime User
can anyone play this url rtsp://210.56.50.141/video81
i can use vlc play this
but i wanna play whit my owe app
not use invent 3rd part app
can some guy help
i will pay for this
 
Top