unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to pass a evaluated list as argument of macro?
@ 2020-07-06 13:02 stardiviner
  2020-07-06 13:39 ` Noam Postavsky
  0 siblings, 1 reply; 4+ messages in thread
From: stardiviner @ 2020-07-06 13:02 UTC (permalink / raw)
  To: Emacs Help


I have a prototype of bellowing elisp code. I try to write a macro for construct
ffmpeg commands. But found the passed in arglist is not evaluated or literal
"arglist" in some ways. I marked the problem in source code. Can somebody help
me on this problem? Thanks in advance. :)

#+begin_src emacs-lisp
(defmacro ffmpeg--command-macro (name arglist &rest body)
  "Construct ffmpeg command with ARGS and BODY."
  ;; (declare (debug t))
  `(defun ,(intern (format "ffmpeg-%s" name)) ()
     (interactive)
     (make-process
      :name "ffmpeg"
      ;; FIXME `arglist' is not evaluated
      :command ,(apply 'append '("ffmpeg") (eval arglist)) ; <------------- problem here
      :buffer "*ffmpeg*"
      :sentinel (lambda (_ __)
                  (message "FFmpeg process finished.")))
     ,@body))

;;; NOTE Because ffmpeg command option "-t" accept seconds like 57 as value.
(defun ffmpeg--subtract-timestamps (start-timestamp end-timestamp)
  "Subtract END-TIMESTAMP with START-TIMESTAMP."
  (time-subtract
   (encode-time (parse-time-string
                 (concat "2020-01-01T" end-timestamp)))
   (encode-time (parse-time-string
                 (concat "2020-01-01T" start-timestamp)))))

;; (ffmpeg--subtract-timestamps "00:11:25" "00:12:12")

(defun ffmpeg-cut-clip (input-filename start-timestamp end-timestamp output-filename)
  "Cut clip of media INPUT-FILENAME between START-TIMESTAMP END-TIMESTAMP and output to OUTPUT-FILENAME."
  (interactive (list
                (read-file-name "FFmpeg input filename: ")
                (read-string "FFmpeg start timestamp: ")
                (read-string "FFmpeg end timestamp: ")
                (read-file-name "FFmpeg output filename: ")))
  ;; "ffmpeg -i input-filename -ss start-timestamp -t time-timestamp -codec copy output-filename"
  (let ((arglist `("-i" ,input-filename
                   "-ss" ,start-timestamp
                   "-t" ,(ffmpeg--subtract-timestamps start-timestamp end-timestamp)
                   "-codec" "copy"
                   ,output-filename)))
    (ffmpeg--command-macro "cut-clip" arglist)))
#+end_src

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-06 15:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-06 13:02 How to pass a evaluated list as argument of macro? stardiviner
2020-07-06 13:39 ` Noam Postavsky
2020-07-06 14:46   ` stardiviner
2020-07-06 15:23     ` Noam Postavsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).