I want to transform programmatically an image with FFmpeg. I know you have nice libraries Image, Vix, Stb_image but I want to use the capacity of FFmpeg to take buffer as input. I don’t see how System.cmd
nor Port
can accept inputs from stdin so I sought for something.
I found Porcelain
and erlexec
. I saw the last commit was 4 years ago for Porcelaine. Not saying it’s bad but erlexec
has its last commit 2 months ago.
I can do it with Porcelaine
but not with erlexec
and I don’t see why. Maybe someone has some experience with it.
file = File.read!("img.png")
porcelaine = Porcelain.spawn("ffmpeg", ["-i", "-", "img.jpg"], in: :receive, out: :stream)
{:input, data} = Porcelain.Process.send_input(porcelaine, file)
File.write!("img.jpg", file)
#=> success
but not erlexec: “bad arguments”.
{:ok, pid, os_pid} = :exec.run("ffmpeg -i - img.jpg", [:stdin, stdout: "img2.jpg"])
:ok = :exec.send(os_pid, file)
[error] GenServer :exec terminating
** (stop) :einval
Last message: {:EXIT, #Port<0.6>, :einval}
Is it related to the way you pass strings to the function?