kens
Rerun command if it die in elixir
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)
First Post!
tty
Typically we would do the following: Port.open returns a port(). You can monitor this port() using Port.monitor/1
If ffmpeg dies it will send a {:DOWN, ref, :port, object, reason} to GenServer.handle_info allowing you to act on it.
Popular in Questions
can someone please explain to me how Enum.reduce works with maps
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217
Let’s say I have a map with required and optional k...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New








