                                                :process proc
                                                :name (process-name proc)
                                                :calling-buffer (current-buffer)
-                                               :files-before (dwim-shell--dired-files)
+                                               :files-before files-before
                                                :reporter progress-reporter))
                   dwim-shell--execs))
       (set-process-sentinel proc #'dwim-shell--sentinel)

(defun dwim-shell-convert-audio-to-mp3 ()
  "Convert all marked audio to mp3(s)."
  (interactive)
  (dwim-shell--dired-execute-script-on-marked-files
   "ffmpeg -stats -n -i <<f>> -acodec libmp3lame <<fne>>.mp3"
   "Convert to mp3" '("ffmpeg")))

(defun dwim-shell-convert-image-to-jpg ()
  "Convert all marked images to jpg(s)."
  (interactive)
  (dwim-shell--dired-execute-script-on-marked-files
   "convert -verbose <<f>> <<fne>>.jpg"
   "Convert to jpg" '("convert")))

(defun dwim-shell-convert-image-to-png ()
  "Convert all marked images to png(s)."
  (interactive)
  (dwim-shell--dired-execute-script-on-marked-files
   "convert -verbose <<f>> <<fne>>.png"
   "Convert to png" '("convert")))

(defun dwim-shell-convert-to-gif ()
  "Convert all marked videos to optimized gif(s)."
  (interactive)
  (dwim-shell--dired-execute-script-on-marked-files
   "ffmpeg -loglevel quiet -stats -y -i <<f>> -pix_fmt rgb24 -r 15 <<fne>>.gif"
   "Convert to gif" '("ffmpeg")))

(defun dwim-shell-convert-to-optimized-gif ()
  "Convert all marked videos to optimized gif(s)."
  (interactive)
  (dwim-shell--dired-execute-script-on-marked-files
   "ffmpeg -loglevel quiet -stats -y -i <<f>> -pix_fmt rgb24 -r 15 <<fne>>.gif
    gifsicle -O3 <<fne>>.gif --lossy=80 -o <<fne>>.gif"
   "Convert to optimized gif" '("ffmpeg" "gifsicle")))

(defun dwim-shell-drop-video-audio ()
  "Drop audio from all marked videos."
  (interactive)
  (dwim-shell--command-on-marked-files
   "ffmpeg -i <<f>> -c copy -an <<fne>>_no_audio.<<e>>"
   "Drop audio" '("ffmpeg")))

(defun dwim-shell--command-on-marked-files (script name utils &optional post-process-template on-completion)
  "Execute SCRIPT, using buffer NAME, FILES, and bin UTILS."
  (dwim-shell-execute-script script name (dwim-shell--marked-files) utils
                             post-process-template on-completion))

(defun dwim-shell--marked-files ()
  "Return buffer file (if available) or marked files for a `dired' buffer."
  (if (buffer-file-name)
      (list (buffer-file-name))
    (dired-get-marked-files)))

(defun dwim-shell-execute-script (script name files utils &optional post-process-template on-completion)
  "Execute SCRIPT, using buffer NAME, FILES, and bin UTILS."
