I have an external Python script sending out a WAV file over RTSP through mediamtx. I receive the stream in TouchDesigner with an Audio Stream In CHOP. The issue, however, is that I only hear the rear-end of the WAV, and it repeats on loop while the stream has already ended. For example when I generate “1,2,3,4,5,6,7” using TTS I only hear: 4,5,6,7…,4,5,6,7… etc. While in FFMPEG the stream has already finished, and mediamtx has closed the connection.
import subprocess
import os
import threading
def stream_wav_rtsp(path):
print(f"[FFmpeg] Streaming {path} to rtsp://localhost:8554/mystream")
ffmpeg_cmd = [
"ffmpeg",
"-re",
"-i", path,
"-vn",
"-c:a", "aac",
"-f", "rtsp",
"rtsp://localhost:8554/mystream"
]
try:
proc = subprocess.Popen(ffmpeg_cmd)
def cleanup():
proc.wait()
os.remove(path)
print("[FFmpeg] Stream finished and file removed.")
threading.Thread(target=cleanup, daemon=True).start()
except Exception as e:
print(f"[FFmpeg] Error: {type(e).__name__}: {e}")
os.remove(path)
stream_wav_rtsp("voice123.wav")
I have added the following to the mediamtx yml file:
paths:
mystream:
source: publisher
record: false
runOnDemand: ""
fallback: ""
In TouchDesigner I simply have an Audio Stream In CHOP with the URL: rtsp://localhost:8554/mystream
Does anyone know why this happens? Or have a better/simpler way of streaming audio (from a remote server)? The machine running TouchDesigner is not the same machine as where the audio file is generated.