index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

18 December 2022 Emacs: ffmpeg and macOS aliasing commands

On a recent mastodon post, Chris Spackman mentioned he uses Emacs to save ffmpeg commands he's figured out for later usage. Emacs is great for this kind of thing. I've tried different approaches over time and eventually landed on dwim-shell-command, a small package I wrote. Like Chris, I also wanted a way to invoke magical incantations of known shell commands without having to remember all the details.

Chris's post reminded me of a few use-cases I'd been meaning to add DWIM shell commands for.

ffmpeg

  1. Trimming seconds from videos
    • dwim-shell-commands-video-trim-beginning using:

      ffmpeg -i '<<f>>' -y -ss <<Seconds:5>> -c:v copy -c:a copy '<<fne>>_trimmed.<<e>>'
      
    • dwim-shell-commands-video-trim-end using:

      ffmpeg -sseof -<<Seconds:5>> -i '<<f>>' -y -c:v copy -c:a copy '<<fne>>_trimmed.<<e>>'
      

      Side-node: The <<Seconds:5>> placeholder is recognized as a query, so Emacs will prompt you for a numeric value.

  2. Extracting audio from videos
    • dwim-shell-commands-video-to-mp3 using:

      ffmpeg -i '<<f>>' -vn -ab 128k -ar 44100 -y '<<fne>>.mp3'
      

With these new dwim shell commands added, I can easily apply them one after the other. No need to remember command details.

trim_convert_mp3_x1.4.webp

macOS aliases

After rebuilding Emacs via the wonderful emacs-plus, I recently broke my existing /Applications/Emacs.app alias. No biggie, one can easily add a new one alias from macOS Finder, but I've been wanting to do it from Emacs. Turns out there's a bit of AppleScript we can turn into a more memorale command like dwim-shell-commands-macos-make-finder-alias:

osascript -e 'tell application \"Finder\" to make alias file to POSIX file \"<<f>>\" at POSIX file \"%s\"'

It's highly unlikely I'll remember the AppleScript snippet (are there better ways?), but I'll easily find and invoke my new command with fuzzy searching:

make-emacs-alias_x1.4.webp

Included in dwim-shell-command

All of these are now included in dwim-shell-commands.el, which you can optionally load after installing dwim-shell-command from MELPA.