Another Video Capture question
Another Video Capture question
With the help of some nice people on here, i have managed to make a small app to display my webcam. Is it as simple to pass the captured image through a video compressor then through a video decompressor? I want to stream this over the internet like MSN Messenger does. Im not expecting it to be straight forward but is it pretty feasable?
-
- Enthusiast
- Posts: 196
- Joined: Tue Sep 30, 2003 4:32 pm
- Location: The Netherlands
@AndyMk,
I see no reason why not, MSN does it!! Oke it will not be simple to write but yes very possible.
You need some kind of server on your side and the client logs into your server (which has to run 24h a day). See the manual for the network instructions there is even an server.pb and client.pb in the example section.
Let your (web-) camera app put a bmp file into a directory. And let the server send it to the client who can put this onto his (or Here) screen. It works have done it before, we got very easy some 15 frames a second, but needed one shot every 1 sec to keep an eye onto a nest of Husky dogs.
Hope this helps. Ask if you need more assistance.
Jan V.
I see no reason why not, MSN does it!! Oke it will not be simple to write but yes very possible.
You need some kind of server on your side and the client logs into your server (which has to run 24h a day). See the manual for the network instructions there is even an server.pb and client.pb in the example section.
Let your (web-) camera app put a bmp file into a directory. And let the server send it to the client who can put this onto his (or Here) screen. It works have done it before, we got very easy some 15 frames a second, but needed one shot every 1 sec to keep an eye onto a nest of Husky dogs.
Hope this helps. Ask if you need more assistance.
Jan V.
Life goes to Fast, Enjoy!!
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
Sounds good but isnt 320x240@15fps bmp gonna be way too much for an average broadband outbound connection to handle? It works out to around 3MB/sec.. even @5fps its gonna be a wopping 1MB/sec! I read a post regarding "PBSOL" libraries and some way of doing it with that and not having to save the file first but do it straight from memory. Problem is, the site is in German. Is there no frame compression/decompression with avicap?
Is there any way you could post the german link to this reference to PBOSL reference? Im interested in doing something fairly similar.
Another option is to be instead of using BMP, use JPG compression or some other compression that will keep the image small and can be shown on the other end from memory.
Another option is to be instead of using BMP, use JPG compression or some other compression that will keep the image small and can be shown on the other end from memory.
http://www.purebasic.fr/english/viewtop ... ight=pbosl
I just found this link so i might still have a chance
I just found this link so i might still have a chance

My apologies, I thought you meant a german thread that contains info on how to transmit a continous stream of images from one comp to another
my bad.
(edit): Nevermind, the BriefL_Z test in the PBOSL library contains a client/server example. Though the desktop res must be the same on both for the image to turn out correctly, I believe.

(edit): Nevermind, the BriefL_Z test in the PBOSL library contains a client/server example. Though the desktop res must be the same on both for the image to turn out correctly, I believe.
- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
The code below works for displaying a webcam preview.
I am trying to copy frames to the clipboard where i can convert them to a jpeg file ready for sending over the network. As you can see i have had a go but been unsuccessful due to my total lack of PB syntax understanding. Can anyone give me a few pointers?
Code: Select all
#WM_CAP_START = #WM_USER
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_DRIVER_GET_CAPS = #WM_CAP_START + 14
#WM_CAP_EDIT_COPY = #WM_CAP_START + 30
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_STOP = #WM_CAP_START + 68
#WM_CAP_SET_SCALE = #WM_CAP_START + 53
If OpenWindow(0, 0, 0, 640, 480, "Video Preview", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenLibrary(0, "avicap32.dll")
*capAddress = GetFunction(0, "capCreateCaptureWindowA")
hWndC.l = CallFunctionFast(*capAddress, "My Capture Window", #WS_CHILD | #WS_VISIBLE, 0, 0, 640, 480, WindowID(0),0)
SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEWRATE, 1, 0)
SendMessage_(HWndC, #WM_CAP_SET_SCALE, #True, 0)
EndIf
EndIf
;SendMessage_(hWndC, #WM_CAP_EDIT_COPY, 0, 0)
;img.l = GetClipboardImage(#PB_Any)
;reult.l=SaveImage(img.l,"c:\test.jpg",#PB_ImagePlugin_JPEG,10)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
SendMessage_(hWndC, #WM_CAP_STOP, 0, 0)
SendMessage_(hWndC, #WM_CAP_DRIVER_DISCONNECT, 0, 0)
DestroyWindow_(hWndC)
CloseLibrary(0)
End
-
- Enthusiast
- Posts: 196
- Joined: Tue Sep 30, 2003 4:32 pm
- Location: The Netherlands
You are right but the webcam (through AviCap) can in default write in BMP format. I figured it out to use JPG (some 2 years ago). Must first update to PB4 before i can post the code. Will try tomorrow (it is 03:30 (AM) herer at night.Joakim Christiansen wrote:Bether try with a jpg, since bmp files is just too big!Let your (web-) camera app put a bmp file into a directory. And let the server send it to the client who can put this onto his (or Here) screen.
@AndyMk,
I have found (old) code to view webcam images on remote computers will check tomorrow and post it, but again need conversion to PB4 first.
night night
Jan V.
(PS have found code to see webcam images on remote computers will check tomorrow and post)
Life goes to Fast, Enjoy!!
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
-
- Enthusiast
- Posts: 196
- Joined: Tue Sep 30, 2003 4:32 pm
- Location: The Netherlands
As promised yesterday the 'code' to view a remote webcam.
It is in two parts since the original code used 'urldownloadtofile()' which is not very accurate (the least).
Looking on the board found (old) code by ElChiconi modified it an hé presto a 'talking' download, now at least we now why we can not download a 'camera'.
As you van see very simple (i think).
First the download.pb
second the 'camera' program:
All very simple and working it is code for PB4.0 (but it worked originaly for 3.94).
As you can see some cameras are no longer functional those are commented out.
Have fun with it!!
Jan V.
It is in two parts since the original code used 'urldownloadtofile()' which is not very accurate (the least).
Looking on the board found (old) code by ElChiconi modified it an hé presto a 'talking' download, now at least we now why we can not download a 'camera'.
As you van see very simple (i think).
First the download.pb
Code: Select all
#INTERNET_FLAG_RELOAD = $80000000
#INTERNET_DEFAULT_HTTP_PORT = 80
#INTERNET_SERVICE_HTTP = 3
#HTTP_QUERY_FLAG_NUMBER = $20000000
#HTTP_QUERY_CONTENT_LENGTH = 5
#HTTP_QUERY_STATUS_CODE = 19
#HTTP_STATUS_OK = 200
#INTERNET_OPEN_TYPE_DIRECT = 1
Enumeration 1
#dl_noInet
#dl_Urlfail
#dl_NoConn
#dl_HTTPfail
#dl_HTTPsend
#dl_HTTPqry
#dl_STATfail
#dl_CLENfail
#dl_NOmem
#dl_NOfile
#dl_FAIL
EndEnumeration
Dim dl_Errors.s( 20)
dl_Errors( #dl_noInet) = "Internet connection not available."
dl_Errors( #dl_Urlfail) = "InternetOpenUrl_() failed"
dl_Errors( #dl_NoConn) = "Unable to connect to "
dl_Errors( #dl_HTTPfail) = "Http open failed to "
dl_Errors( #dl_HTTPsend) = "Http send request failed to "
dl_Errors( #dl_HTTPqry) = "Http query failed."
dl_Errors( #dl_STATfail) = "Status code query failed."
dl_Errors( #dl_CLENfail) = "CONTENT_LENGTH query failed."
dl_Errors( #dl_NOmem) = "Not enough memory."
dl_Errors( #dl_NOfile) = "Unable to create file: "
dl_Errors( #dl_FAIL) = "Download failed."
; dl_Errors( ) =
Procedure CheckError( value.l, message.l, terminate.l, mess.s = "")
Shared dl_Errors.s()
If value=0
MessageRequester("Error", dl_Errors.s( message.l)+mess.s)
If terminate
End
EndIf
EndIf
EndProcedure
Procedure Download(URL$, LocalFile$)
Domain$ = RemoveString(Left(URL$, FindString(URL$, "/", 8)-1), "http://")
dwordSize = 4
hInet = InternetOpen_("Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.7.8) Gecko/20050511 Firefox/1.0.4", #INTERNET_OPEN_TYPE_DIRECT, #Null, #Null, 0)
CheckError(hInet, #dl_noInet, #True)
hURL = InternetOpenUrl_(hInet, URL$, #Null, 0, #INTERNET_FLAG_RELOAD, 0)
CheckError(hURL, #dl_Urlfail, #True, URL$)
hInetCon = InternetConnect_(hInet, Domain$, #INTERNET_DEFAULT_HTTP_PORT, #Null, #Null, #INTERNET_SERVICE_HTTP, 0, 0)
CheckError(hInetCon, #dl_NoConn, #True, Domain$)
hHttpOpenRequest = HttpOpenRequest_(hInetCon, "HEAD", RemoveString(URL$, "http://"+Domain$+"/"), "http/1.0", #Null, 0, #INTERNET_FLAG_RELOAD, 0)
CheckError(hHttpOpenRequest, #dl_HTTPfail, #True, Domain$)
CheckError(HttpSendRequest_(hHttpOpenRequest, #Null, 0, 0, 0), #dl_HTTPsend, #True, Domain$)
CheckError(HttpQueryInfo_(hHttpOpenRequest, #HTTP_QUERY_FLAG_NUMBER|#HTTP_QUERY_STATUS_CODE, @sCode, @dwordSize, @lpdwIndex), #dl_HTTPqry, #False)
CheckError(sCode=#HTTP_STATUS_OK, #dl_STATfail, #False)
CheckError(HttpQueryInfo_(hHttpOpenRequest, #HTTP_QUERY_FLAG_NUMBER|#HTTP_QUERY_CONTENT_LENGTH, @sCode, @dwordSize, @lpdwIndex), #dl_CLENfail, #False)
If sCode
DataBufferLength = sCode
Else
DataBufferLength = 4096
EndIf
*DataBuffer = AllocateMemory(DataBufferLength)
CheckError(*DataBuffer, #dl_NOmem, #True)
CheckError( CreateFile(0, LocalFile$), #dl_NOfile, #True, localFile$)
Repeat
CheckError( InternetReadFile_(hURL, *DataBuffer, DataBufferLength, @Bytes), #dl_FAIL, #True)
If Bytes
WriteData( 0, *DataBuffer, Bytes)
EndIf
Until Bytes=0
CloseFile(0)
FreeMemory(*DataBuffer)
InternetCloseHandle_(hInetCon)
InternetCloseHandle_(hURL)
InternetCloseHandle_(hInet)
EndProcedure
; Download("http://xoap.weather.com/weather/local/USNY0181?cc=*&dayf=1", "c:\sources\purebasic\webcam\weather.xml")
Code: Select all
;
; ------------------------------------------------------------
; Purebasic Webcam viewer by midebor (mdb@skynet.be)
; The programm uses URLDownloadToFile Api to download Webcam images
; to temp.jpg file and displays them using the UseJPEGImageDecoder()
; function.
; The program assumes you are already connected To the Internet
; Has only been tested with ADSL connection
; ------------------------------------------------------------
; 18jul2006
; Modified by Jan J. Vooijs (jan.vooijs@wanadoo.nl)
; - No more array but a linked list if a cam no longer works you can shut it down by one ';' character.
; - It uses Download.pb as the downloader, now we get a verbal warning what is wrong.
; Download code by ElChiconi (thanks)..
; - Much simpler loading of the image into a screen.
;
XIncludeFile "download.pb"
UseJPEGImageDecoder() ; to decode the "temp.jpg" file
; ------------------ List of camera's ------------------------
NewList slCams.s()
AddElement( slCams()) : slCams() = "Antwerpen Zeevaartschool ! http://www.hzs.be/antwerp/schelde.jpg"
; AddElement( slCams()) : slCams() = "Bad Godesberg ! http://www.general-anzeiger-bonn.de/images/neteye/stadthaus.jpg"
AddElement( slCams()) : slCams() = "Berlin - Podsdammerplatz ! http://www.cityscope.de/pp/panos/cityscope.jpg"
; AddElement( slCams()) : slCams() = "Bruxelles Avenue de Terveuren ! http://camera.viking.be/images/ispy.jpg"
AddElement( slCams()) : slCams() = "CFN WebCam ! http://www.spiretech.com/~leonard/cfn/webcam/webcam.jpg"
; AddElement( slCams()) : slCams() = "DAX ! http://deutsche-boerse.com/parkett/parkett2.jpg"
; AddElement( slCams()) : slCams() = "De Haan Belgium ! http://www.dehaan.be/webcam/Video01.jpg"
; AddElement( slCams()) : slCams() = "Del Mar Beach Cam ! http://os1.prod.camzone.com/camzone-ie?delmar:1:1025193280125:0"
; AddElement( slCams()) : slCams() = "Dome of Cologne ! http://www.wdr.de/domcam.jpg"
; AddElement( slCams()) : slCams() = "Essen-Kupferdreh ! http://www.kupferdreh.de/cam.jpg"
AddElement( slCams()) : slCams() = "Europe Weather Satelite ! http://www.usatoday.com/weather/twc_images/europesat_440x297.jpg"
; AddElement( slCams()) : slCams() = "GameStar Online-Webcam ! http://www.gamestar.de/aktuell/webcam/cam.jpg"
AddElement( slCams()) : slCams() = "Ground Zero ! http://65.200.140.25/ec_metros/ourcams/johnst.jpg"
AddElement( slCams()) : slCams() = "Iowa State University ! http://www.iastate.edu/webcam/hugesize.jpg"
AddElement( slCams()) : slCams() = "Jericho Beach, Vancouver ! http://www.jericho.ca/webcam/images/webcam.jpg"
; AddElement( slCams()) : slCams() = "Kauai, Hawaii ! http://hawaiiweathertoday.com/images/webcam_kauai.jpg"
AddElement( slCams()) : slCams() = "Knokke, Belgium ! http://www.quiksilver.be/beachcam/live/beach.jpg"
AddElement( slCams()) : slCams() = "Koenigssee, Germany ! http://www.koenigssee.com/rodelbahn/fsc4.jpg"
; AddElement( slCams()) : slCams() = "La Tour Eifel ! http://www.images-abcparislive.com/eiffel1.jpg?1011467343523"
AddElement( slCams()) : slCams() = "La Tour Eifel (2) ! http://www.images2-abcparislive.com/eiffelcam1.jpg?1153262971609"
AddElement( slCams()) : slCams() = "Louvain La Neuve, Belgium ! http://www.sri.ucl.ac.be/SRI/webcam/universite.jpg"
AddElement( slCams()) : slCams() = "MGM Grand (Las Vegas) ! http://images.earthcam.com/ec_metros/ourcams/mgm.jpg"
; AddElement( slCams()) : slCams() = "Midvale Hill (Highway 95) ! http://www.ruralnetwork.net/~rnsmvlcm/midvalehill.jpg"
AddElement( slCams()) : slCams() = "MOBOTIX M1 PreParkCam ! http://preparkcam.mobotixserver.de/record/current.jpg"
AddElement( slCams()) : slCams() = "New York Times Square Cam 1 ! http://images.earthcam.com/ec_metros/ourcams/lindys.jpg"
AddElement( slCams()) : slCams() = "New York Times Square Cam 2 ! http://images.earthcam.com/ec_metros/ourcams/lennon.jpg"
AddElement( slCams()) : slCams() = "Niagara Falls ! http://www.fallsview.com/fallsmain.jpg"
AddElement( slCams()) : slCams() = "Nieuwpoort, Belgium ! http://www.vvwnieuwpoort.be/webcam/images/webcam.jpg"
AddElement( slCams()) : slCams() = "Oostende aan zee, Belgium ! http://aanzee.be/images/groot.jpg"
; AddElement( slCams()) : slCams() = "Oostende Camera radioamateurs ! http://www.flanderswebhost.com/webcams/radiocam/radiocam.jpg"
; AddElement( slCams()) : slCams() = "Oostende Webcam, Belgium ! http://www.oostende.net/webcam/oostendecam.jpg"
AddElement( slCams()) : slCams() = "Panama Canal, Miraflores Locks ! http://www.pancanal.com/miraflores/miraflores.jpg"
; AddElement( slCams()) : slCams() = "Poppies Pool, Bali ! http://www.poppies.net/webcam.jpg"
; AddElement( slCams()) : slCams() = "Poppies Restaurant, Bali ! http://www.poppies.net/webcam1.jpg"
; AddElement( slCams()) : slCams() = "Prague ! http://193.165.174.197/fullsize.jpg"
AddElement( slCams()) : slCams() = "PSC/EET Weather Station (New York) ! http://www.paulsmiths.edu/aai/eet/aaicam.jpg"
; AddElement( slCams()) : slCams() = "San Diego Zoo Panda Cam ! http://outstream.camzone.com/camzone-ie?zoo:2:1020871595627:0"
; AddElement( slCams()) : slCams() = "World - Shamu Cam ! http://outstream.camzone.com/camzone-ie?shamu:13:1023798289913"
AddElement( slCams()) : slCams() = "Seattle ! http://images.earthcam.com/ec_metros/washingtonst/seattle/marqueen.jpg"
AddElement( slCams()) : slCams() = "Stadt Neuburg, Germany ! http://www.neuburg-donau.de/donaucam/donaukai.jpg"
; AddElement( slCams()) : slCams() = "Trafalgar Square, London ! http://www.webviews.co.uk/liveimages/trafalgarsq.jpg"
AddElement( slCams()) : slCams() = "University of Arizona ! http://www.cs.arizona.edu/camera/view.jpg"
AddElement( slCams()) : slCams() = "University of Iowa ! http://www.iihr.uiowa.edu/webcam/cam.jpg"
AddElement( slCams()) : slCams() = "USS Intrepid Cam (New York City) ! http://65.200.140.25/ec_metros/ourcams/intrepid.jpg"
AddElement( slCams()) : slCams() = "Waikiki in Honolulu ! http://images.earthcam.com/ec_metros/hawaii/waikiki.jpg"
AddElement( slCams()) : slCams() = "Washington Memorial ! http://images.earthcam.com/ec_metros/washington/metrosquare.jpg"
AddElement( slCams()) : slCams() = "Weimar ! http://www.thueringer-webcams.de/weimar/theaterplatz/fullsize.jpg"
AddElement( slCams()) : slCams() = "WorldTradeAftermath.com ! http://worldtradeaftermath.com/capture0.jpg"
AddElement( slCams()) : slCams() = "Zeebrugge, Belgium ! http://www.rustyhouse.com/beachcam/beachcam.jpg"
ForEach slCams.s()
Nam.s = Trim( StringField( slCams(), 1, "!"))
Url.s = Trim( StringField( slCams(), 2, "!"))
Debug "Nam = " + Nam.s + " Url: "+ Url.s
Download( Url.s, "temp.jpg")
If OpenWindow(0, 0, 0, 800, 600, "PB - Webcam " + Nam.s, #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
Result.l = LoadImage( #PB_Any, "temp.jpg") ; change 2nd parameter to the path/filename of your image..
If Result.l
ImageGadget(0, 10, 10, ImageWidth( Result.l), ImageHeight( Result.l), ImageID( Result.l)) ; imagegadget standard
; ImageGadget(1, 130, 10, 100, 83, ImageID(0), #PB_Image_Border) ; imagegadget with border
EndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Else
MessageRequester("Error", "Can't load the image...", 0)
EndIf
Next
End
As you can see some cameras are no longer functional those are commented out.
Have fun with it!!

Jan V.
Life goes to Fast, Enjoy!!
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
-
- Enthusiast
- Posts: 196
- Joined: Tue Sep 30, 2003 4:32 pm
- Location: The Netherlands
Your'e welcom. And YES the people here are amazing!! So much code to play with like above the cam program original by Midebor and the original download prog is from ElChiconi, modified both (mostly to PB4) and hey presto a webcan viewer program (well very simple).AndyMK wrote:Thank you very much for this code. I will experiment over the weekend. I must say, coming from a Blitzbasic/DBpro environment, the people on this forum is so much more helpfull.
Have you read my tip about images and freeimage() in the Tips and tricks section?
Btw. because of this forum i stick with PureBasic 4.0 it rocks!
It is SO easy to try (little) bits of code being windows apps or good old plain console programs! Copy & paste, press F5 and we have liftoff!!!
There is NO other programming language (and IDE) like it!! The rest all need loads of setup (at least 40 lines of code) or produce programs which do not fit on 1 (one) CD!! Here if a programs exe is above 100k i start to worry


My motto here on the forum is "Help where you can and be helped" and with the execption of two other boards there is NO comparissing. And yes i own a legal copy of BlitzBasic but there forum eeks!! No code to speak of or it does not work or... But that is MY opinion not that of others. I did stop usinfg Blitz now for a year.
No here i feel at home among peers. Nobody yells (oke exept me sometimes, yes i have a big mouth

No PureBasic a day helps to keep the docter at bay (something to do with an apples original i think, no real appels!!)
Anytime,
Jan V.
Life goes to Fast, Enjoy!!
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!
AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)