六一的部落格


关关难过关关过,前路漫漫亦灿灿。




需求

有尝试使用Logseq和Obsidian做视频笔记,结果不太满意,不过弄清楚了需求

-
在笔记页面控制视频的暂停,前进,后退
播放器能加载字幕,能设置屏幕大小(全屏)
在笔记页面添加时间戳
从时间戳播放视频

说明

-
播放器 mpv
插件 emms 播放器和Emacs间的接口:控制播放器,获取相关参数
插件 pretty-hydra 自定义快捷键菜单
自定义函数 打时间戳,跳转

时间戳样式

无!

!

需设置emms默认播放路径

1;; (setq my/movie-path "path/to/movie")

需设置视频根目录

1;; (setq my/video-path "path/to/video")

安装emms

emms-安装


安装pretty-hydra

pretty-hydra-安装


插入时间戳

 1(defun my/insert-timestamp()
 2  (interactive)
 3  (let ((desc (read-string "Description: ")))
 4    (setq my/mpv-current-file nil)
 5    (setq my/mpv-timestamp nil)
 6    (emms-player-mpv-ipc-req-send '(get_property path)
 7                                  #'(lambda (ret err) (unless err
 8                                                        (setq my/mpv-current-file (file-relative-name ret my/video-path))
 9                                                        )
10                                      )
11                                  )
12    (emms-player-mpv-ipc-req-send '(get_property time-pos)
13                                  #'(lambda (ret err) (unless err
14                                                        (setq my/mpv-timestamp ret)
15                                                        )
16                                      )
17                                  )
18    (sleep-for 0.1)
19    (when (and my/mpv-timestamp my/mpv-current-file)
20      (insert (format (concat "[[" "timestamp:%s#%d][时间戳:%s]]") my/mpv-current-file my/mpv-timestamp desc))
21      (message "Add timestamp %s#%d success!" my/mpv-current-file my/mpv-timestamp)
22      )
23    (unless (and my/mpv-timestamp my/mpv-current-file)
24      (message "Fail to insert timestamp!")
25      )
26    )
27  )
28(global-set-key (kbd "C-c e i") 'my/insert-timestamp)

时间戳跳转

 1(defun my/emms-player-start-hook ()
 2  ;; (emms-pause)
 3  (emms-seek-to my/emms-timestamp)
 4  (remove-hook 'emms-player-started-hook 'my/emms-player-start-hook))
 5
 6(defun my/seek-to-timestamp ()
 7  (interactive)
 8  (when (search-backward (concat "[[" "timestamp:") nil t)
 9    (when (re-search-forward (rx "[[" "timestamp:" (group (0+ (not "#"))) "#" (group (0+ (not "]"))) "][" (group (0+ (not "]"))) "]]" ) nil t)
10      (let ((file (string-join (mapcar #'string (match-string 1)))))
11        (setq my/emms-timestamp (string-join (mapcar #'string (match-string 2))))
12        (if emms-player-playing-p (emms-stop))
13        (add-hook 'emms-player-started-hook 'my/emms-player-start-hook)
14        (emms-player-start (emms-track 'file (concat my/video-path "/" file)))
15        ;; (setq track (emms-track 'file (concat my/video-path "/" file)))
16        ;; (emms-player-start track)
17        )
18      )
19    )
20  )
21(global-set-key (kbd "C-c e g") 'my/seek-to-timestamp)

使用Emacs做视频笔记



需求

有尝试使用Logseq和Obsidian做视频笔记,结果不太满意,不过弄清楚了需求

-
在笔记页面控制视频的暂停,前进,后退
播放器能加载字幕,能设置屏幕大小(全屏)
在笔记页面添加时间戳
从时间戳播放视频

说明

-
播放器 mpv
插件 emms 播放器和Emacs间的接口:控制播放器,获取相关参数
插件 pretty-hydra 自定义快捷键菜单
自定义函数 打时间戳,跳转

时间戳样式

无!

!

需设置emms默认播放路径

1;; (setq my/movie-path "path/to/movie")

需设置视频根目录

1;; (setq my/video-path "path/to/video")

安装emms

emms-安装


安装pretty-hydra

pretty-hydra-安装


插入时间戳

 1(defun my/insert-timestamp()
 2  (interactive)
 3  (let ((desc (read-string "Description: ")))
 4    (setq my/mpv-current-file nil)
 5    (setq my/mpv-timestamp nil)
 6    (emms-player-mpv-ipc-req-send '(get_property path)
 7                                  #'(lambda (ret err) (unless err
 8                                                        (setq my/mpv-current-file (file-relative-name ret my/video-path))
 9                                                        )
10                                      )
11                                  )
12    (emms-player-mpv-ipc-req-send '(get_property time-pos)
13                                  #'(lambda (ret err) (unless err
14                                                        (setq my/mpv-timestamp ret)
15                                                        )
16                                      )
17                                  )
18    (sleep-for 0.1)
19    (when (and my/mpv-timestamp my/mpv-current-file)
20      (insert (format (concat "[[" "timestamp:%s#%d][时间戳:%s]]") my/mpv-current-file my/mpv-timestamp desc))
21      (message "Add timestamp %s#%d success!" my/mpv-current-file my/mpv-timestamp)
22      )
23    (unless (and my/mpv-timestamp my/mpv-current-file)
24      (message "Fail to insert timestamp!")
25      )
26    )
27  )
28(global-set-key (kbd "C-c e i") 'my/insert-timestamp)

时间戳跳转

 1(defun my/emms-player-start-hook ()
 2  ;; (emms-pause)
 3  (emms-seek-to my/emms-timestamp)
 4  (remove-hook 'emms-player-started-hook 'my/emms-player-start-hook))
 5
 6(defun my/seek-to-timestamp ()
 7  (interactive)
 8  (when (search-backward (concat "[[" "timestamp:") nil t)
 9    (when (re-search-forward (rx "[[" "timestamp:" (group (0+ (not "#"))) "#" (group (0+ (not "]"))) "][" (group (0+ (not "]"))) "]]" ) nil t)
10      (let ((file (string-join (mapcar #'string (match-string 1)))))
11        (setq my/emms-timestamp (string-join (mapcar #'string (match-string 2))))
12        (if emms-player-playing-p (emms-stop))
13        (add-hook 'emms-player-started-hook 'my/emms-player-start-hook)
14        (emms-player-start (emms-track 'file (concat my/video-path "/" file)))
15        ;; (setq track (emms-track 'file (concat my/video-path "/" file)))
16        ;; (emms-player-start track)
17        )
18      )
19    )
20  )
21(global-set-key (kbd "C-c e g") 'my/seek-to-timestamp)