Solved using FFmpeg and FFserver. Note FFserver only works on Linux. The solution uses python code from here as suggested by Ryan.

Flow is as follows -

  • Start FFserver background process using the desired configuration (mjpeg in this case).
  • FFmpeg input is the mmst stream, output stream to localhost.
  • Run python script to open the localhost stream and decode frame by frame.

Run FFserver

ffserver -d -f /etc/ffserver.conf

On a second terminal run FFmpeg

ffmpeg -i mmst://194.90.203.111/cam2 http://localhost:8090/cam2.ffm

The Python code. In this case, the code will open a window with the video stream.

import cv2, platform
import numpy as np
import urllib
import os

cam2 = "http://localhost:8090/cam2.mjpeg"

stream=urllib.urlopen(cam2)
bytes=''
while True:
    # to read mjpeg frame -
    bytes+=stream.read(1024)
    a = bytes.find('\xff\xd8')
    b = bytes.find('\xff\xd9')
    if a!=-1 and b!=-1:
        jpg = bytes[a:b+2]
        bytes= bytes[b+2:]
    frame = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
    # we now have frame stored in frame.

    cv2.imshow('cam2',frame)

    # Press 'q' to quit 
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

ffserver.config -

Port 8090
BindAddress 0.0.0.0
MaxClients 10
MaxBandWidth 50000
CustomLog -
#NoDaemon

<Feed cam2.ffm>
    File /tmp/cam2.ffm
    FileMaxSize 1G
    ACL allow 127.0.0.1
    ACL allow localhost
</Feed>
<Stream cam2.mjpeg>
    Feed cam2.ffm
    Format mpjpeg
    VideoFrameRate 25
    VideoBitRate 10240
    VideoBufferSize 20480
    VideoSize 320x240
    VideoQMin 3
    VideoQMax 31
    NoAudio
    Strict -1
</Stream>
<Stream stat.html>
    Format status
    # Only allow local people to get the status
    ACL allow localhost
    ACL allow 192.168.0.0 192.168.255.255
</Stream>
<Redirect index.html>
    URL http://www.ffmpeg.org/
</Redirect>

Note that this ffserver.config needs more fine tuning, but they work rather well and produce a frame very close to source with only a little frame freeze.

Answer from NoamR on Stack Overflow
🌐
OpenCV
docs.opencv.org › 4.13.0 › dd › d43 › tutorial_py_video_display.html
OpenCV: Getting Started with Videos
OpenCV-Python Tutorials · Gui Features in OpenCV · Getting Started with Videos · Learn to read video, display video, and save video. Learn to capture video from a camera and display it. You will learn these functions : cv.VideoCapture(), cv.VideoWriter() Often, we have to capture live stream with a camera.
🌐
Medium
medium.com › @anshulsjr6 › building-a-basic-video-streaming-application-in-python-with-opencv-cfb6995e2479
Building a Basic Video Streaming Application in Python with OpenCV | by Anshul Vishwakarma | Medium
September 15, 2023 - You can install it using pip install opencv-python. Two machines (or instances) to act as the server and client. We start by setting up the server. In our example, the server captures video from a webcam and streams it to the client.
🌐
PyImageSearch
pyimagesearch.com › home › blog › live video streaming over network with opencv and imagezmq
Live video streaming over network with OpenCV and ImageZMQ - PyImageSearch
April 17, 2021 - Learn how to stream live video over a network with OpenCV and implement Python + OpenCV scripts to capture and stream video frames from a camera to a server.
🌐
PyImageSearch
pyimagesearch.com › home › blog › opencv – stream video to web browser/html page
OpenCV - Stream video to web browser/HTML page - PyImageSearch
July 10, 2021 - Last updated on July 9, 2021. In this tutorial, you will learn how to use OpenCV to stream video from a webcam to a web browser/HTML page using Flask and Python. Ever have your car stolen? Mine was stolen over…
🌐
Medium
medium.com › nerd-for-tech › live-streaming-using-opencv-c0ef28a5e497
Live Streaming using OpenCV. At least once we have used live… | by Abhishek Prasad Kesare | Medium
June 11, 2021 - Here first we have imported required libraries for socket and OpenCV and ‘s’ stores the address of the socket.AF_INET represents the IP family v4 and socket.SOCK_DGRAM this keyword is for UDP protocol, And the third line will create a buffer size so that we can store a buffer of data to transmit it continuously. “serveip” and “serverport” hold the IP address and port number of the server. cap = cv2.VideoCapture(0) while True: ret,photo = cap.read() cv2.imshow('streaming', photo) ret, buffer = cv2.imencode(".jpg", photo,[int(cv2.IMWRITE_JPEG_QUALITY),30]) x_as_bytes = pickle.dumps(buffer) s.sendto(x_as_bytes,(serverip , serverport)) if cv2.waitKey(10) == 13: break cv2.destroyAllWindows()cap.release()
🌐
GitHub
gist.github.com › keithweaver › 5bd13f27e2cc4c4b32f9c618fe0a7ee5
Stream video in Python using OpenCV · GitHub
Stream video in Python using OpenCV. GitHub Gist: instantly share code, notes, and snippets.
Top answer
1 of 1
11

Solved using FFmpeg and FFserver. Note FFserver only works on Linux. The solution uses python code from here as suggested by Ryan.

Flow is as follows -

  • Start FFserver background process using the desired configuration (mjpeg in this case).
  • FFmpeg input is the mmst stream, output stream to localhost.
  • Run python script to open the localhost stream and decode frame by frame.

Run FFserver

ffserver -d -f /etc/ffserver.conf

On a second terminal run FFmpeg

ffmpeg -i mmst://194.90.203.111/cam2 http://localhost:8090/cam2.ffm

The Python code. In this case, the code will open a window with the video stream.

import cv2, platform
import numpy as np
import urllib
import os

cam2 = "http://localhost:8090/cam2.mjpeg"

stream=urllib.urlopen(cam2)
bytes=''
while True:
    # to read mjpeg frame -
    bytes+=stream.read(1024)
    a = bytes.find('\xff\xd8')
    b = bytes.find('\xff\xd9')
    if a!=-1 and b!=-1:
        jpg = bytes[a:b+2]
        bytes= bytes[b+2:]
    frame = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
    # we now have frame stored in frame.

    cv2.imshow('cam2',frame)

    # Press 'q' to quit 
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

ffserver.config -

Port 8090
BindAddress 0.0.0.0
MaxClients 10
MaxBandWidth 50000
CustomLog -
#NoDaemon

<Feed cam2.ffm>
    File /tmp/cam2.ffm
    FileMaxSize 1G
    ACL allow 127.0.0.1
    ACL allow localhost
</Feed>
<Stream cam2.mjpeg>
    Feed cam2.ffm
    Format mpjpeg
    VideoFrameRate 25
    VideoBitRate 10240
    VideoBufferSize 20480
    VideoSize 320x240
    VideoQMin 3
    VideoQMax 31
    NoAudio
    Strict -1
</Stream>
<Stream stat.html>
    Format status
    # Only allow local people to get the status
    ACL allow localhost
    ACL allow 192.168.0.0 192.168.255.255
</Stream>
<Redirect index.html>
    URL http://www.ffmpeg.org/
</Redirect>

Note that this ffserver.config needs more fine tuning, but they work rather well and produce a frame very close to source with only a little frame freeze.

