You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello guys, I have this prototype and I'm trying to create 2 pipe outputs for video and audio, but video part doesn't work.
Do you know how this problem could be solved?
Audio works as is, and if you comment out audio-related stuff, video works, too.
import ffmpeg
import numpy as np
if __name__ == '__main__':
# Input opts for ffmpeg.probe() and ffmpeg.input()
input_opts = {'threads': 1, 'fflags': 'nobuffer'}
# Probe - discover parameters of the stream
rtsp_stream_link = 'rtsp://SOME_LINK'
probe = ffmpeg.probe(rtsp_stream_link, **input_opts)
# Get video stream info (video frame width, height)
video_stream_info = None
for substream in probe['streams']:
if substream['codec_type'] == 'video':
video_stream_info = substream
width = int(video_stream_info['width'])
height = int(video_stream_info['height'])
# Open RTSP stream
rtsp_stream = ffmpeg.input(rtsp_stream_link, **input_opts)
video_output_opts = {'f': 'rawvideo', 'pix_fmt': 'rgb24'}
rtsp_video_pipe_output = (
rtsp_stream.video
.output('pipe:v', **video_output_opts)
.global_args('-y', '-loglevel', 'panic')
.run_async(pipe_stdout=True)
)
save_output_opts = {'vcodec': 'h264'}
video_file_output = (
ffmpeg
.input('pipe:v', format='rawvideo', pix_fmt='rgb24', s='{}x{}'.format(width, height))
.output('video_out.mp4', **save_output_opts)
.overwrite_output()
.run_async(pipe_stdin=True)
)
rtsp_audio_pipe_output = (
rtsp_stream.audio
.output('pipe:a', format='f32le', acodec='pcm_s32le', ac=1, ar='48k')
.global_args('-y', '-loglevel', 'panic')
.run_async(pipe_stdout=True)
)
save_output_opts = {'loglevel': 'error', 'codec:a': 'libmp3lame', 'f': 'mp3'}
audio_file_output = (
ffmpeg
.input('pipe:a', format='f32le', acodec='pcm_s32le', ac=1, ar='48k')
.output('audio_out.mp3', **save_output_opts)
.overwrite_output()
.run_async(pipe_stdin=True)
)
start_timestamp_sec = 0
while True:
# Video frame bytes logic
poll_video_data = rtsp_video_pipe_output.poll()
if poll_video_data is None:
# Read bytes from pipe_output
in_video_bytes = rtsp_video_pipe_output.stdout.read(width * height * 3)
if in_video_bytes:
# Transform bytes to pixels
pixels = (
np.frombuffer(in_video_bytes, np.uint8)
.reshape([height, width, 3])
)
video_file_output.stdin.write(
pixels
.astype(np.uint8)
.tobytes()
)
# Audio frame bytes logic
poll_audio_data = rtsp_audio_pipe_output.poll()
if poll_audio_data is None:
in_audio_bytes = rtsp_audio_pipe_output.stdout.read(4*48000)
if in_audio_bytes:
if len(in_audio_bytes) == 4*48000:
audio_file_output.stdin.write(in_audio_bytes)
The text was updated successfully, but these errors were encountered:
Hello guys, I have this prototype and I'm trying to create 2 pipe outputs for video and audio, but video part doesn't work.
Do you know how this problem could be solved?
Audio works as is, and if you comment out audio-related stuff, video works, too.
The text was updated successfully, but these errors were encountered: