-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
38 lines (32 loc) · 998 Bytes
/
play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import ffmpeg
import numpy as np
from subprocess import TimeoutExpired
def read_audio_from_rtsp(rtsp_url, output_file):
process = (
ffmpeg
.input(rtsp_url)
.output(output_file, format='wav', acodec='pcm_s16le', ac=2, ar='44100', b='192k', bufsize='1920k')
.overwrite_output()
.run_async(pipe_stderr=True)
)
try:
while True:
try:
process.wait(timeout=1)
break
except TimeoutExpired:
print("Enregistrement en cours...")
continue
except KeyboardInterrupt:
process.terminate()
break
except Exception as e:
print(f"An error occurred: {e}")
finally:
process.terminate()
process.wait()
print(f"Audio saved to {output_file}")
# Exemple d'utilisation
rtsp_url = "rtsp://localhost:8554/mic"
output_file = "recorded_audio.wav"
read_audio_from_rtsp(rtsp_url, output_file)