dwim-shell-command icon indicating copy to clipboard operation
dwim-shell-command copied to clipboard

quoting around complex noweb template use is unclear

Open gvoysey opened this issue 1 year ago • 2 comments

Consider the following defun:

    (defun dwim-shell-command-thumbnail-with-ffmpeg ()
      "Generate a thumbnail with ffmpeg."
      (interactive)
      (dwim-shell-command-on-marked-files
       "Thumbnail with ffmpeg"
       " ffmpeg -i '<<f>>' -vf  \"thumbnail,scale=640:360\" -frames:v 1 '<<td>>/<<fne>>.png'"
       :utils "ffmpeg"
       :silent-success t))

This fails with dwim-shell-command--escaped-quote-around: Couldn’t figure out how to quote for " ffmpeg -i '<<f>>' -vf "thumbnail,scale=640:360" -frames:v 1 '<<td>>/<<fne>>.png'" using / and .

If instead the command is " ffmpeg -i '<<f>>' -vf \"thumbnail,scale=640:360\" -frames:v 1 '<<fne>>.png'", (ie, omitting the temporary directory), this succeeds.

how does <

> work? omitting the explicit / path separator doesn't seem to matter, nor does hardcoding a /tmp/ instead of using <<td>>.

(my actual goal here is to generate temporary thumbnails for videos, so what i really want is something like " ffmpeg -i '<<f>>' -vf \"thumbnail,scale=640:360\" -frames:v 1 '<<td>>/<<fne>>.png' && feh <<td>>/<<fne>>.png", but omitting the && ... clause doesn't affect the error here. I'm also a little curious about how to use <>; maybe i can just pipe the png into feh and avoid the file entirely, but i don't know how.)

gvoysey avatar Nov 08 '23 13:11 gvoysey

This wasn't quite possible. Made some changes.

Adds support for and for https://github.com/xenodium/dwim-shell-command/issues/15

This adds <b> (base name) and <bne> (base name no extension), so we can now craft what you're after.

(my actual goal here is to generate temporary thumbnails for videos, so what i really want is something like " ffmpeg -i '<>' -vf "thumbnail,scale=640:360" -frames:v 1 '<>/<>.png' && feh <>/<>.png",

After getting the latest (v0.60), it should be possible with something like:

(defun dwim-shell-commands-video-temporary-thumbnail ()
  "Generate a thumbnail with ffmpeg."
  (interactive)
  (let ((temp-dir (make-temp-file "thumbnails-" t)))
    (dwim-shell-command-on-marked-files
     "Thumbnail with ffmpeg"
     "ffmpeg -i '<<f>>' -vf  \"thumbnail,scale=640:360\" -frames:v 1 '<<td>>/<<bne>>.png' && feh <<td>>/<<bne>>.png"
     :silent-success t
     :utils "ffmpeg")))

Note: I'm on a mac, so I used open instead of feh. Should hopefully work on linux with feh.

ps. Would be nice if there was a way to preserve the video aspect ratio in the thumbnail, if you know?

xenodium avatar Nov 08 '23 20:11 xenodium

ps. Would be nice if there was a way to preserve the video aspect ratio in the thumbnail, if you know?

This worked for me: "ffmpeg -i '<<f>>' -ss 00:00:01.000 -vframes 1 '<<td>>/<<bne>>.jpg' && feh <<td>>/<<bne>>.jpg"

xenodium avatar Nov 09 '23 08:11 xenodium