September 18th, 2024

Cutting videos in the terminal with chafa and FFmpeg

The terminal video editor "vic" utilizes chafa and ffmpeg for playback and editing, allowing video cuts via command line. Future updates aim to improve installation, playback speed, and add audio support.

Read original articleLink Icon
Cutting videos in the terminal with chafa and FFmpeg

The article discusses the development of a terminal-based video editor named "vic," which utilizes the chafa and ffmpeg libraries for video playback and editing. The author highlights the aesthetic appeal of terminal graphics, particularly with chafa, which enhances video representation using various symbols. Initial performance issues were resolved, allowing for smooth playback at 20-30 frames per second. The program primarily relies on two ffmpeg commands: one for decoding videos into pixel frames and another for cutting videos based on user-defined timestamps. The author shares a bug encountered during testing, where the program became unresponsive after 270 seconds due to the accumulation of stderr messages from ffmpeg, which was resolved by redirecting stderr to /dev/null. Future improvements are planned, including simplifying installation, enhancing playback speed, and adding audio support to make the tool more functional. The author also contemplates the naming of the program and acknowledges the need for further refinements.

- The terminal video editor "vic" uses chafa and ffmpeg for video playback and editing.

- The program allows users to cut videos directly from the command line.

- A bug related to stderr message accumulation was identified and fixed.

- Future enhancements include better installation processes and audio support.

- The author is considering various names for the program and plans additional improvements.

Link Icon 3 comments
By @dylan604 - 4 months
"That bug was a real head-scratcher for me. I'm glad I figured it out. The simple fix is to pipe stderr to /dev/null. "

That's kind of a nope. It's a feature, not a bug. FFMPEG will exit with 0 even on an actual error for what you were expecting. In one of TFA examples using -ss 5 -to 10, you're expecting a result of a 5 second clip. If for some reason, there was an issue reading the file at 8 seconds, ffmpeg will exit with 0 and an output that was only 3 seconds long. If you dumped stderr to /dev/null, you'd have no idea why.

FFMPEG definitely does some weird things with stdout/stderr for people that are new to it. However, there are reasons for its behavior that make sense after long enough use of it. Being able to pipe raw video using stdout instead of forcing a dump to a file is full on Matrix level flex that distorts the surrounding environment. So if the actual video is going out stdout, stderr receives all of the other info that normies would expect to see on stdout. This is why so many people use 2>/path/to/log so that at the end of the process with an exit 0 any issues with an output can be ascertained.

By @seanmceligot - 4 months
Download the executable? That's not safe. Even if your intentions are good, you're teaching bad security habits.