Hi All,
After about 3 hours of hair pulling, figured out that the HTTP API documentation is outdated/wrong when it comes to Audio Streams, looks like it's not G711a - 8khz A-law, but rather AAC. Shame on them for not giving a hint/updating I can't stand misdirection. The good news is that it might be better than the Telephone quality audio they were extolling in the HTTP API documentation.
Anyhow if you want to extract the Audio, you will need to authenticate with HTTPDigest and lock on the stream, here is a python3 example on how to obtain:
Code: Select all
import requests
from requests.auth import HTTPDigestAuth
def download_aac_stream(url, output_file, duration=10, username='', password=''):
"""
Downloads and saves an AAC audio stream to a file.
Parameters:
url (str): URL of the AAC audio stream.
output_file (str): Filepath to save the AAC file.
duration (int): Duration to record the stream in seconds.
username (str): Username for digest authentication.
password (str): Password for digest authentication.
"""
try:
# Connect to the stream with digest authentication
print(f"Connecting to {url}...")
response = requests.get(url, stream=True, auth=HTTPDigestAuth(username, password))
response.raise_for_status()
# Open the output file for writing
with open(output_file, "wb") as file:
print("Recording audio stream...")
bytes_written = 0
sample_rate = 8000 # Assuming 8 kHz sampling rate for duration calculation
bits_per_sample = 16 # Assuming 16 bits per sample for duration calculation
for chunk in response.iter_content(chunk_size=1024):
if not chunk:
break
# Write AAC data directly into the file
file.write(chunk)
bytes_written += len(chunk)
# Stop after the specified duration
if bytes_written >= sample_rate * duration * (bits_per_sample // 8):
break
print(f"Audio stream saved to {output_file}")
except Exception as e:
print(f"An error occurred: {e}")
# Usage example
stream_url = "http://192.168.0.109/cgi-bin/audio.cgi?action=getAudio&httptype=singlepart&channel=1"
output_aac = "output_audio.aac"
username = "admin"
password = "admin"
download_aac_stream(stream_url, output_aac, duration=10, username=username, password=password)
I used a SNAP install on Ubuntu 24 to install Audacity to view / play the file.
There looks to be a way to download the audio/video with the RSTP stream using ffmpeg, but I really wanted to not just download to MP4, but rather wanted to do frame over frame processing of both audio and data and combine both into a MP4 when I am done. ffmpeg would have to be launched with a sub process, not terrible, but real time A/V detection goes out the window.
Code: Select all
https://gist.github.com/ChronoMonochrome/f56014ad06d107e02c1387ea61a62a7a
Really looking for a way to just strip it out of of the RSTP feed, don't know if OpenCV has that.