abhiTronix / vidgear

A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features :fire:
https://abhitronix.github.io/vidgear
Apache License 2.0
3.37k stars 254 forks source link

How can I send this video to javascript #71

Closed tomriddle54 closed 4 years ago

tomriddle54 commented 5 years ago

Question

I was trying to use a socket but found this. My question is how can I send this video to web and using javascript and this lib

this is my javascript this is how I receive image using javascript

    var arrayBuffer = msg.data;
    var bytes = new Uint8Array(arrayBuffer);

    var image = document.getElementById('image');
    image.src = 'data:image/png;base64,'+encode(bytes);
};
abhiTronix commented 5 years ago

@syedmustafa54 Hello, vidgear as of now doesn't support web streaming. It planned to add support for webrtc(that enables web browsers with Real-Time Communications) in upcoming release, see its development in proposal: #50.

For now, Kindly see Aiortc, a library for Web Real-Time Communication (WebRTC) and Object Real-Time Communication (ORTC) in Python.

abhiTronix commented 4 years ago

Thanks for your patience, VidGear just introduced WebGear API, that might help in your application. Kindly install the PR(#98) as follows:

git clone https://github.com/abhiTronix/vidgear.git
cd vidgear
git checkout development
sudo pip3 install .
cd

and install uvicorn as follows:

sudo pip3 install uvicorn

Then run this python code:

#import libs
import uvicorn
from vidgear.gears import WebGear

#various performance tweaks
options = {"frame_size_reduction": 40, "frame_jpeg_quality": 80, "frame_jpeg_optimize": True, "frame_jpeg_progressive": False}

#initialize WebGear app  and open stream(for e.g `test.mp4`)
web = WebGear(source = "test.mp4", logging = True, **options)

#run this app on Uvicorn server
uvicorn.run(web(), host='0.0.0.0', port=8000)

#close app safely
web.shutdown()

This will run at address: http://0.0.0.0:8000/ on browser.

Then you can run your javascript code as follows:

 var arrayBuffer = msg.data;
    var bytes = new Uint8Array(arrayBuffer);

    var image = document.getElementById('video');
    image.src = 'data:image/jpeg,'+encode(bytes);
};

Try this and revert your results here. Goodluck!

abhiTronix commented 4 years ago

@syedmustafa54 I'm hoping you to test this PR as soon as possible as it will be going to be merged by tomorrow.

abhiTronix commented 4 years ago

@syedmustafa54 I merged this PR and marked this issue as solved as it performed as expected at my end, Kindly share your results when you're ready. Good luck!

abhiTronix commented 4 years ago

Successfully resolved and merged in commit d57f01e