I am planning to write my own live stream server in python using the HLS protocol for a small project.
My idea is to use Amazon S3 for storage and have the python server just output the m3u8 file.
This is all straightforward, now to the problem: I want to stream live video from a camera over an unreliable network and if there is a congestion the player could end up with completing playing of the last file referenced in the m3u8 file. Can i in some way mark the stream as a live stream having the player try again reloading the m3u8 for a specific time looking for a next segment or how should live streaming using HLS be handled?
Maybe live streaming over HLS is not supported?
This is explictly allowed in the HLS spec as a "live Playlist". There are a few things you need to be aware of, but notably, from section 6.2.1:
The server MUST NOT change the Media Playlist file, except to:
o Append lines to it (Section 6.2.1).
And if we take a look at Section 4.3.3.4:
The EXT-X-ENDLIST tag indicates that no more Media Segments will be added to the Media Playlist file. It MAY occur anywhere in the Media Playlist file.
In other words, if a playlist does not include the #EXT-X-ENDLIST tag, it's expected that the player will keep loading the playlist from whatever source it originally loaded it from with some frequency, looking for the server to append segments to the playlist.
Most players will do this taking into account current network conditions so they have a chance to get new segments before the playback is caught up. If the server needs to interrupt the segments, or otherwise introduce a gap, it has the responsibility to introduce a #EXT-X-DISCONTINUITY-SEQUENCE tag.
Apple provides a more concrete example of a Live Playlist on their developer website.
Related
I am an intern and I work on a project to create WebSDR. I need to create a web interface that allows users to observe the activity on the frequency range they want (with a waterfall graph) and also transmit the sound on the chosen frequency.
example of a websdr
For this purpose we have an SDR connected to a local server and running GNURadio. (I show you the block diagram as it is now, it is obviously not final)
global architecture
I then created a server code in python which retrieves the data sent in UDP via the "UDP Sink" block which for the moment simply transmits it in text to the client code in javascript to display it on an html page. (I will send you the codes if needed)
server
client.js and client.html
I'm stuck now, I can't find any resources on the internet for the rest. I would like to process the data on the server in order to create an audio data stream that would be streamed to the web client. But also a way to create a waterfall graphic, which I will convert to an image afterwards and which will be sent to the client every second to give the impression that the waterfall graphic is refreshed regularly.
Please can you give me some answers to create these two features. I am open to other proposals as well if the method I want to apply is not the right one.
Thank you very much,
I want to share some images (Local or stored in one drive, no issue) as a file attachment to MS Teams channel (not chat) using python.
I've already tried using Requests module and Webhooks to send Images (using base64 encoding and links), but they are the tiny images which can't be opened. I've also tried the Azure bot but it's only useful if we want to sent the image file to the chat.
If you do know, Can you share some sample working code (instead of sharing this link) here.
Technically, there is not proper chance to send images using python in teams. One of the previous researchers worked on this. As you are not focusing on bot and directly need to share the image using python. There is no procedure to accomplish the task.
https://techcommunity.microsoft.com/t5/microsoft-teams/post-image-to-teams-channel-from-local-path-using-python/m-p/2484798
I am making a music player application with Pygame, initially, I was playing songs that I have downloaded in my local system, now I want to share this app as an executable file with my friends, now the issue is they may not have songs already downloaded on their system nor will the location be the same, hence I thought of uploading the song files on to the cloud, Mega in my case, I am a noob and this is the first time I'm exploring something with cloud storage and streaming, Now I want to access the songs stored in my cloud account and play it in my application, basically I need all possible access to every file stored in cloud, since the app does quite a few things like shuffle, next song's title, loop, etc.
My question now is How to stream the audio from my cloud account in my Python desktop app?
I chose Mega since it offers 20GB of storage for a free account, but I am not sure if this is even a suitable platform for what I'm trying to achieve or is this only for cloud storage, any insights in the right direction to the next move would be really helpful.
Update: I tried using mega API, but I'm facing errors logging in
Are there any alternatives or does anyone know how to get rid of this error mega.errors.RequestError: EACCESS, Access violation faced during logging in.
The code I used for logging in:
from mega import Mega
mega = Mega()
m = mega.login(email, password)
m = mega.login()
I have had success in obtaining files from mega using the mega.py package. Install with
pip install mega.py
And then obtain files to play with:
from mega import Mega
import tempfile
# Login to mega
mega = Mega()
email="XXXXXX#XXXXX.XXX"
password="XXXXXXXXXXXX"
m = mega.login(email, password)
# Get the file descriptor of a previously uploaded file
filename='file_example_MP3_700KB.mp3'
filedesc = m.find(filename)
with tempfile.TemporaryDirectory() as tmpdir:
# Download the file to a temporary directory
downloaded_file_name = m.download(filedesc, tmpdir)
# replace the following with pygame code for playing the downloaded_file_name file
print(downloaded_file_name)
Where email, password, and filename are replaced as appropriate.
Note that if my email/password are not correct I get a RequestError as in the question.
mega.errors.RequestError: ENOENT, Object (typically, node or user) not found
Once the file is downloaded it can be played in pygame as in https://www.geeksforgeeks.org/python-playing-audio-file-in-pygame/
A possibility to stream audio data is to first download the data, write the binary audio data into a virtual file (into memory) and then play audio from this file. The following example demonstrates how to play a wave file from a remote location:
from io import BytesIO
import requests
import simpleaudio
response = requests.get("https://www2.cs.uic.edu/~i101/SoundFiles/CantinaBand3.wav")
audio_stream = BytesIO()
audio_stream.write(response.content)
audio_stream.seek(0)
wave_obj = simpleaudio.WaveObject.from_wave_file(audio_stream)
wave_obj.sample_rate = 44000 # TODO: set this appropriately
play_obj = wave_obj.play() # start playing audio from bytes IO
play_obj.wait_done()
This example first downloads the file and then plays it. In order to properly stream the audio, you might to introduce asynchronous processing, e.g., based on threads or async programming, where one thread will fill the byte buffer and another plays from the buffer.
I would like to know what is the most elegant way to scrape live webcam (traffic) data, ideally using Python. The webcam feed is represented by an API, with each get request yielding a image of the currently available feed from the webcam. The feed in question has a 2/3 second delay and therefore there are ~ 30 images per minute that can be requested.
My current (trivial) solution simply queries the API in a loop (perhaps with a sleep timer) and then cleans up any duplicated images. However, this seems quite dirty and I was wondering if there is a cleaner/more elegant solution available.
In principal I would like the solution to (if at all possible) avoid:
downloading duplicated images
sleep timers
looping
Is something like this possible?
To avoid sleep timers in your code, you can write a process that is triggered by cron. Cron will handle running your script at defined intervals, such as every 2 seconds (60s / 30 images per minute).
An example process might call the API using requests. Assuming an image is passed back, the following example code might work. If a JSON string is passed back then you will need to parse it and extract the image URL.
r = requests.get('https://traffic-cam-site.com/cam', auth=('user', 'pass'))
if r.status == 200:
image = r.content
To avoid downloading duplicate images, you would need to know when a new image is present on the API. You will need to periodically check the cam site API for this purpose. Store a hash of the collected images in a database (or text file), and send that with your request to the API. Then hash the image that is currently present on the cam site - if the hashes match, don't download the image to your server.
Alternatively, if the cam site API does push notifications then you may be notified when a new image is present.
I have an HLS stream that expires every 12 hours and a new link is generated. How can I create one static HLS stream?
One idea I've thought of is to keep refreshing the stream and forwarding it to one static URL? Is this possible and could anyone point me to resources on how to do this?
One idea is, you can make a static link like M3U8 file which will be containing the link of your HLS streaming service.
Thereafter, you can update your M3U8 file every 12 hours as HLS streaming link get updated.
Therefore, the M3U8 file will be a static link forever.
A brief introduction is given here about M3U8 files.