kens

kens

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)

Showing Posts 1 to 7

tty

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.

kens

kens OP

I added this code:

port = Port.open({:spawn, exec}, [:binary])
Port.monitor(port)

....
def handle_info({:DOWN, ref, :port, object, reason}, state) do
    IO.inspect "========= DOWN =============="
    IO.inspect reason
    {:noreply, state}
end

it always run to :DOWN with reason :normal, I change exec query to error it continue run the same

tty

tty

Can you force ffmpeg to terminate unexpectedly to see if the “reason” changes ?

kens

kens OP

I try it, but it same, I change wrong command to exec, but it not change reason

tty

tty

Given this you might have to call a shell script which exec ffmpeg. The shell script can traps it dying unexpectedly and returning an error code if that occurs.

OvermindDL1

OvermindDL1

erlexec or porcelain can do that for you as well with their helper addons.

kens

kens OP

I am wrong with command, I remove >/dev/null 2>&1 & and it work

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews