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)
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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
I added this code:
it always run to :DOWN with reason :normal, I change
execquery to error it continue run the sametty
Can you force ffmpeg to terminate unexpectedly to see if the “reason” changes ?
kens
I try it, but it same, I change wrong command to exec, but it not change reason
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
erlexec or porcelain can do that for you as well with their helper addons.
kens
I am wrong with command, I remove
>/dev/null 2>&1 &and it work