Find elsewhere
🌐
Medium
medium.com › @alionurulker › live-stream-on-any-camera-using-opencv-and-python-e18d4de6fad7
Live stream on any camera using OpenCV and Python | by Ali Onur Ülker | Medium
July 20, 2020 - cap = cv2.VideoCapture(0) ret, imgOriginalScene = cap.read() First of all, we should import “requests”, “cv2”, and “numpy as np” libraries for our project. ... And then, create a variable as named URL for views of the stream, we can see what’s going on writing /shot.jpg on our browser.
🌐
Medium
medium.com › @prasadparit006 › python-project-building-a-simple-video-streaming-server-using-opencv-c8a9d9ba86d2
Python Project — Building a Simple Video Streaming Server using OpenCV | by Prasad A Parit | Medium
November 10, 2023 - Before getting started, make sure you have Python installed on your hardware . Install the required libraries using the following: ... Let’s jump directly into the code for the server. The server captures video frames and sends them to the client using the socket connection. import cv2 import socket import pickle import struct · Import the necessary libraries such as ,OpenCV for video capture, socket for networking, pickle for serialization, and struct for packing dat
🌐
GitHub
gist.github.com › keithweaver › 4b16d3f05456171c1af1f1300ebd0f12
Stream and save video in Python with OpenCV · GitHub
# For more info: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html import cv2 as cv2 import cv2 as cv import numpy as np import os FILE_OUTPUT = 'output.avi' # Checks and deletes the output file # You cant have a existing file or it will through an error if os.path.isfile(FILE_OUTPUT): os.remove(FILE_OUTPUT) # Playing video from file: # cap = cv2.VideoCapture('vtest.avi') # Capturing video from webcam: cap = cv2.VideoCapture(0) currentFrame = 0 width = cap.set(cv2.CAP_PROP_FRAME_WIDTH, 160); height = cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 120); # Get cu
🌐
Towards Data Science
towardsdatascience.com › home › latest › video streaming in web browsers with opencv & flask
Video Streaming in Web Browsers with OpenCV & Flask | Towards Data Science
March 5, 2025 - Most IP cameras are RTSP (Real Time Streaming Protocol) based and is therefore "not supported**" natively in internet browsers. ... In this article we will learn how to do that using Computer Vision. Computer Vision is an interdisciplinary field that deals with how computers can be made to gain a high-level understanding from digital images or videos. For implementing the computer vision part we will use the OpenCV module in Python and to display the live stream in the web browser we will use the Flask web framework.
🌐
Mike Polinowski
mpolinowski.github.io › machine learning, ai and computer vision › machine learning › opencv, streams and video files
OpenCV, Streams and Video Files | Mike Polinowski
Setup OpenCV · Webcam Capture · IP Camera Capture · Video Stream Recording · Playback Video Files · Github Repo · Create and activate a virtual work environment: python -m venv .env · source .env/bin/activate · python -m pip install --upgrade pip · Add a file dependencies.txt with all project pip dependencies: opencv-python ·
🌐
Medium
medium.com › analytics-vidhya › opencv-basic-and-useful-tools-video-feeds-python-5ef1cadc2fb0
OpenCV Basic and Useful Tools: Video Feeds (Python) | by Arthur K Jakobsson | Analytics Vidhya | Medium
May 3, 2020 - For example, I created a slider for user-input using OpenCV (I may write a tutorial on this later), but this was a window I wanted to close at the same time. I also displayed several edited (closed, dilated, etc.) versions of my video feed which I wanted to end. ... Overall, I created a class to handle these two functions of the video feed. #class to handle camera actionsclass Cameras: #reads and sends stream data def readStream(): #begins stream stream = cv2.VideoCapture(0) #creates the frame from stream data _, frame = stream.read() #sends frames and stream object return frame, stream #kill the feed #Parameter: Stream object def killFeed(stream): #stream object is killed stream.release() #windows are closed cv2.destroyAllWindows()
🌐
Medium
medium.com › @paliwalsamriddhi › simple-live-video-streaming-app-e8670bd4121b
Simple Live Video Streaming App. with Python and OpenCV | by samriddhipaliwal | Medium
September 15, 2023 - The OpenCV library installed (you can install it using pip install opencv-python). Run the server code on Computer A. This code captures the video stream from the client and displays it on Computer A’s screen.
🌐
Stack Overflow
stackoverflow.com › questions › 70805012 › cv2-videocapture-html-live-stream
python - cv2.VideoCapture( ' html live stream'? ) - Stack Overflow
I'm streaming this from my raspberry pi to my view it on windows so I can run opencv and yolo. Is there a way to do this with opencv? Copyimport cv2 cap = cv2.VideoCapture('http://______/html/#') while True: ret, frame = cap.read() cv2.imshow("frame", frame) key = cv2.waitKey(50) if key == 27: break cv2.destroyAllWindows()
🌐
AranaCorp
aranacorp.com › blog › tutorials › synchronized video streaming with opencv and multithreading
Synchronized video streaming with OpenCV and Multithreading • AranaCorp
March 4, 2024 - Here is the complete code for capturing non-synchronized video streams · N.B.: This code works once the ffmpeg commands have been run on each machine. #!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import cv2 import datetime #&lt;add code to run ffmpeg command via ssh&gt; cap0 = cv2.VideoCapture("udp://127.0.0.1:8553") cap1 = cv2.VideoCapture("udp://127.0.0.1:8554") while cap0.isOpened() and cap1.isOpened(): # Capture frame-by-frame ret0, frame0 = cap0.read() ret1, frame1 = cap1.read() # Get current date and time now=datetime.datetime.now() date_time = now.strftime("%H:%M:%S
🌐
GeeksforGeeks
geeksforgeeks.org › python-play-a-video-using-opencv
Python | Play a video using OpenCV - GeeksforGeeks
July 3, 2024 - Let’s see how to play a video using the OpenCV Python. To capture a video, we need to create a VideoCapture object. VideoCapture have the device index or the name of a video file.
🌐
Note.nkmk.me
note.nkmk.me › home › python › opencv
Capture video from camera/file with OpenCV in Python | note.nkmk.me
October 19, 2022 - In Python, you can read, capture, and display video files and camera stream using the VideoCapture class with OpenCV. Note that Video I/O must be enabled in OpenCV to process video. OpenCV: cv::VideoC ...