ndrean
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?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
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
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
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 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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #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
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
The
stdoutoption toexecexpects a value matching theoutput_dev_optspec:https://github.com/saleyn/erlexec/blob/f5d9995448362489b349a1452cc3b1c0588d62c5/src/exec.erl#L306-L320
You’re passing a
binarythere, which isn’t on the list. Try a charlist (single quotes, or~cinstead.ndrean
I removed the stdout option, same result.
In their example, they use:
exec:send(I, <<"Test data\n">>).. Not sure what this means because I can’t stringify a file.saleyn
Perhaps you are not using the options correctly?
Terminal1:
Terminal2:
ndrean
Yes, you are right. But in fact, I don’t need the
:stdoutoption as FFmpeg knows what to do - namely save into “img.jpg” - as it is included in the command argument.FFmpeg only needs to know what his input is,
stdin.A test.
In a shell, I pipe from stdin and it works.
In IEX, I send an empty file in the buffer, it works, but when I pass an image, it fails.
In the shell:
In IEX:
The difference I see is that I am passing data as a string in the first case, and then a binary.
However, it seems to be able to use binaries, as shown below, so I don’t know.
In IEX:
saleyn
I see. The issue is that
ffmpegneeds to know that the input sent to it is complete. Otherwise, it’ll sit waiting for more data.When you use pipes in the shell, the head of the pipe (
cat img.png) closes the pipe upon sending the entire content of the file, which helpsffmpegdetect theeof.In case of
erlexecyou need to tell the child process that there’s an eof condition like this:This will fix your issue.
It is illustrated here.
ndrean
Ahh, I tried to append
\n(or ‘10’ in binary ?) to the file as in the example, but I failed.With almost zero knowledge of Erlang, and discovering that that atoms are Elixir specific, I wasn’t sure at all what it was.
Thanks for your time.
akash-akya
@ndrean I created
Exile&ExCmdspecifically to support moving large amount of data between external process. If you are interested you can check them out.I created a Livebook sometime back using
ffmpeg: Community Livebooks Thread - Share Yours! - #4 by akash-akyandrean
Looks nice! Many thanks!
I did not found
ex_cmd, more Elixir style.I will look more closely when I find why
System.find_executable("ffmepg")returnsnil! (Livebook only).I solved my problem with Porcelain by using a GenServer. The use case is receiving chunks as strings via a WebSocket. In the GenServer, I spawn Porcelain to start FFmpeg to read from stdin, and then just forward messages/chunks continuously to the GenServer and Porcelain feeds pipe:0.
I see you request files via a GET request, but in my case I want to receive octet-stream via HTTP and am stuck so I will definitively look more closely.