Reputation: 2812
I have a webcam that stream the video/audio via rtsp. I wish to make a small program that only detect the audio stream and make a room loudness detection.
My plan is to use ffmpeg
to get the audio stream only as a stream of integer/float to stdout. So that I can read the stream in Python or Go as callback and analyse and decibles.
I found an example:
ffmpeg -i rtsp://some_url -c:a aac -c:v copy -hls_list_size 65535 -hls_time 2 "./live.m3u8"
But this write the whole video to files. Any suggestion how to change that?
I am also open to any other solution/packages in other languages that I can do something like
connection = RTSP('rtsp://url')
signal_array = connection.read_audio_frame()
Please advice
Upvotes: 1
Views: 2514
Reputation: 5954
ffmpeg can be made to output to stdout by adding pipe:
. Per the docs:
The accepted syntax is:
pipe:[number]
number is the number corresponding to the file descriptor of the pipe (e.g. 0 for stdin, 1 for stdout, 2 for stderr). If number is not specified, by default the stdout file descriptor will be used for writing, stdin for reading.
http://ffmpeg.org/ffmpeg-all.html#pipe
Personally I would use this in conjunction with a named pipe (FIFO):
mkfifo /tmp/videofifo
ffmpeg -i myfile.mp4 -f avi pipe: > /tmp/videofifo
with open("/tmp/videofifo", "rb") as f:
...
Of course, for your use case, you use your ffmpeg command, and you open the fifo in "r"
not "rb"
mode.
The advantage of using a fifo over just capturing stdout (with subprocess.PIPE
directly is probably minimal in your case (ascii data linewise) but seems cleaner in the case of binary data. In any case I prefer to keep the data separate from how I got it. If you do just want to handle stdout directly, use p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
and then work on p.stdout
, which is a file-like object.
Doubtless there are equivalent ways to launch subprocesses in Go, but to my shame I don't actually know Go at all at the moment.
Upvotes: 2