Get Video from RTSP and stream by RTMP

Hi guys, i'm build a stream video realtime through rtmp but my camera video source is from an rtsp link. i used Membrane.RTSP.Source but got stuck and many error. please help me, thanks you.
7 Replies
Feliks
Feliks3w ago
Could you provide some code and error messages? It is hard to solve your problem without that. Or maybe you don't know how to approach the problem and what operations have to be done in the pipeline you need?
ℓé
ℓéOP3w ago
yeah, this is my code and the error log below: == Compilation error in file lib/baseline_camera.ex == ** (exit) {:membrane_child_crash, :video_source, {%KeyError{key: #Reference<0.2512758526.2801270788.174057>, term: %{}, message: nil}, [{:erlang, :map_get, [#Reference<0.2512758526.2801270788.174057>, %{}], [error_info: %{module: :erl_erts_errors}]}, {Membrane.RTSP.Source, :handle_pad_added, 3, [file: ~c"lib/membrane_rtsp_plugin/source.ex", line: 220]}, {Membrane.Core.CallbackHandler, :exec_callback, 4, [file: ~c"lib/membrane/core/callback_handler.ex", line: 139]}, {Membrane.Core.CallbackHandler, :exec_and_handle_callback, 5, [file: ~c"lib/membrane/core/callback_handler.ex", line: 69]}, {Membrane.Core.Bin, :handle_info, 2, [file: ~c"lib/membrane/core/bin.ex", line: 196]}, {:gen_server, :try_dispatch, 4, [file: ~c"gen_server.erl", line: 1123]}, {:gen_server, :handle_msg, 6, [file: ~c"gen_server.erl", line: 1200]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 240]}]}}
ℓé
ℓéOP3w ago
Billal
Billal3w ago
The issue is that you link Membrane.RTSP.Source pads directly to other elements which is not how the plugin works. You have to wait for notification from the rtsp source before linking to other elements. Check the documentation for an example: https://hexdocs.pm/membrane_rtsp_plugin/readme.html#usage And by the way the RTSP video output will be encoded access units, so you cannot feed it directly to a pixel converter, you need first to decode it. and the decoder output will be :I420 images most of the time so you don't need the converter only the decoder.
ℓé
ℓéOP3w ago
yeah, thank you for your replied, i have all ready read the document and test a small program take the video source(location: video.h264). But i'm still get stuck. I don't understand much about membrane framework and the flow of video, audio going. can you help me write a sample on it.
Billal
Billal3w ago
Share your code in github or somewhere else to review it Looking at your pipeline now, I noticed that you're using RTSP to read from a local webcam, it'll not work since the webcam don't use rtsp protocol. I tried a test with my webcam (only video) with the following code and it works fine
defmodule Pipeline do
use Membrane.Pipeline

def handle_init(_ctx, _opts) do
spec = [
child(:camera, %Membrane.CameraCapture{device: "/dev/video1"})
|> child(:converter, %Membrane.FFmpeg.SWScale.Converter{format: :I420})
|> child(:overlay, %Membrane.OverlayFilter{
initial_overlay: %Membrane.OverlayFilter.OverlayDescription{
overlay: "/path/to/logo.png",
x: :right,
y: :top
}
})
|> child(:video_encoder, %Membrane.H264.FFmpeg.Encoder{
profile: :baseline,
preset: :ultrafast,
tune: :zerolatency
})
|> child(:video_payloader, %Membrane.H264.Parser{
output_stream_structure: :avc1,
}
)
|> via_in(Pad.ref(:video, 0))
|> child(:sink, %Membrane.RTMP.Sink{
rtmp_url: "rtmp://127.0.0.1:1935/live",
tracks: [:video],
max_attempts: 10
})
]

{[spec: spec], %{}}
end
end
defmodule Pipeline do
use Membrane.Pipeline

def handle_init(_ctx, _opts) do
spec = [
child(:camera, %Membrane.CameraCapture{device: "/dev/video1"})
|> child(:converter, %Membrane.FFmpeg.SWScale.Converter{format: :I420})
|> child(:overlay, %Membrane.OverlayFilter{
initial_overlay: %Membrane.OverlayFilter.OverlayDescription{
overlay: "/path/to/logo.png",
x: :right,
y: :top
}
})
|> child(:video_encoder, %Membrane.H264.FFmpeg.Encoder{
profile: :baseline,
preset: :ultrafast,
tune: :zerolatency
})
|> child(:video_payloader, %Membrane.H264.Parser{
output_stream_structure: :avc1,
}
)
|> via_in(Pad.ref(:video, 0))
|> child(:sink, %Membrane.RTMP.Sink{
rtmp_url: "rtmp://127.0.0.1:1935/live",
tracks: [:video],
max_attempts: 10
})
]

{[spec: spec], %{}}
end
end
ℓé
ℓéOP23h ago
sorry for the late of response. because the luna new year, your code is about using the usb camera. But my task is on camera conecttion by LAN and get source from rstp server.

Did you find this page helpful?