Now, using two threads, one is a thread that stores a video of a webcam as a file One function is to turn over this saved file to HTML and display it on the web in HTML. I don't know much about the web, but it went over the value of the video variable saved as a flask and render_template I want to receive and output the variable from html using url_for. But the video doesn't print out.
Python code for storing video.
4cc = VideoWriter_4cc (*'H264')
out = VideoWriter('/content/drive/My Drive/Colab Notebooks/MRCNN_pure/static/image/output.mp4', fourcc, 13.0, (1280, 720))
_lock = threading.Lock()
def webcam(capture):
while True:
frame_pos = capture.get(cv2.CAP_PROP_POS_FRAMES)
frame_count = capture.get(cv2.CAP_PROP_FRAME_COUNT)
grabbed, frame = capture.read()
if not grabbed:
print ("Not grabbed.")
break;
if grabbed:
_lock.acquire()
out.write(frame)
_lock.release()
Here is the flask execution code that hands it over to render_template.
app = Flask(__name__)
run_with_ngrok(app)
@app.route("/")
def home()-> 'html':
return render_template('test.html', output = "image/output.mp4")
if __name__ == "__main__":
app.run()
The following is the html file:
<body>
<h1>HTML5 Open Community</h1>
<p>This material is distributed by <a href="http://www.htmlfive.co.kr">HTML5 Open Community</a>.</p>
{% {% if True %}
<video controls autoplay preload="metadata" width="50%" src="{{ url_for('static',filename=output) }}" type='video/mp4'>
not working
</video>
<img src="{{url_for('static', filename=output)}}">
{% {% endif %}
</body>
It's okay to turn over another complete video file and print it out on the web, but it's not okay to print out the video you're saving. Is there a good way?
flask html video
What you're talking about is streaming. Twitch is that kind of service. Instead of encoding and storing the input image source as a static file, it is transmitting the output to the buffer immediately with minimal conversion as the incoming input. Find the right library and write it.
© 2024 OneMinuteCode. All rights reserved.