How to display in browser and modify locally stored video without OpenCV library functions?

Viewed 113

I've Python code that enables capture and size modification of a video content stored in a local file (there is source which is based on Flask):

import cv2
import time


from flask import render_template, Flask, send_from_directory, abort, json, \
   Response  

app = Flask(__name__)

@app.route("/")
def index():
   """Video streaming home page."""
   return render_template('index.html')

def gen():
   """Video streaming generator function."""
   while True:
      cap = cv2.VideoCapture('/var/media/something.ts')

      # Read until video is completed
      while (cap.isOpened()):
         # Capture frame-by-frame
         ret, img = cap.read()
         if ret == True:
            img = cv2.resize(img, (0,0), fx=1.5, fy=1.5)
            frame = cv2.imencode('.jpg', img)[1].tobytes()
            yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
            time.sleep(0.1)
         else:
            break

@app.route('/video_feed')
def video_feed():
   """Video streaming route. Put this in the src attribute of an img tag."""
   return Response(gen(),
                   mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
   app.run(host = "0.0.0.0", port = '5000')

While program running, the video plays in browser on port 5000, well. I wonder if there is any alternate option to display content in the same way, but omitting any OpenCV-featured functions like VideoCapture or resize. Is it reachable to do that? What Python modules and functions may replace instructions like those with OpenCV?

0 Answers
Related