Skip to content

Instantly share code, notes, and snippets.

@5hanth
Created February 22, 2016 17:59
Show Gist options
  • Save 5hanth/ae1e4a4c0f2ebfd36695 to your computer and use it in GitHub Desktop.
Save 5hanth/ae1e4a4c0f2ebfd36695 to your computer and use it in GitHub Desktop.
Screencasting + Gif = Gifcasting :: using ffcast + ffmpeg in emacs
(defun sha/screencast (&optional output-file)
(let ((output-file
(or output-file
(concat "/tmp/"
(format "%S" (abs (random)))
".mp4"))))
(message "screen-cast started")
(start-process "screencasting"
(get-buffer-create "*screencast-buffer*")
"ffcast"
"rec"
output-file)
output-file))
(defun sha/screencast-handler ()
(interactive)
(if (process-status "screencasting")
(progn
(process-send-string "screencasting" "q")
(message "screen-cast stopped"))
(sha/screencast)))
(global-set-key (kbd "s--") 'sha/screencast-handler )
(defun sha/gif-encode (input-file &optional scale frames)
(setq sha/gif/frames (or frames "15"))
(setq sha/gif/scale (or scale "720"))
(setq sha/gif/palette "/tmp/palette.png")
(setq sha/gif/filters
(concat "fps=" sha/gif/frames
",scale=" sha/gif/scale
":-1:flags=lanczos"))
(set-process-sentinel
(start-process "gifcasting"
(get-buffer-create "*gifcast-buffer*")
"ffmpeg" "-i" input-file
"-vf" (concat sha/gif/filters ",palettegen")
"-y" sha/gif/palette)
(lambda (process event)
(when (= 0 (process-exit-status process))
(set-process-sentinel
(start-process "gifcasting"
(get-buffer-create "*gifcast-buffer*")
"ffmpeg" "-i" input-file
"-i" sha/gif/palette
"-lavfi" (concat sha/gif/filters
"[x]; [x][1:v] paletteuse")
"-y" (concat input-file ".gif"))
(lambda (process event)
(when (= 0 (process-exit-status process))
(message "gif-casting done"))))))))
(defun sha/screencast-to-gif (&optional scale frames)
(interactive)
(sha/gif-encode (read-file-name "Enter .mp4 path : " "/tmp/")
scale frames)
(message "Gif-casting started" ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment