-3

I used host='0.0.0.0' so that i can run this code from a different machine. Now suppose my ip is ###.###.#.###. What i want to do is pass a link like this: ###.###.#.###/ and the video will run on the browser. I tried this way but it seems like it is wrong approach.

For a rough work, i simply tried to run this using opencv only I pasted the link like this: video_link = <'link.com'> cap = cv2.VideoCapture(video_link) It worked.

This is what i tried

from flask import Flask
import cv2

app = Flask(__name__)
@app.route("/video/<string:url>")
def input_value(url):
    link = str(url)
    return link

    cap = cv2.VideoCapture(link)

    while (cap.isOpened()):
        ret, frame = cap.read()

        if ret:
            cv2.imshow('output', frame)
            if cv2.waitKey(1) == ord('q'):
                break
        else:
            break


if __name__ == "__main__":
    app.run(host='0.0.0.0', debug=True)

I'm getting messages like 404

Rajan Sharma
  • 2,211
  • 3
  • 21
  • 33
a1ft a1ft
  • 15
  • 4
  • Please see below url which shows how to use URL directly from Open VideoCapture method https://stackoverflow.com/questions/50185654/opencv-load-video-from-url – Shirish Goyal Jul 30 '19 at 10:34
  • This is not what i'm looking for. I already mentioned that i tried this. – a1ft a1ft Jul 30 '19 at 10:38
  • No, you didn't mention that you tried this link anywhere – Shirish Goyal Jul 30 '19 at 10:41
  • This is an example: from flask import Flask app = Flask(__name__) @app.route("/add/,") def add(number, number2): x = number y = number2 result = x + y return str(result) if __name__ == "__main__": app.run(host='0.0.0.0', debug=True) When i type this on the address bar: ###.###.#.###:5000/add/3,5 It gives me a blank white page with 8 as the result printed on the top left corner. – a1ft a1ft Jul 30 '19 at 10:42
  • I mentioned this: For a rough work, i simply tried to run this using opencv only I pasted the link like this: video_link = <'link.com'> cap = cv2.VideoCapture(video_link) It worked. I tried this on vs code – a1ft a1ft Jul 30 '19 at 10:44

3 Answers3

0

i see that you have not provided the url to fetch the video which is giving 404 error message.

@app.route("/video/<string:url>")

line 2, repace with the desired url which includes video you want to show.

such as :

@app.route("/video/https://www.youtube.com/watch?v=Jvf5y21ZqtQ")
Abdullah Akhtar
  • 529
  • 5
  • 14
  • I didn't provide the url because i will pass the url as a parameter from my web browser..like this....123.147.1.355:5000/video/https://www.youtube.com/watch?v=Jvf5y21ZqtQ and it should display the video on the web browser – a1ft a1ft Jul 30 '19 at 12:07
  • For this you should use call by reference method. for example def url(x): print "x=",x," id=",id(x) x=123.147.1.355:5000 print "x=",x," id=",id(x) After that use this url(x) in your code. – Abdullah Akhtar Jul 30 '19 at 12:29
0

I got it.

from flask import Flask
import cv2
app = Flask(__name__)
@app.route("/video/<path:url>")
def input_value(url):
    counter = 0
    cap = cv2.VideoCapture(url)


    while (cap.isOpened()):
        ret, frame = cap.read()

        if ret:
            counter += 1
            cv2.imshow('output', frame)
            if cv2.waitKey(1) == ord('q'):
                break
        else:
            break
    return str(counter)
if __name__ == "__main__":
    app.run(host='0.0.0.0', debug=True)

This code takes the link from the address bar, then runs the video on my machine and returns the counter value on the webpage

a1ft a1ft
  • 15
  • 4
  • why did you immediately answer the question when you asked it recently? –  Jul 31 '19 at 05:56
  • 1
    I didn't answer it immediately. I was looking for answers and also figuring out the code at the same time. – a1ft a1ft Aug 01 '19 at 09:56
-1

Based on your code, I believe you want video to be visible on a webpage. For that just use a html video tag and pass in the URL from the django as value in the webpage.

Shirish Goyal
  • 510
  • 2
  • 9