Converting audio data from RTMP Stream to PCM or WAV format in Python

Viewed 380

We have an audio stream running on an RTMP server and we tried to use librtmp library in Python to read the stream. We used the following code to get the stream data-

import librtmp

# Create a connection
conn = librtmp.RTMP("rtmp://your.server.net/app/playpath", live=True)
# Attempt to connect
conn.connect()
# Get a file-like object to access to the stream
stream = conn.create_stream()
# Read 1024 bytes of data
data = stream.read(1024)

This is the result when I print data:

b'FLV\x01\x05\x00\x00\x00\t\x00\x00\x00\x00\x12\x00\x01M\x00\x00\x00\x00\x00\x00\x00\x02\x00\nonMetaData\x03\x00\x08duration\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08filesize\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05width\x00@\x94\x00\x00\x00\x00\x00\x00\x00\x06height\x00@\x86\x80\x00\x00\x00\x00\x00\x00\x0cvideocodecid\x02\x00\x04avc1\x00\rvideodatarate\x00@i\x00\x00\x00\x00\x00\x00\x00\tframerate\x00@>\x00\x00\x00\x00\x00\x00\x00\x0caudiocodecid\x02\x00\x04mp4a\x00\raudiodatarate\x00@`\x00\x00\x00\x00\x00\x00\x00\x0faudiosamplerate\x00@\xe7p\x00\x00\x00\x00\x00\x00\x0faudiosamplesize\x00@0\x00\x00\x00\x00\x00\x00\x00\raudiochannels\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x06stereo\x00?\xf0\x00\x00\x00\x00\x00\x00\x00\x07encoder\x02\x00\x1eRogue Amoeba RTMP Streamer 1.0\x00\x00\t\x00\x00\x01X\x08\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\xaf\x00\x11\x90\x00\x00\x00\x0f'

The data object contains encoded data with FLV tags and due to insufficient documentation , we have been unable to use data to convert to PCM format. So is there a way to do this? Or are there other libraries in Python to read rtmp stream and convert to PCM format?

0 Answers
Related