修改成用rtmpstream推送实时流
This commit is contained in:
parent
e4b2cab164
commit
f0b46ddb8e
2
app.py
2
app.py
|
@ -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='cpierse/wav2vec2-large-xlsr-53-esperanto')
|
||||||
# parser.add_argument('--asr_model', type=str, default='facebook/wav2vec2-large-960h-lv60-self')
|
# 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')
|
parser.add_argument('--asr_save_feats', action='store_true')
|
||||||
# audio FPS
|
# audio FPS
|
||||||
parser.add_argument('--fps', type=int, default=50)
|
parser.add_argument('--fps', type=int, default=50)
|
||||||
|
|
30
nerfreal.py
30
nerfreal.py
|
@ -7,6 +7,7 @@ import subprocess
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from asrreal import ASR
|
from asrreal import ASR
|
||||||
|
from rtmp_streaming import StreamerConfig, Streamer
|
||||||
|
|
||||||
class NeRFReal:
|
class NeRFReal:
|
||||||
def __init__(self, opt, trainer, data_loader, debug=True):
|
def __init__(self, opt, trainer, data_loader, debug=True):
|
||||||
|
@ -53,6 +54,25 @@ class NeRFReal:
|
||||||
if self.opt.asr:
|
if self.opt.asr:
|
||||||
self.asr = ASR(opt)
|
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'
|
video_path = 'video_stream'
|
||||||
if not os.path.exists(video_path):
|
if not os.path.exists(video_path):
|
||||||
os.mkfifo(video_path, mode=0o777)
|
os.mkfifo(video_path, mode=0o777)
|
||||||
|
@ -61,8 +81,6 @@ class NeRFReal:
|
||||||
os.mkfifo(audio_path, mode=0o777)
|
os.mkfifo(audio_path, mode=0o777)
|
||||||
width=450
|
width=450
|
||||||
height=450
|
height=450
|
||||||
fps=25
|
|
||||||
push_url='rtmp://localhost/live/livestream' #'data/video/output_0.mp4'
|
|
||||||
command = ['ffmpeg',
|
command = ['ffmpeg',
|
||||||
'-y', #'-an',
|
'-y', #'-an',
|
||||||
#'-re',
|
#'-re',
|
||||||
|
@ -90,6 +108,7 @@ class NeRFReal:
|
||||||
self.fifo_video = open(video_path, 'wb')
|
self.fifo_video = open(video_path, 'wb')
|
||||||
self.fifo_audio = open(audio_path, 'wb')
|
self.fifo_audio = open(audio_path, 'wb')
|
||||||
#self.test_step()
|
#self.test_step()
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
@ -127,13 +146,14 @@ class NeRFReal:
|
||||||
outputs = self.trainer.test_gui_with_data(data, self.W, self.H)
|
outputs = self.trainer.test_gui_with_data(data, self.W, self.H)
|
||||||
print(f'[INFO] outputs shape ',outputs['image'].shape)
|
print(f'[INFO] outputs shape ',outputs['image'].shape)
|
||||||
image = (outputs['image'] * 255).astype(np.uint8)
|
image = (outputs['image'] * 255).astype(np.uint8)
|
||||||
|
self.streamer.stream_frame(image)
|
||||||
#self.pipe.stdin.write(image.tostring())
|
#self.pipe.stdin.write(image.tostring())
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
frame = self.asr.get_audio_out()
|
frame = self.asr.get_audio_out()
|
||||||
print(f'[INFO] get_audio_out shape ',frame.shape)
|
print(f'[INFO] get_audio_out shape ',frame.shape)
|
||||||
frame = (frame * 32767).astype(np.int16).tobytes()
|
self.streamer.stream_frame_audio(frame)
|
||||||
self.fifo_audio.write(frame)
|
# frame = (frame * 32767).astype(np.int16).tobytes()
|
||||||
self.fifo_video.write(image.tostring())
|
# self.fifo_audio.write(frame)
|
||||||
else:
|
else:
|
||||||
if self.audio_features is not None:
|
if self.audio_features is not None:
|
||||||
auds = get_audio_features(self.audio_features, self.opt.att, self.audio_idx)
|
auds = get_audio_features(self.audio_features, self.opt.att, self.audio_idx)
|
||||||
|
|
Loading…
Reference in New Issue