如何从无尽的音频流中获取和分开音频

发布于 2025-01-24 17:51:31 字数 747 浏览 5 评论 0原文

首先,我有一个无尽的凸轮流,其中包括音频和视频。

如何根据RTSP流中的时间间隔在流媒体流中进行分配。

我已经尝试了下面的代码,但是在流结束之前我无法获取音频数据

command = ['ffmpeg.exe',
                   '-i', 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4',
                   '-f', 's16le',
                   '-acodec', 'libmp3lame',
                   '-ar', '44100',  
                   '-ac', '2', 
                   '-']
 
pipe = sp.Popen(command, stdout=sp.PIPE)

raw_audio = self.pipe.stdout.read()
print(raw_audio)

Firstly I have an endless cam stream which includes audio and video.

How to get divided .wav files according to time intervals from RTSP streaming while streaming.

I want to

I have tried the code below but I couldn't get the audio data before the stream ended

command = ['ffmpeg.exe',
                   '-i', 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4',
                   '-f', 's16le',
                   '-acodec', 'libmp3lame',
                   '-ar', '44100',  
                   '-ac', '2', 
                   '-']
 
pipe = sp.Popen(command, stdout=sp.PIPE)

raw_audio = self.pipe.stdout.read()
print(raw_audio)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2025-01-31 17:51:31

尝试 -f segment 输出容器。类似:

command = ['ffmpeg.exe',
    "-i", r"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4",
    '-vn', '-acodec', 'pcm_s16le', '-ar', '44100', '-ac', '2', 
    "-f", "segment", '-segment_time','3','out%03d.wav']
)

现在,如果您真正需要的是原始样本,而不一定是.wav文件,则需要通过删除' - acodec','libmp3lame'来修复命令,并指定号码要阅读的样本:

# how to read a block of audio data from stdout
n = 44100 * 3 # # of samples (sampling rate * duration)
nbytes = n * 2 * 2 # (#samples * #ch  * 2 bytes/sample)
while True:
    raw_audio = np.frombuffer(self.pipe.stdout.read(nread),shape=(n,2), dtype=np.int16)

    ... # do your thing

Try -f segment output container. Something like:

command = ['ffmpeg.exe',
    "-i", r"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4",
    '-vn', '-acodec', 'pcm_s16le', '-ar', '44100', '-ac', '2', 
    "-f", "segment", '-segment_time','3','out%03d.wav']
)

Now, if what you really need are the raw samples and not necessarily .wav files, you need to fix your command by removing the '-acodec', 'libmp3lame' option and specify the number of samples to read:

# how to read a block of audio data from stdout
n = 44100 * 3 # # of samples (sampling rate * duration)
nbytes = n * 2 * 2 # (#samples * #ch  * 2 bytes/sample)
while True:
    raw_audio = np.frombuffer(self.pipe.stdout.read(nread),shape=(n,2), dtype=np.int16)

    ... # do your thing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文