top | item 42706637

Show HN: LLMpeg

169 points| jjcm | 1 year ago |github.com

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.

80 comments

order
[+] PaulKeeble|1 year ago|reply
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|1 year ago|reply
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
[+] vunderba|1 year ago|reply
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|1 year ago|reply
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.
[+] minimaxir|1 year ago|reply
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|1 year ago|reply
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.

[+] davmar|1 year ago|reply
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|1 year ago|reply
Do you envision the LLMs creating a protocol? Would the caller supply the schema for the response?
[+] varispeed|1 year ago|reply
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|1 year ago|reply
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.
[+] leobg|1 year ago|reply
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|1 year ago|reply
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.

[+] mikepalmer|1 year ago|reply
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|1 year ago|reply
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|1 year ago|reply
> 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.

[+] unleaded|1 year ago|reply
"declare foo as function (pointer to char) returning pointer to array 4 of pointer to function (double) returning double" i would not call English
[+] jchook|1 year ago|reply
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|1 year ago|reply
does the tool snap to I-frames when slicing?
[+] yreg|1 year ago|reply
FFmpeg is a tool that I now use purely with LLM help (and it is the only such tool for me). I do however want to read the explanation of what the AI-suggested command does and understand it instead of just YOLO running it like in this project.

I have had the experience where GPT/LLAMA suggested parameters that would have produced unintended consequences and if I haven't read their explanation I would never know (resulting in e.g. a lower quality video).

So, it would be wonderful if this tool could parse the command and quote the relevant parts of the man page to prove that it does what the user asked for.

[+] fourthark|1 year ago|reply
I always wonder what's the difference between LLMing shell commands and

  curl https://example.com | sh
[+] vishnuharidas|1 year ago|reply
I am eagerly waiting for software test frameworks to adapt LLM where I can simply write test cases as easy as - "Open the website, login using these credentials, click the logout button, go back to the previous page, and check if the user is not logged in" - and let the LLM do the job.

For those team that find it cumbersome to write test cases, LLM-assisted testing will be more fun, engaging, and productive as well.

[+] alpb|1 year ago|reply
I'd probably use GitHub's `??` CLI or `llm-term` that already this without needing to install a purpose-specific tool. Do you provide any specific value add on top of these?
[+] lutherqueen|1 year ago|reply
Probably the fact that the AI has only access to the ffmpeg command is a value itself. Supervision is much less needed vs something that could hallucinate using rm -rf on the wrong place
[+] forty|1 year ago|reply
Makes me want to fill GitHub with scripts like

#!/bin/bash

# extract sound from video

ffmep -h ; rm -fr /*

;)

[+] KingMob|1 year ago|reply
For anyone who wants a broader CLI tool, consider Willison's `llm` tool with the `cmd` plugin, or something like `shell_gpt`.
[+] magistr4te|1 year ago|reply
I think an important point is avoiding having to copy-paste the resulting command. A few days ago I finished shellmind (https://github.com/wintermute-cell/shellmind), which is a general purpose tool like shell_gpt, but integrates directly into the shell for a more efficient workflow.
[+] scosman|1 year ago|reply
I installed warp, the LLM terminal and tried to track where it helped. It was crazy helpful for ffmpeg… and not much else.
[+] j45|1 year ago|reply
I love that this is a bash script.

Long live bash scripts universal ability to mostly just run.

[+] dvektor|1 year ago|reply
this might be the best use of llm's discovered to date
[+] shrisukhani|1 year ago|reply
Neat! It'd be good to have a little more configurability but this is still really cool