Is Camera Audio Hampered at 64kbit telephone audio?

Have some questions or having issues with the Amcrest WebUI? Post them here for the mods and other users to assist you.
Post Reply
ultimatecodewarrior
Posts: 26
Joined: Mon Jan 13, 2025 3:04 pm

Is Camera Audio Hampered at 64kbit telephone audio?

Post by ultimatecodewarrior »

Hi All,

According to the HTTP API, it seems that Audio is limited.

Code: Select all

  http://192.168.0.109/cgi-bin/audio.cgi?action=getAudio&httptype=singlepart&channel=1

200 OK HTTP/1.1
Server: device/1.0
Content-Type: multipart/x-mixed-replace; boundary=<boundary>
--<boundary>
Content-Type: Audio/G.711A
Content-Length: 800
<Audio data>
--<boundary>
Telephone quality audio 8,000 samples per second, 8 bits per sample, mono.    64kbits per second
300-3400 Hz

Is that the best it can do? I would have paid another $1.50 for something like this 20-20khz

Code: Select all

https://www.adafruit.com/product/1064
I mean if the goal was do do some audio processing and detect things like:

"Types": [
"AudioCrashingGlass",
"AudioScream",
"AudioGunshot",
"AudioExplosion"
]

I think a better quality than 8,000 HZ might be in order. Is there a Camera that has a better Mic or an audio Jack to plug one in?
ultimatecodewarrior
Posts: 26
Joined: Mon Jan 13, 2025 3:04 pm

Re: Is Camera Audio Hampered at 64kbit telephone audio?

Post by ultimatecodewarrior »

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.
Post Reply