i'm making remote-assistant program should send screenshots server. use tcp. problem client send packets @ high speed , if server not able kkep coming images , memory overflow exception(because 1 image takes 30 mb in memory). came idea: buffer images in avi file on disk (like many video-audio streaming applications do-something mjpeg mode). found perfect library this:directshow , video aforge. ,i write avi file while reading (in fifo style). test project streaming(i write couple of pictures avi , trying read it):
public class form1 dim thr new thread(addressof write) dim videowriter new videofilewriter dim withevents vid new avireader dim withevents vidd directshow.filevideosource dim cc long, used boolean dim aa filterinfocollection, bb new videocapturedevice private sub form1_load(sender object, e eventargs) handles mybase.load end sub private sub button2_click(sender object, e eventargs) handles button2.click if file.exists(application.startuppath & "/video/stream.avi") file.delete(application.startuppath & "/video/stream.avi") thr.start() thread.sleep(1000) 'wait avi contains frames vidd = new directshow.filevideosource(application.startuppath & "/video/stream.avi") vidd.start() end sub sub a(sender object, args newframeeventargs) handles vidd.newframe draw(args.frame.clone) thread.sleep(100) 'wait again end sub sub draw(byref pic bitmap) if picturebox1.image isnot nothing picturebox1.image.dispose() picturebox1.image = nothing end if picturebox1.image = pic end sub sub write() dim count integer = 0 dim crop_bit new bitmap(320, 240), bit bitmap dim g graphics = graphics.fromimage(crop_bit) videowriter.open(application.startuppath & "/video/stream.avi", 320, 240, 100, videocodec.mpeg4) each fil string in directory.getfiles(application.startuppath & "/pictures") count += 1 debug.print(count) bit = image.fromfile(fil) g.drawimage(bit, 0, 0, 320, 240) videowriter.writevideoframe(crop_bit) bit.dispose() next 'stop..here videowriter.close() end sub end class
but not working. no error. creates file..the video shows no images on picturebox. seems when writes avi open writeonly , doesn't allow reading(maybe?). there way around? heard queues still stored in memory..it has on disk. option make own mjpeg-like file (store every image inside file within delimiters/header)?
30mb huge screen shot.
you might consider finding out why it's large, , either fixing problem or compressing image. it's unlikely normal home internet connection or average businesses connection can stream 30mb frames.
if server can not keep up, not stream screen shots , in fact, make slower because of added overhead.
to fix problem, need drop frames or reduce image size when server or network connection slow. streaming not help.
for it's worth, actual streaming servers transcode media @ multiple resolutions , framerates, reason. fiber internet connection might able stream full 1080p or better video, while on 2g phone might need scaled (180x320?) , couple of frames/second, not acceptable if you're dealing screen shots need readable.
Comments
Post a Comment