Hi, I use m3u8 to live stream audio, I use ffmpeg to convert from webrtc to m3u8. but some reason ffm (port not avaiable) can not start or it die when running. I want to Rerun it again with other port.
I use Supervisor and GenServer to do it. here my code:
defmodule FFmpeg.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, [])
end
def init(_) do
children = [
worker(FFmpeg.Service, [])
]
supervise(children, [strategy: :one_for_one])
end
end
defmodule FFmpeg.Service do
use GenServer
def init(:ok) do
{:ok, :ok}
end
def start_link do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
end
def start_ffmpeg(room) do
GenServer.call(__MODULE__, {:check, room})
end
def handle_call({:check, room}, _from, state) do
exec = "ffmpeg -analyzeduration 300M -probesize 300M -i #{sdp_file} -strict -2 -c:a aac -ar 16k -ac 1 -preset ultrafast -tune zerolatency -f flv #{path_rtmp_janus}/stream_#{room.id} -nostdin -nostats >/dev/null 2>&1 &"
Port.open({:spawn, exec}, [:binary]) # how to RERUN if it die
IO.inspect "========= END run ffmpeg =============="
{:reply, :ok}
end
end
and run by:
if !Process.whereis(FFmpeg.Service) do
FFmpeg.Supervisor.start_link()
end
FFmpeg.Service.start_ffmpeg(room)






















