Emacs Lisp: ffmpeg-cut-dired

Emacs Lisp: ffmpeg-cut-dired

This function is used with Dired within Emacs to cut video files from specific begin time for specific duration. Files are cut and saved in the directory. This may be handy to use your Emacs editor as movie editor application.

(defun shell-double-quote (s)
  "Double quotes for the string that shall be fed to shell command"
  (replace-regexp-in-string "\"" "\\\\\"" s))

(defun ffmpeg-cut-dired ()
  "Dired function to cut video files from specific begin time for
specific duration. You can cut many files at once if marked, or
the function will work only on the specific file. Customize the
list of video extensions below."
  (interactive)
  (let* ((files (dired-get-marked-files))
     (allowed-extensions '("mp4" "ogv" "3gp")))
    (dolist (file files)
      (let* ((file-sans-ext (file-name-sans-extension file))
         (file-ext (file-name-extension file)))
    (when (seq-contains allowed-extensions file-ext)
      (let* ((output (concat file-sans-ext "-cut." file-ext))
         (begin-time (read-from-minibuffer "Begin time in format 00:00:00: " "00:00:00"))
         (duration (read-from-minibuffer "Duration in format 00:00:00: " "00:00:10"))
         (command (format "ffmpeg -i \"%s\" -ss %s -t %s -async 1 \"%s\""
                  (shell-double-quote file)
                  begin-time duration
                  (shell-double-quote output))))
        (shell-command command)))))))

Cutting video files with GNU Emacs editor is easy.

Leave Your Comment or Contact GNU.Support

Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know


Full name:


E-mail:


Message: