{"id":550,"date":"2021-10-08T04:48:00","date_gmt":"2021-10-08T04:48:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=550"},"modified":"2021-10-08T04:48:00","modified_gmt":"2021-10-08T04:48:00","slug":"550","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/10\/08\/550\/","title":{"rendered":"\u56fe\u7247\u6587\u4ef6\u53f3\u952e\u6279\u91cf\u8f6cWebp\u683c\u5f0f\uff0c\u6216\u8005\u89c6\u9891\u8f6c\u6362\u683c\u5f0f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/539784735.webp\" alt=\"wp.png_new.webp\" title=\"wp.png_new.webp\"><\/p>\n<h3>\u6ce8\u518c\u8868\u7f16\u8f91\u5668\u6dfb\u52a0\u53f3\u952e\u83dc\u5355\u7684\u57fa\u672c\u539f\u7406<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/2316917356.png\" alt=\"ffmpeg.png\" title=\"ffmpeg.png\"><\/p>\n<ul>\n<li>\n<p>\u6ce8\u518c\u8868\u6dfb\u52a0\u4ee5\u4e0b\u952e\u503c\uff0c\u5c31\u80fd\u53f3\u952e\u8fd0\u884c\u547d\u4ee4<\/p>\n<pre><code>Windows Registry Editor Version 5.00\n\n[HKEY_CLASSES_ROOT*shell\u56fe\u7247\u8f6cWebp]\n@=\"\u56fe\u7247\u8f6cWebp(&amp;W)\"\n\"icon\"=\"C:\\soft\\amd.ico\"\n\n[HKEY_CLASSES_ROOT*shell\u56fe\u7247\u8f6cWebpcommand]\n@=\"cmd \/c ffmpeg -i %1 %1_new.webp\"<\/code><\/pre>\n<h3>\u4f7f\u7528 <code>FFMPEG<\/code> \u8f6c\u6362\u56fe\u7247<\/h3>\n<pre><code>ffmpeg -i a.png new.webp\n# \u56e0\u4e3a\u662f\u547d\u4ee4\u884c\u7a0b\u5e8f\uff0c\u6240\u4ee5\u8c03\u7528\u7cfb\u7edfShell \"cmd -c\"\u8fd0\u884c\ncmd \/c ffmpeg -i %1 %1_new.webp<\/code><\/pre>\n<h3>\u56e0\u4e3a\u5de5\u5177\u8c03\u7528 <code>ffmpeg<\/code> \u8fd8\u53ef\u4ee5\u89c6\u9891\u8f6c<code>webp<\/code>,\u53ea\u8981\u5c0f\u5c0f\u6539\u52a8:\u89c6\u9891\u683c\u5f0f\u8f6c\u6362\uff0c\u89c6\u9891\u63d0\u53d6mp3<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/2970448578.webp\" alt=\"GIF.gif_new.webp\" title=\"GIF.gif_new.webp\"><\/p>\n<\/li>\n<\/ul>\n<h2>\u4f7f\u7528 <code>Python<\/code> \u53ef\u4ee5\u64cd\u4f5c Windows \u6ce8\u518c\u8868\u6dfb\u52a0\uff0c\u8fd8\u53ef\u4ee5\u6dfb\u52a0\u5feb\u6377\u952e<\/h2>\n<ul>\n<li>\u6dfb\u52a0\u53f3\u952e\u83dc\u5355\u7684\u4ee3\u7801\uff0c\uff0c\u5c01\u88c5\u6210\u4e86 <code>add_context_menu<\/code> \u51fd\u6570\uff1a<\/li>\n<li>\n<p>\u6e90\u7801: <code>add_context_menu.py<\/code><\/p>\n<pre><code># coding:utf-8\nimport winreg as reg\ndef add_context_menu(menu_name,command,reg_root_key_path,reg_key_path,shortcut_key):\n  '''\n  \u5c01\u88c5\u7684\u6dfb\u52a0\u4e00\u4e2a\u53f3\u952e\u83dc\u5355\u7684\u65b9\u6cd5\n  :param menu_name: \u663e\u793a\u7684\u83dc\u5355\u540d\u79f0\n  :param command: \u83dc\u5355\u6267\u884c\u7684\u547d\u4ee4\n  :param reg_root_key_path: \u6ce8\u518c\u8868\u6839\u952e\u8def\u5f84\n  :param reg_key_path: \u8981\u6dfb\u52a0\u5230\u7684\u6ce8\u518c\u8868\u7236\u952e\u7684\u8def\u5f84\uff08\u76f8\u5bf9\u8def\u5f84\uff09\n  :param shortcut_key: \u83dc\u5355\u5feb\u6377\u952e\uff0c\u5982\uff1a'S'\n  :return:\n  '''\n  # \u6253\u5f00\u540d\u79f0\u7236\u952e\n  key = reg.OpenKey(reg_root_key_path, reg_key_path)\n  # \u4e3akey\u521b\u5efa\u4e00\u4e2a\u540d\u79f0\u4e3amenu_name\u7684sub_key\uff0c\u5e76\u8bbe\u7f6esub_key\u7684\u503c\u4e3amenu_name\u52a0\u4e0a\u5feb\u6377\u952e\uff0c\u6570\u636e\u7c7b\u578b\u4e3aREG_SZ\u5b57\u7b26\u4e32\u7c7b\u578b\n  reg.SetValue(key, menu_name, reg.REG_SZ, menu_name + '(&amp;{0})'.format(shortcut_key))\n\n  # \u6253\u5f00\u521a\u521a\u521b\u5efa\u7684\u540d\u4e3amenu_name\u7684sub_key\n  sub_key = reg.OpenKey(key, menu_name)\n  # \u4e3asub_key\u6dfb\u52a0\u540d\u4e3a'command'\u7684\u5b50\u952e\uff0c\u5e76\u8bbe\u7f6e\u5176\u503c\u4e3acommand + ' \"%v\"'\uff0c\u6570\u636e\u7c7b\u578b\u4e3aREG_SZ\u5b57\u7b26\u4e32\u7c7b\u578b\n  # reg.SetValue(sub_key, 'command', reg.REG_SZ, command + ' \"%v\"')\n  reg.SetValue(sub_key, 'command', reg.REG_SZ, command)\n\n  # \u5173\u95edsub_key\u548ckey\n  reg.CloseKey(sub_key)\n  reg.CloseKey(key)\n\ndef img2webp_menu():\n  '''\n  \u6dfb\u52a0\u53f3\u952e\u83dc\u5355\uff0c\u53ef\u4ee5\u5728\u53f3\u952e\u70b9\u51fb\u4e00\u4e2a\u6587\u4ef6\u3001\u76ee\u5f55\u3001\u6587\u4ef6\u5939\u7a7a\u767d\u5904\u6216\u9a71\u52a8\u5668\u76d8\u7b26\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u6253\u5370\u51fa\u5f53\u524d\u7684\u7edd\u5bf9\u8def\u5f84\n  :return: None\n  '''\n  # \u83dc\u5355\u540d\u79f0\n  menu_name = '\u56fe\u7247\u8f6cWebp'\n  # \u6267\u884c\u4e00\u4e2apython\u811a\u672c\u7684\u547d\u4ee4\uff0c\u7528\u4e8e\u6253\u5370\u547d\u4ee4\u884c\u53c2\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff08\u5373\u9009\u4e2d\u7684\u6587\u4ef6\u8def\u5f84\uff09\n  py_command = r'cmd \/c ffmpeg -i %1 %1_new.webp'\n\n  # \u6dfb\u52a0\u6587\u4ef6\u53f3\u952e\u83dc\u5355\n  add_context_menu(menu_name, py_command,reg.HKEY_CLASSES_ROOT,r'*\\shell','W')\n\n  # # \u6dfb\u52a0\u6587\u4ef6\u5939\u53f3\u952e\u83dc\u5355\n  # add_context_menu(menu_name, py_command, reg.HKEY_CLASSES_ROOT, r'Directory\\shell', 'S')\n  # # \u6dfb\u52a0\u6587\u4ef6\u5939\u7a7a\u767d\u5904\u53f3\u952e\u83dc\u5355\n  # add_context_menu(menu_name, py_command, reg.HKEY_CLASSES_ROOT, r'Directory\\Background\\shell', 'S')\n  # # \u6dfb\u52a0\u78c1\u76d8\u9a71\u52a8\u5668\u53f3\u952e\u83dc\u5355\n  # add_context_menu(menu_name, py_command, reg.HKEY_CLASSES_ROOT, r'Drive\\shell', 'S')\n\nif __name__ == '__main__':\n  img2webp_menu()<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>\u4ee3\u7801\u4e2d\u6dfb\u52a0\u6ce8\u518c\u8868\u952e\u7684command\u547d\u4ee4\u65f6\uff0c\u662f\u4ee5%v\u4ee3\u8868\u4e00\u4e2a\u8def\u5f84\u53c2\u6570\u7684\uff0c\u8fd8\u6709\u5176\u4ed6\u51e0\u79cd\u53c2\u6570\u53ef\u4ee5\u4f7f\u7528\uff1a<\/h3>\n<pre><code>\u7cfb\u7edf\u9ed8\u8ba4\u53d8\u91cf\u7684\u542b\u4e49\uff1a\n%1  \u8868\u793a\u7a0b\u5e8f\u64cd\u4f5c\u7684\u6587\u4ef6\n%2  \u8868\u793a\u7cfb\u7edf\u9ed8\u8ba4\u7684\u6253\u5370\u673a\n%3  \u8868\u793a\u8d44\u6599\u6247\u533a\n%4  \u8868\u793a\u64cd\u4f5c\u7684Port\u7aef\u53e3\n\"%v\"  \u7a0b\u5e8f\u64cd\u4f5c\u7684\u8def\u5f84<\/code><\/pre>\n<ul>\n<li>\u53c2\u8003\u6587\u7ae0: <a href=\"https:\/\/github.com\/dnxbjyj\/py-project\/tree\/master\/AddWinContextMenu\">\u5982\u4f55\u5728Windows\u4e0b\u7528Python\u5f00\u53d1\u53f3\u952e\u83dc\u5355\u529f\u80fd\uff1f<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\u518c\u8868\u7f16\u8f91\u5668\u6dfb\u52a0\u53f3\u952e\u83dc\u5355\u7684\u57fa\u672c\u539f\u7406 \u6ce8\u518c\u8868\u6dfb\u52a0\u4ee5\u4e0b\u952e\u503c\uff0c\u5c31\u80fd\u53f3\u952e\u8fd0\u884c\u547d\u4ee4 Windows Regis [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[39,45,53],"class_list":["post-550","post","type-post","status-publish","format-standard","hentry","category-default","tag-ffmpeg","tag-python","tag-webp"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=550"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/550\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}