修改成用rtmpstream推送实时流

This commit is contained in:
lihengzhong 2023-12-27 12:37:03 +08:00
parent e4b2cab164
commit f0b46ddb8e
2 changed files with 27 additions and 5 deletions

2
app.py
View File

@ -191,6 +191,8 @@ if __name__ == '__main__':
parser.add_argument('--asr_model', type=str, default='cpierse/wav2vec2-large-xlsr-53-esperanto')
# parser.add_argument('--asr_model', type=str, default='facebook/wav2vec2-large-960h-lv60-self')
parser.add_argument('--push_url', type=str, default='rtmp://localhost/live/livestream')
parser.add_argument('--asr_save_feats', action='store_true')
# audio FPS
parser.add_argument('--fps', type=int, default=50)

View File

@ -7,6 +7,7 @@ import subprocess
import os
from asrreal import ASR
from rtmp_streaming import StreamerConfig, Streamer
class NeRFReal:
def __init__(self, opt, trainer, data_loader, debug=True):
@ -53,6 +54,25 @@ class NeRFReal:
if self.opt.asr:
self.asr = ASR(opt)
fps=25
#push_url='rtmp://localhost/live/livestream' #'data/video/output_0.mp4'
sc = StreamerConfig()
sc.source_width = self.W
sc.source_height = self.H
sc.stream_width = self.W
sc.stream_height = self.H
sc.stream_fps = fps
sc.stream_bitrate = 1000000
sc.stream_profile = 'main' #'high444' # 'main'
sc.audio_channel = 1
sc.sample_rate = 16000
sc.stream_server = opt.push_url
self.streamer = Streamer()
self.streamer.init(sc)
self.streamer.enable_av_debug_log()
'''
video_path = 'video_stream'
if not os.path.exists(video_path):
os.mkfifo(video_path, mode=0o777)
@ -61,8 +81,6 @@ class NeRFReal:
os.mkfifo(audio_path, mode=0o777)
width=450
height=450
fps=25
push_url='rtmp://localhost/live/livestream' #'data/video/output_0.mp4'
command = ['ffmpeg',
'-y', #'-an',
#'-re',
@ -90,6 +108,7 @@ class NeRFReal:
self.fifo_video = open(video_path, 'wb')
self.fifo_audio = open(audio_path, 'wb')
#self.test_step()
'''
def __enter__(self):
@ -127,13 +146,14 @@ class NeRFReal:
outputs = self.trainer.test_gui_with_data(data, self.W, self.H)
print(f'[INFO] outputs shape ',outputs['image'].shape)
image = (outputs['image'] * 255).astype(np.uint8)
self.streamer.stream_frame(image)
#self.pipe.stdin.write(image.tostring())
for _ in range(2):
frame = self.asr.get_audio_out()
print(f'[INFO] get_audio_out shape ',frame.shape)
frame = (frame * 32767).astype(np.int16).tobytes()
self.fifo_audio.write(frame)
self.fifo_video.write(image.tostring())
self.streamer.stream_frame_audio(frame)
# frame = (frame * 32767).astype(np.int16).tobytes()
# self.fifo_audio.write(frame)
else:
if self.audio_features is not None:
auds = get_audio_features(self.audio_features, self.opt.att, self.audio_idx)