Readit News logoReadit News
Posted by u/jjcm a year ago
Show HN: LLMpeggithub.com/jjcm/llmpeg...
Inspired by the "ffmpeg by examples" comments, here's a simple script that pulls it all together. Set your OpenAI API key env var and make the script executable, and you're golden.
PaulKeeble · a year ago
FFMpeg is one of those tools that is really quite hard to use. The sheer surface area of the possible commands and options is incredible and then there is so much arcane knowledge around the right settings. Its defaults aren't very good and lead to poor quality output in a lot of cases and you can get some really weird errors when you combine certain settings. Its an amazingly capable tool but its equipped with every foot gun going.
fastily · a year ago
ffmpeg has abysmal defaults. I've always been of the opinion that CLI utilities should have sane defaults useful to a majority of users. As someone who has used ffmpeg for well over a decade, I find it baffling that you have to pass so many arguments to get an even remotely usable result
jasonjmcghee · a year ago
For certain file formats, it's true (e.g. gif), but I gotta say- I use "ffmpeg -i input.mov output.mp4" after taking a video on mac, and it looks good and is a tiny fraction (sometimes 100x smaller) of the size.
Vampiero · a year ago
it should really just have an interactive mode that supports batching. It would cover 99% of use cases.

I recommend everyone ITT to just use Handbrake (a GUI) unless they have extremely niche use cases. What's the point of using a LLM? You just need one person who knows ffmpeg better than you to write a GUI. And someone did. So use that.

If Handbrake doesn't solve your problem please just go to Stack Overflow. The LLM was trained there anyway, and your use case is not novel.

bambax · a year ago
The basics aren't that hard to remember. I posted this here a couple of days ago in another ffmpeg thread:

https://news.ycombinator.com/item?id=42708088

varenc · a year ago
great intro guide!

I'd say another big tip is getting proper ffmpeg completion into your shell. That's helpful for seeing a list of all possible encoders, pixel formats, etc.

I also found that playing around with filters in mpv was a great what to learn the ffmpeg filter expression language!

vunderba · a year ago
It's good that you have a "read" statement to force confirmation by the user of the command, but all it takes is one errant accidental enter to end up running arbitrary code returned from the LLM.

I'd constrain the tool to only run "ffmpeg" and extract the options/parameters from the LLM instead.

magistr4te · a year ago
I finished shellmind (https://github.com/wintermute-cell/shellmind) a few days ago, and it might interest you! It avoids having to copy-paste commands, by integrating directly into the shell and let's you review the real command before send-off. It's also general purpose and can handle more then just ffmpeg.
kernel-panics · a year ago
Coincidentally I made a shell script (https://github.com/pgodschalk/dotfiles/blob/main/bin/ai) around the same time, though it doesn't put the command in the buffer. I might borrow that idea. One thing I did add though, and would recommend, is an --explain flag. Usually if I don't know e.g. ffmpeg, I tend to want a short overview of what I'm actually about to run.
sovok · a year ago
Seems to be a common thing. I did something similar two days ago. Pretty helpful so far: https://github.com/combatwombat/cmdline-ai-helper

Dead Comment

minimaxir · a year ago
The system prompt may be a bit too simple, especially when using gpt-4o-mini as the base LLM that doesn't adhere to prompts well.

> You write ffmpeg commands based on the description from the user. You should only respond with a command line command for ffmpeg, never any additional text. All responses should be a single line without any line breaks.

I recently tried to get Claude 3.5 Sonnet to solve an FFmpeg problem (write a command to output 5 equally-time-spaced frames from a video) with some aggressive prompt engineering and while it seems internally consistent, I went down a rabbit hole trying to figure out why it didn't output anything, as the LLMs assume integer frames-per-second which is definitely not the case in the real world!

sdesol · a year ago
I asked your question across multiple LLMs and had them reviewed by multiple LLMs. DeepSeek Chat said Claude 3.5 Sonnet produced an invalid command. Here is my chat.

https://beta.gitsense.com/?chats=197c53ab-86e9-43d3-92dd-df8...

Scroll to the bottom on the left window to see that Claude acknowledges that the command that DeepSeek produced was accurate. In the right window, you'll find the conversation I had with DeepSeek chat about all the commands.

I then asked all the models again if the DeepSeek generated command was correct and they all said no. And when I asked them to compare all the "correct" commands, Sonnet and DeepSeek said Sonnet was the accurate one:

https://beta.gitsense.com//?chat=47183567-c1a6-4ad5-babb-9bb...

That command did not work but I got the impression that DeepSeek could probably get me a working solution, so after telling it the errors I keep getting, it got to a point where it could write a bash script for me to get 5 equally spaced frames.

I guess the long story short is, changing the prompt probably won't be enough and you will need to constantly shop around to see which LLM will most likely give the correct response based on the question you are asking.

minimaxir · a year ago
So that last one is a hallucination: there's no `n_frames` variable for the select filter: https://ffmpeg.org/ffmpeg-filters.html#select_002c-aselect

At the least, I learnt a lot about how FFmpeg works.

davmar · a year ago
i think this type of interaction is the future in lots of areas. i can imagine we replace API's completely with a single endpoint where you hit it up with a description of what you want back. like, hit up 'news.ycombinator.com/api' with "give me all the highest rated submissions over the past week about LLMs". a server side LLM translates that to SQL, executes the query, returns the results.

this approach is broadly applicable to lots of domains just like FFMpeg. very very cool to see things moving in this direction.

sitkack · a year ago
Do you envision the LLMs creating a protocol? Would the caller supply the schema for the response?
andai · a year ago
I mentioned here recently that I let LLMs design the APIs which they are going to use. I got quite a negative response to that, which surprised me.
halJordan · a year ago
The big protocol doing this is called "Model Context Protocol" and it should've been a widely read/discussed post except hn has taken a wide anti-ai stance
varispeed · a year ago
Imagine that every API will be behind government gateway, checking all the queries before passing on to the real API and then checking its replies.
mochajocha · a year ago
Except you don't need an LLM to do any of this, and it's already computationally cheaper. If you don't know the results you want, you should figure that out first, instead of asking a Markov chain to do it.
tomrod · a year ago
I believe this approach is destined for a lot of disappointment. LLMs enable a LOT of entry- and mid-level performance, quickly. Rightfully, you and I worry about the edge cases and bugs. But people will trend towards things that enable them to do things faster.
leobg · a year ago
This should be a terminal utility.

   xx ffmpeg video1.mp4 normalize audio without reencoding video to video2.mp4
And have sensible defaults. Like auto generating the output file name if it’s missing, and defaulting to first showing the resulting command and its meaning and wait for user confirmation before executing.

andai · a year ago
Indeed it should support all commands. ffmpeg shouldn't even be relevant, that's just an implementation detail. If a command is missing, it should be installed.

Just tell the computer what you want, and it figures out how to do it. Isn't that the dream?

I think the logical conclusion here is replacing the shell with GPT. It might not be a good idea — yet — but it's certainly possible already.

halJordan · a year ago
There are already bash replacements and cli tools doing this. The main thing here is how acerbic the anti-AI luddites that prevent the knowledge of this stuff from propagating
mikepalmer · a year ago
aider https://aider.chat/ basically does this already.

% aider

[...]

> do this on command line: ffmpeg cat\ meets\ skunk.mp4 normalize audio without reencoding video to video2.mp4

To normalize the audio without re-encoding the video, we'll use ffmpeg's loudnorm filter and stream copy for video. Here's the command:

ffmpeg -i "cat meets skunk.mp4" -c:v copy -af loudnorm -c:a aac video2.mp4

This command:

• Uses -c:v copy to stream copy the video (no re-encoding) • Applies loudnorm filter to normalize audio • Re-encodes only the audio using AAC codec • Outputs to video2.mp4

[...]

Run shell command? (Y)es/(N)o/(D)on't ask again [Yes]:

kazinator · a year ago
Parsing simple English and converting it to ffmpeg commands can be done without an LLM, running locally, using megabytes of RAM.

Check out this AI:

  $ apt install cdecl
  [ ... ]
  After this operation, 62.5 kB of additional disk space will be used.
  [ ... ]
  $ cdecl
  Type `help' or `?' for help
  cdecl> declare foo as function (pointer to char) returning pointer to array 4 of pointer to function (double) returning double
  double (*(*foo(char *))[4])(double )
Granted, this one has a very rigid syntax that doesn't allow for variation, but it could be made more flexible.

If FFMpeg's command line bugged me badly enough, I'd write "ffdecl".

_w1tm · a year ago
> Granted, this one has a very rigid syntax that doesn't allow for variation, but it could be made more flexible.

That’s kind of the killer feature of an LLM. You don’t even need to have your fingers on the right place on the keyboard and it will parse gibberish correctly as long as it’s shifted consistently.

airstrike · a year ago
I tell Claude to do things like I have brainrot and it still understands me like "ok, gib fn innew codblock"
unleaded · a year ago
"declare foo as function (pointer to char) returning pointer to array 4 of pointer to function (double) returning double" i would not call English
mochajocha · a year ago
Terms of art aren't not English just because they're inscrutable to non-experts.
bdhcuidbebe · a year ago
That should be crystal clear to the hn crowd, or is that no longer the case?
xnx · a year ago
Reminds me of llm-jq: https://github.com/simonw/llm-jq
jchook · a year ago
Most commonly I use ffmpeg to extract a slice of an audio or video file without re-encoding.

In case it interests folks, I made a tool called ffslice to do this: https://github.com/jchook/ffslice/

npollock · a year ago
does the tool snap to I-frames when slicing?
miles · a year ago
I don't know about ffslice, but you can get frame-perfect slicing with minimal reencoding via LosslessCut's experimental "smart cut" feature[2] or Smart Media Cutter's[3] smartcut[4].

[1] https://github.com/mifi/lossless-cut

[2] https://github.com/mifi/lossless-cut/issues/126

[3] https://smartmediacutter.com/

[4] https://github.com/skeskinen/smartcut

jchook · a year ago
Yes, the tool snaps to I-frames when slicing. The `-c copy` flag ensures no re-encoding, and inherently limits cuts to keyframes.

TBH it's an unfortunate side-effect sometimes as you cannot cut video or audio exactly where you want.

oguz-ismail · a year ago
>without re-encoding

What do you think?